• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang stdcli.Usage函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/convox/cli/stdcli.Usage函数的典型用法代码示例。如果您正苦于以下问题:Golang Usage函数的具体用法?Golang Usage怎么用?Golang Usage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Usage函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: cmdExec

func cmdExec(c *cli.Context) {
	_, app, err := stdcli.DirApp(c, ".")

	if err != nil {
		stdcli.Error(err)
		return
	}

	if len(c.Args()) < 1 {
		stdcli.Usage(c, "exec")
		return
	}

	ps := c.Args()[0]

	command := ""

	if len(c.Args()) > 1 {
		args := c.Args()[1:]
		command = strings.Join(args, " ")
	}

	err = stdcli.Run("docker", "exec", "-it", fmt.Sprintf("%s-%s", app, ps), "sh", "-c", command)

	if err != nil {
		stdcli.Error(err)
		return
	}
}
开发者ID:nguyendangminh,项目名称:cli,代码行数:29,代码来源:exec.go


示例2: cmdServiceInfo

func cmdServiceInfo(c *cli.Context) {
	if len(c.Args()) != 1 {
		stdcli.Usage(c, "info")
		return
	}

	name := c.Args()[0]

	data, err := ConvoxGet("/services/" + name)

	if err != nil {
		stdcli.Error(err)
		return
	}

	var s *Service
	err = json.Unmarshal(data, &s)

	if err != nil {
		stdcli.Error(err)
		return
	}

	fmt.Printf("Name    %s\n", s.Name)
	fmt.Printf("Status  %s\n", s.Status)
	fmt.Printf("URL     %s\n", s.URL)
}
开发者ID:linearregression,项目名称:cli,代码行数:27,代码来源:services.go


示例3: cmdRun

func cmdRun(c *cli.Context) {
	_, app, err := stdcli.DirApp(c, ".")

	if err != nil {
		stdcli.Error(err)
		return
	}

	if len(c.Args()) < 1 {
		stdcli.Usage(c, "run")
		return
	}

	ps := c.Args()[0]

	command := ""

	if len(c.Args()) > 1 {
		args := c.Args()[1:]
		command = strings.Join(args, " ")
	}

	v := url.Values{}
	v.Set("command", command)

	_, err = ConvoxPostForm(fmt.Sprintf("/apps/%s/processes/%s/run", app, ps), v)

	if err != nil {
		stdcli.Error(err)
		return
	}

	fmt.Printf("Running %s `%s`\n", ps, command)
}
开发者ID:ngotnghet,项目名称:cli,代码行数:34,代码来源:run.go


示例4: cmdBuildsInfo

func cmdBuildsInfo(c *cli.Context) {
	_, app, err := stdcli.DirApp(c, ".")

	if err != nil {
		stdcli.Error(err)
		return
	}

	if len(c.Args()) != 1 {
		stdcli.Usage(c, "info")
		return
	}

	build := c.Args()[0]

	path := fmt.Sprintf("/apps/%s/builds/%s", app, build)

	resp, err := ConvoxGet(path)

	if err != nil {
		stdcli.Error(err)
		return
	}

	var b Build

	err = json.Unmarshal(resp, &b)

	if err != nil {
		stdcli.Error(err)
		return
	}

	fmt.Println(b.Logs)
}
开发者ID:noqcks,项目名称:cli,代码行数:35,代码来源:builds.go


示例5: cmdServiceInfo

func cmdServiceInfo(c *cli.Context) {
	if len(c.Args()) != 1 {
		stdcli.Usage(c, "info")
		return
	}

	name := c.Args()[0]

	data, err := ConvoxGet("/services/" + name)

	if err != nil {
		stdcli.Error(err)
		return
	}

	var s *Service
	err = json.Unmarshal(data, &s)

	if err != nil {
		stdcli.Error(err)
		return
	}

	fmt.Printf("Name    %s\n", s.Name)
	fmt.Printf("Status  %s\n", s.Status)
	fmt.Printf("URL     %s\n", fmt.Sprintf("%s://%s:%[email protected]%s:%s/%s", s.Tags["Service"], s.Outputs["EnvPostgresUsername"], s.Outputs["EnvPostgresPassword"], s.Outputs["Port5432TcpAddr"], s.Outputs["Port5432TcpPort"], s.Outputs["EnvPostgresDatabase"]))
}
开发者ID:ngotnghet,项目名称:cli,代码行数:27,代码来源:services.go


