computer_log.go 882 字节
Newer Older
LinuxSuRen's avatar
LinuxSuRen 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
package cmd

import (
	"github.com/jenkins-zh/jenkins-cli/client"

	"github.com/jenkins-zh/jenkins-cli/app/i18n"

	"github.com/spf13/cobra"
)

// ComputerLogOption option for config list command
type ComputerLogOption struct {
	CommonOption
}

var computerLogOption ComputerLogOption

func init() {
	computerCmd.AddCommand(computerLogCmd)
}

var computerLogCmd = &cobra.Command{
	Use:   "log <name>",
	Short: i18n.T("Output the log of the agent"),
	Long:  i18n.T("Output the log of the agent"),
	Args:  cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		jClient := &client.ComputerClient{
			JenkinsCore: client.JenkinsCore{
				RoundTripper: computerLogOption.RoundTripper,
			},
		}
		getCurrentJenkinsAndClient(&(jClient.JenkinsCore))

		var log string
		if log, err = jClient.GetLog(args[0]); err == nil {
			cmd.Print(log)
		}
		return
	},
}