當前位置: 首頁>>代碼示例>>Golang>>正文


Golang stdcli.DirApp函數代碼示例

本文整理匯總了Golang中github.com/convox/cli/stdcli.DirApp函數的典型用法代碼示例。如果您正苦於以下問題:Golang DirApp函數的具體用法?Golang DirApp怎麽用?Golang DirApp使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了DirApp函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: cmdEnvSet

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

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

	resp, err := fetchEnv(app)

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

	var old map[string]string
	err = json.Unmarshal(resp, &old)

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

	data := ""

	for key, value := range old {
		data += fmt.Sprintf("%s=%s\n", key, value)
	}

	stat, err := os.Stdin.Stat()

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

	if (stat.Mode() & os.ModeCharDevice) == 0 {
		in, err := ioutil.ReadAll(os.Stdin)

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

		data += string(in)
	}

	for _, value := range c.Args() {
		data += fmt.Sprintf("%s\n", value)
	}

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

	resp, err = ConvoxPost(path, data)

	if err != nil {
		stdcli.Error(err)
		return
	}
}
開發者ID:nguyendangminh,項目名稱:cli,代碼行數:60,代碼來源:env.go

示例2: cmdEnvGetAll

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

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

	resp, err := fetchEnv(app)

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

	var env map[string]string
	err = json.Unmarshal(resp, &env)

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

	keys := []string{}

	for key, _ := range env {
		keys = append(keys, key)
	}

	sort.Strings(keys)

	for _, key := range keys {
		fmt.Printf("%s=%s\n", key, env[key])
	}
}
開發者ID:nguyendangminh,項目名稱:cli,代碼行數:35,代碼來源:env.go

示例3: cmdEnvUnset

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

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

	if len(c.Args()) == 0 {
		stdcli.Error(errors.New("No variable specified"))
		return
	}

	if len(c.Args()) > 1 {
		stdcli.Error(errors.New("Only 1 variable can be unset at a time"))
		return
	}

	variable := c.Args()[0]

	path := fmt.Sprintf("/apps/%s/environment/%s", app, variable)

	_, err = ConvoxDelete(path)

	if err != nil {
		stdcli.Error(err)
		return
	}
}
開發者ID:nguyendangminh,項目名稱:cli,代碼行數:29,代碼來源:env.go

示例4: cmdEnvUnset

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

	if err != nil {
		stdcli.Error(err)
		return
	}
	if len(c.Args()) == 1 {
		variable := c.Args()[0]

		path := fmt.Sprintf("/apps/%s/environment/%s", app, variable)

		_, err = ConvoxDelete(path)

		if err != nil {
			stdcli.Error(err)
			return
		}
	else {
		fmt.Printf("You supplied %d arguments to convox env unset, 1 is required\n", len(c.Args()))
	}
}

func fetchEnv(app string) ([]byte, error) {
	path := fmt.Sprintf("/apps/%s/environment", app)

	resp, err := ConvoxGet(path)

	if err != nil {
		return nil, err
	}

	return resp, nil
}
開發者ID:srri,項目名稱:cli,代碼行數:34,代碼來源:env.go

示例5: cmdBuilds

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

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

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

	resp, err := ConvoxGet(path)

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

	var builds []Build

	err = json.Unmarshal(resp, &builds)

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

	fmt.Printf("%-12s  %-12s  %-9s  %-22s  %s\n", "ID", "RELEASE", "STATUS", "STARTED", "ENDED")

	for _, build := range builds {
		started := build.Started
		ended := build.Ended
		fmt.Printf("%-12s  %-12s  %-9s  %-22s  %s\n", build.Id, build.Release, build.Status, started.Format(time.RFC822Z), ended.Format(time.RFC822Z))
	}
}
開發者ID:noqcks,項目名稱:cli,代碼行數:34,代碼來源:builds.go

示例6: cmdEnvGet

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

	if err != nil {
		stdcli.Error(err)
		return
	}
	if len(c.Args()) == 1 {
		variable := c.Args()[0]

		resp, err := fetchEnv(app)

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

		var env map[string]string
		json.Unmarshal(resp, &env)

		fmt.Println(env[variable])
	} else {
        	fmt.Printf("You supplied %d arguments to convox env get, 1 is required\n", len(c.Args()))
        }
}
開發者ID:srri,項目名稱:cli,代碼行數:25,代碼來源:env.go

示例7: 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

示例8: 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

示例9: 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

示例10: cmdEnvGet

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

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

	if len(c.Args()) == 0 {
		stdcli.Error(errors.New("No variable specified"))
		return
	}

	if len(c.Args()) > 1 {
		stdcli.Error(errors.New("Only 1 variable can be retrieved at a time"))
		return
	}

	variable := c.Args()[0]

	resp, err := fetchEnv(app)

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

	var env map[string]string
	json.Unmarshal(resp, &env)

	fmt.Println(env[variable])
}
開發者ID:redbadger,項目名稱:cli,代碼行數:32,代碼來源:env.go

示例11: cmdPs

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

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

	if len(c.Args()) == 0 {
		processList(app)
	} else {
		processTop(app, c.Args()[0])
	}
}
開發者ID:ngotnghet,項目名稱:cli,代碼行數:14,代碼來源:ps.go

示例12: cmdReleases

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

	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)

	data, err = ConvoxGet(fmt.Sprintf("/apps/%s/releases", a.Name))

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

	var releases *Releases
	err = json.Unmarshal(data, &releases)

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

	t := stdcli.NewTable("ID", "CREATED", "ACTIVE")

	for _, r := range *releases {
		active := ""
		if a.Parameters["Release"] == r.Id {
			active = "yes"
		}

		t.AddRow(r.Id, humanize.Time(r.Created), active)
	}

	t.Print()
}
開發者ID:2opremio,項目名稱:cli,代碼行數:46,代碼來源:releases.go

示例13: cmdScale

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

	if err != nil {
		stdcli.Error(err)
		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 {
		_, 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
	}

	fmt.Printf("Count %v\n", a.Parameters["DesiredCount"])
	fmt.Printf("Memory %v\n", a.Parameters["Memory"])
}
開發者ID:nguyendangminh,項目名稱:cli,代碼行數:45,代碼來源:scale.go

示例14: cmdEnvUnset

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

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

	variable := c.Args()[0]

	path := fmt.Sprintf("/apps/%s/environment/%s", app, variable)

	_, err = ConvoxDelete(path)

	if err != nil {
		stdcli.Error(err)
		return
	}
}
開發者ID:rjocoleman,項目名稱:cli,代碼行數:19,代碼來源:env.go

示例15: cmdDebug

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

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

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

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

	lines := strings.Split(string(data), "\n")
	for i := len(lines) - 1; i >= 0; i-- {
		fmt.Printf("%v\n", lines[i])
	}
}
開發者ID:ngotnghet,項目名稱:cli,代碼行數:20,代碼來源:debug.go


注:本文中的github.com/convox/cli/stdcli.DirApp函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。