示例6: cmdServiceCreate

func cmdServiceCreate(c *cli.Context) {
	if len(c.Args()) != 2 {
		stdcli.Usage(c, "create")
		return
	}

	name := c.Args()[0]
	t := c.Args()[1]

	fmt.Printf("Creating service %s (%s)... ", name, t)

	v := url.Values{}
	v.Set("name", name)
	v.Set("type", t)
	data, err := ConvoxPostForm("/services", v)

	if err != nil {
		stdcli.Error(err)
		return
	}

	data, err = ConvoxGet("/services/" + name)

	if err != nil {
		stdcli.Error(err)
		return
	}

	var s *Service
	err = json.Unmarshal(data, &s)

	if err != nil {
		stdcli.Error(err)
		return
	}

	// poll for complete
	for {
		data, err = ConvoxGet(fmt.Sprintf("/services/%s/status", name))

		if err != nil {
			stdcli.Error(err)
			return
		}

		if string(data) == "running" {
			break
		}

		time.Sleep(3 * time.Second)
	}

	fmt.Printf("OK, %s\n", s.Name)
}
开发者ID:linearregression,项目名称:cli,代码行数:54,代码来源:services.go


示例7: cmdSwitch

func cmdSwitch(c *cli.Context) {
	if len(c.Args()) < 1 {
		stdcli.Usage(c, "switch")
		return
	}

	host := c.Args()[0]

	err := switchHost(host)

	if err != nil {
		stdcli.Error(err)
		return
	}

	fmt.Printf("Switched to %s\n", host)
}
开发者ID:nguyendangminh,项目名称:cli,代码行数:17,代码来源:switch.go


示例8: cmdAppDelete

func cmdAppDelete(c *cli.Context) {
	if len(c.Args()) < 1 {
		stdcli.Usage(c, "delete")
		return
	}

	app := c.Args()[0]

	fmt.Printf("Deleting %s: ", app)

	_, err := ConvoxDelete(fmt.Sprintf("/apps/%s", app))

	if err != nil {
		stdcli.Error(err)
		return
	}

	fmt.Println("OK")
}
开发者ID:rjocoleman,项目名称:cli,代码行数:19,代码来源:apps.go


示例9: cmdServiceDelete

func cmdServiceDelete(c *cli.Context) {
	if len(c.Args()) != 1 {
		stdcli.Usage(c, "delete")
		return
	}

	name := c.Args()[0]

	fmt.Printf("Deleting %s... ", name)

	_, err := ConvoxDelete(fmt.Sprintf("/services/%s", name))

	if err != nil {
		stdcli.Error(err)
		return
	}

	fmt.Println("OK")
}
开发者ID:linearregression,项目名称:cli,代码行数:19,代码来源:services.go


示例10: cmdReleasePromote

func cmdReleasePromote(c *cli.Context) {
	if len(c.Args()) < 1 {
		stdcli.Usage(c, "release promote")
		return
	}

	release := c.Args()[0]

	_, app, err := stdcli.DirApp(c, ".")

	if err != nil {
		stdcli.Error(err)
		return
	}

	_, err = postRelease(app, release)

	if err != nil {
		stdcli.Error(err)
		return
	}
}
开发者ID:noqcks,项目名称:cli,代码行数:22,代码来源:releases.go


示例11: cmdReleaseInfo

func cmdReleaseInfo(c *cli.Context) {
	if len(c.Args()) < 1 {
		stdcli.Usage(c, "release info")
		return
	}

	release := c.Args()[0]

	_, app, err := stdcli.DirApp(c, ".")

	if err != nil {
		stdcli.Error(err)
		return
	}

	data, err := ConvoxGet(fmt.Sprintf("/apps/%s/releases/%s", app, release))

	if err != nil {
		stdcli.Error(err)
		return
	}

	var r Release

	err = json.Unmarshal(data, &r)

	if err != nil {
		stdcli.Error(err)
		return
	}

	fmt.Printf("Id       %s\n", r.Id)
	fmt.Printf("Build    %s\n", r.Build)
	fmt.Printf("Created  %s\n", r.Created)
	fmt.Printf("Env      ")
	fmt.Println(strings.Replace(r.Env, "\n", "\n         ", -1))
}
开发者ID:noqcks,项目名称:cli,代码行数:37,代码来源:releases.go


