コード例 #1
0
ファイル: ssh_options.go プロジェクト: Doebe/workplace
func NewSSHOptions(fc flags.FlagContext) (*SSHOptions, error) {
	sshOptions := &SSHOptions{}

	sshOptions.AppName = fc.Args()[0]
	sshOptions.Index = uint(fc.Int("i"))
	sshOptions.SkipHostValidation = fc.Bool("k")
	sshOptions.SkipRemoteExecution = fc.Bool("N")
	sshOptions.Command = fc.StringSlice("c")

	if fc.IsSet("L") {
		for _, arg := range fc.StringSlice("L") {
			forwardSpec, err := sshOptions.parseLocalForwardingSpec(arg)
			if err != nil {
				return sshOptions, err
			}
			sshOptions.ForwardSpecs = append(sshOptions.ForwardSpecs, *forwardSpec)
		}
	}

	if fc.IsSet("t") && fc.Bool("t") {
		sshOptions.TerminalRequest = REQUEST_TTY_YES
	}

	if fc.IsSet("tt") && fc.Bool("tt") {
		sshOptions.TerminalRequest = REQUEST_TTY_FORCE
	}

	if fc.Bool("T") {
		sshOptions.TerminalRequest = REQUEST_TTY_NO
	}

	return sshOptions, nil
}
コード例 #2
0
ファイル: curl.go プロジェクト: Doebe/workplace
func (cmd *Curl) Execute(c flags.FlagContext) {
	path := c.Args()[0]
	method := c.String("X")
	headers := c.StringSlice("H")
	body := c.String("d")
	verbose := c.Bool("v")

	reqHeader := strings.Join(headers, "\n")

	if verbose {
		trace.EnableTrace()
	}

	responseHeader, responseBody, apiErr := cmd.curlRepo.Request(method, path, reqHeader, body)
	if apiErr != nil {
		cmd.ui.Failed(T("Error creating request:\n{{.Err}}", map[string]interface{}{"Err": apiErr.Error()}))
	}

	if verbose {
		return
	}

	if c.Bool("i") {
		cmd.ui.Say(responseHeader)
	}

	if c.String("output") != "" {
		err := cmd.writeToFile(responseBody, c.String("output"))
		if err != nil {
			cmd.ui.Failed(T("Error creating request:\n{{.Err}}", map[string]interface{}{"Err": err}))
		}
	} else {
		if strings.Contains(responseHeader, "application/json") {
			buffer := bytes.Buffer{}
			err := json.Indent(&buffer, []byte(responseBody), "", "   ")
			if err == nil {
				responseBody = buffer.String()
			}
		}

		cmd.ui.Say(responseBody)
	}
	return
}
コード例 #3
0
			Ω(fc.Float64("i")).To(Equal(float64(0)))

			fc.NewFloat64FlagWithDefault("i", "i2", "setting new flag", 5.5)
			fc.Parse()
			Ω(fc.IsSet("i")).To(BeTrue())
			Ω(fc.IsSet("i2")).To(BeTrue())
			Ω(fc.Float64("i")).To(Equal(5.5))
			Ω(fc.Float64("i2")).To(Equal(5.5))
		})
	})

	Describe("NewStringSliceFlag()", func() {
		It("init the flag context with a new StringSlice flagset", func() {
			fc.Parse("-s", "5", "-s", "6")
			Ω(fc.IsSet("s")).To(BeFalse())
			Ω(fc.StringSlice("s")).To(Equal([]string{}))

			fc.NewStringSliceFlag("s", "s2", "setting new StringSlice flag")
			fc.Parse("-s", "5", "-s", "6")
			Ω(fc.IsSet("s")).To(BeTrue())
			Ω(fc.IsSet("s2")).To(BeTrue())
			Ω(fc.StringSlice("s")).To(Equal([]string{"5", "6"}))
			Ω(fc.StringSlice("s2")).To(Equal([]string{"5", "6"}))
		})
	})

	Describe("NewStringSliceFlagWithDefault()", func() {
		It("init the flag context with a new StringSlice flagset with default value", func() {
			fc.Parse()
			Ω(fc.IsSet("s")).To(BeFalse())
			Ω(fc.StringSlice("s")).To(Equal([]string{}))