示例12: cmdPsStop

func cmdPsStop(c *cli.Context) {
	_, app, err := stdcli.DirApp(c, ".")

	if err != nil {
		stdcli.Error(err)
		return
	}

	if len(c.Args()) != 1 {
		stdcli.Usage(c, "stop")
		return
	}

	id := c.Args()[0]

	_, err = ConvoxDelete(fmt.Sprintf("/apps/%s/processes/%s", app, id))

	if err != nil {
		stdcli.Error(err)
		return
	}

	fmt.Printf("Stopping %s\n", id)
}
开发者ID:ngotnghet,项目名称:cli,代码行数:24,代码来源:ps.go


示例13: cmdScale

func cmdScale(c *cli.Context) {
	_, app, err := stdcli.DirApp(c, ".")

	if err != nil {
		stdcli.Error(err)
		return
	}

	if len(c.Args()) < 1 {
		stdcli.Usage(c, "scale")
		return
	}

	v := url.Values{}

	if c.IsSet("count") {
		v.Set("count", c.String("count"))
	}

	if c.IsSet("memory") {
		v.Set("mem", c.String("memory"))
	}

	if len(v) > 0 {
		v.Set("process", c.Args()[0])

		_, err = ConvoxPostForm("/apps/"+app, v)

		if err != nil {
			stdcli.Error(err)
			return
		}
	}

	data, err := ConvoxGet("/apps/" + app)

	if err != nil {
		stdcli.Error(err)
		return
	}

	var a *App
	err = json.Unmarshal(data, &a)

	if err != nil {
		stdcli.Error(err)
		return
	}

	processes := make(map[string]Process, 0)

	longest := 7

	for k, v := range a.Parameters {
		if !strings.HasSuffix(k, "DesiredCount") {
			continue
		}

		ps := strings.Replace(k, "DesiredCount", "", 1)
		p := strings.ToLower(ps)

		i, err := strconv.ParseInt(v, 10, 64)

		if err != nil {
			stdcli.Error(err)
			return
		}

		m, err := strconv.ParseInt(a.Parameters[ps+"Memory"], 10, 64)

		if err != nil {
			stdcli.Error(err)
			return
		}

		processes[p] = Process{Name: p, Count: i, Memory: m}
	}

	fmt.Printf(fmt.Sprintf("%%-%ds  %%-5s  %%-5s\n", longest), "PROCESS", "COUNT", "MEM")

	for _, ps := range processes {
		fmt.Printf(fmt.Sprintf("%%-%ds  %%-5d  %%-5d\n", longest), ps.Name, ps.Count, ps.Memory)
	}
}
开发者ID:noqcks,项目名称:cli,代码行数:84,代码来源:scale.go


示例14: cmdAppInfo

func cmdAppInfo(c *cli.Context) {
	if len(c.Args()) < 1 {
		stdcli.Usage(c, "info")
		return
	}

	app := c.Args()[0]

	data, err := ConvoxGet("/apps/" + app)

	if err != nil {
		stdcli.Error(err)
		return
	}

	var a *App
	err = json.Unmarshal(data, &a)

	if err != nil {
		stdcli.Error(err)
		return
	}

	matcher := regexp.MustCompile(`^(\w+)Port\d+Balancer`)

	ports := []string{}

	for key, value := range a.Outputs {
		if m := matcher.FindStringSubmatch(key); m != nil {
			ports = append(ports, fmt.Sprintf("%s:%s", strings.ToLower(m[1]), value))
		}
	}

	processes := []string{}

	for key, _ := range a.Parameters {
		if strings.HasSuffix(key, "Image") {
			processes = append(processes, strings.ToLower(key[0:len(key)-5]))
		}
	}

	sort.Strings(processes)

	if len(processes) == 0 {
		processes = append(processes, "(none)")
	}

	if len(ports) == 0 {
		ports = append(ports, "(none)")
	}

	release := a.Parameters["Release"]

	if release == "" {
		release = "(none)"
	}

	fmt.Printf("Name       %s\n", a.Name)
	fmt.Printf("Status     %s\n", a.Status)
	fmt.Printf("Release    %s\n", release)
	fmt.Printf("Processes  %s\n", strings.Join(processes, " "))

	if a.Outputs["BalancerHost"] != "" {
		fmt.Printf("Hostname   %s\n", a.Outputs["BalancerHost"])
		fmt.Printf("Ports      %s\n", strings.Join(ports, " "))
	}
}
开发者ID:ngotnghet,项目名称:cli,代码行数:67,代码来源:apps.go


示例15: cmdLogin

func cmdLogin(c *cli.Context) {
	if len(c.Args()) != 1 {
		stdcli.Usage(c, "login")
	}

	host := c.Args()[0]
	u, err := url.Parse(host)

	if err != nil {
		stdcli.Error(err)
		return
	}

	if u.Host != "" {
		host = u.Host
	}

	password := c.String("password")

	if password == "" {
		fmt.Print("Password: ")

		in, err := terminal.ReadPassword(int(os.Stdin.Fd()))

		fmt.Println()

		if err != nil {
			stdcli.Error(err)
			return
		}

		password = string(in)
	}

	client := &http.Client{
		Transport: &http.Transport{
			TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
		},
	}

	req, err := http.NewRequest("GET", fmt.Sprintf("https://%s/apps", host), nil)

	if err != nil {
		stdcli.Error(err)
		return
	}

	req.SetBasicAuth("convox", string(password))

	res, err := client.Do(req)

	if err != nil {
		stdcli.Error(err)
		return
	}

	defer res.Body.Close()

	if res.StatusCode != 200 {
		stdcli.Error(fmt.Errorf("invalid login"))
		return
	}

	err = addLogin(host, password)

	if err != nil {
		stdcli.Error(err)
		return
	}

	err = switchHost(host)

	if err != nil {
		stdcli.Error(err)
		return
	}

	fmt.Println("Logged in successfully.")
}
开发者ID:ngotnghet,项目名称:cli,代码行数:79,代码来源:login.go


示例16: cmdRunAttached

func cmdRunAttached(c *cli.Context) {
	fd := os.Stdin.Fd()
	oldState, err := term.SetRawTerminal(fd)
	if err != nil {
		stdcli.Error(err)
		return
	}
	defer term.RestoreTerminal(fd, oldState)

	_, app, err := stdcli.DirApp(c, ".")

	if err != nil {
		stdcli.Error(err)
		return
	}

	if len(c.Args()) < 2 {
		stdcli.Usage(c, "run")
		return
	}

	ps := c.Args()[0]

	host, password, err := currentLogin()

	if err != nil {
		stdcli.Error(err)
		return
	}

	origin := fmt.Sprintf("https://%s", host)
	url := fmt.Sprintf("wss://%s/apps/%s/processes/%s/run", host, app, ps)

	config, err := websocket.NewConfig(url, origin)

	if err != nil {
		stdcli.Error(err)
		return
	}

	command := strings.Join(c.Args()[1:], " ")

	config.Header.Set("Command", command)

	userpass := fmt.Sprintf("convox:%s", password)
	userpass_encoded := b64.StdEncoding.EncodeToString([]byte(userpass))

	config.Header.Add("Authorization", fmt.Sprintf("Basic %s", userpass_encoded))

	config.TlsConfig = &tls.Config{
		InsecureSkipVerify: true,
	}

	ws, err := websocket.DialConfig(config)

	if err != nil {
		stdcli.Error(err)
		return
	}

	defer ws.Close()

	ch := make(chan int)
	go io.Copy(ws, os.Stdin)
	go messageReceive(ws, os.Stdout, ch)

	code := <-ch

	term.RestoreTerminal(os.Stdin.Fd(), oldState)
	os.Exit(code)
}
开发者ID:noqcks,项目名称:cli,代码行数:71,代码来源:run.go



注:本文中的github.com/convox/cli/stdcli.Usage函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang aws.String函数代码示例发布时间:2022-05-23
下一篇:
Golang stdcli.RegisterCommand函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap