当前位置: 首页>>代码示例>>Golang>>正文


Golang cli.ShowCommandHelp函数代码示例

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


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

示例1: loadPlugin

func loadPlugin(ctx *cli.Context) {
	pAsc := ctx.String("plugin-asc")
	var paths []string
	if len(ctx.Args()) != 1 {
		fmt.Println("Incorrect usage:")
		cli.ShowCommandHelp(ctx, ctx.Command.Name)
		os.Exit(1)
	}
	paths = append(paths, ctx.Args().First())
	if pAsc != "" {
		if !strings.Contains(pAsc, ".asc") {
			fmt.Println("Must be a .asc file for the -a flag")
			cli.ShowCommandHelp(ctx, ctx.Command.Name)
			os.Exit(1)
		}
		paths = append(paths, pAsc)
	}
	r := pClient.LoadPlugin(paths)
	if r.Err != nil {
		if r.Err.Fields()["error"] != nil {
			fmt.Printf("Error loading plugin:\n%v\n%v\n", r.Err.Error(), r.Err.Fields()["error"])
		} else {
			fmt.Printf("Error loading plugin:\n%v\n", r.Err.Error())
		}
		os.Exit(1)
	}
	for _, p := range r.LoadedPlugins {
		fmt.Println("Plugin loaded")
		fmt.Printf("Name: %s\n", p.Name)
		fmt.Printf("Version: %d\n", p.Version)
		fmt.Printf("Type: %s\n", p.Type)
		fmt.Printf("Signed: %v\n", p.Signed)
		fmt.Printf("Loaded Time: %s\n\n", p.LoadedTime().Format(timeFormat))
	}
}
开发者ID:gitter-badger,项目名称:snap-1,代码行数:35,代码来源:plugin.go

示例2: cmdServer

func cmdServer(ctx *cli.Context) {
	c, err := config.GetConfiguration(ctx)
	if err != nil {
		cli.ShowCommandHelp(ctx, "server")
		fmt.Println("Could not get configuration. Reason:", err)
		log.Fatalln("Exiting....")
	}

	if ctx.String("port") == "" {
		cli.ShowCommandHelp(ctx, "server")
		fmt.Println("Missing port")
		log.Fatalln("Exiting....")
	}

	executor := execution.NewExecutor(c.AggregateOutput, c.FailuresOnly, c.StateChangeOnly, c.ResultFormatter(), c.Writer(), c.Workers)

	asrt := NewAsrtHandler(c, executor)
	asrt.refreshServerCache()
	go asrt.loopServerCacheRefresh()

	http.Handle("/data", asrt)
	http.HandleFunc("/", serveStaticWebFiles)

	fmt.Println("Listening on port:", ctx.String("port"))
	log.Fatal(http.ListenAndServe(fmt.Sprintf(":%v", ctx.String("port")), nil))
}
开发者ID:mkboudreau,项目名称:asrt,代码行数:26,代码来源:server.go

示例3: cliDeleteRevNat

func cliDeleteRevNat(ctx *cli.Context) {
	if ctx.Bool("all") {
		if err := client.RevNATDeleteAll(); err != nil {
			fmt.Fprintf(os.Stderr, "%s", err)
			os.Exit(1)
		}
	} else {
		if len(ctx.Args()) == 0 {
			cli.ShowCommandHelp(ctx, "delete-rev-nat")
			os.Exit(1)
		}

		id, err := strconv.ParseUint(ctx.Args().Get(0), 10, 16)
		if err != nil {
			cli.ShowCommandHelp(ctx, "delete-rev-nat")
			os.Exit(1)
		}

		if err := client.RevNATDelete(types.ServiceID(id)); err != nil {
			fmt.Fprintf(os.Stderr, "%s\n", err)
			os.Exit(1)
		}
	}
	fmt.Printf("Successfully deleted\n")
}
开发者ID:cilium-team,项目名称:cilium,代码行数:25,代码来源:main.go

示例4: oci2docker

func oci2docker(c *cli.Context) {
	ociPath := c.String("oci-bundle")
	imgName := c.String("image-name")
	port := c.String("port")

	if ociPath == "" {
		cli.ShowCommandHelp(c, "convert")
		return
	}

	if imgName == "" {
		cli.ShowCommandHelp(c, "convert")
		return
	}

	_, err := os.Stat(ociPath)
	if os.IsNotExist(err) {
		cli.ShowCommandHelp(c, "convert")
		return
	}

	convert.RunOCI2Docker(ociPath, imgName, port)

	return
}
开发者ID:ChengTiesheng,项目名称:oci2docker,代码行数:25,代码来源:main.go

示例5: cmdSetAdmin

func cmdSetAdmin(c *cli.Context) error {
	s, err := openAndCheck(c)
	if err != nil {
		return cli.NewExitError(err.Error(), 3)
	}

	username := c.Args().First()
	if username == "" {
		cli.ShowCommandHelp(c, "set-admin")
		return cli.NewExitError("", 0)
	}

	isAdmin, err := strconv.ParseBool(c.Args().Get(1))
	if err != nil {
		cli.ShowCommandHelp(c, "set-admin")
		return cli.NewExitError("", 0)
	}

	if err := s.GetInterface().SetAdmin(username, isAdmin); err != nil {
		return cli.NewExitError(fmt.Sprintf("Error changing admin status of user '%s': %s", username, err), 3)
	}

	if isAdmin {
		return cli.NewExitError(fmt.Sprintf("user '%s' is now an admin!", username), 0)
	} else {
		return cli.NewExitError(fmt.Sprintf("user '%s' is now a normal user!", username), 0)
	}
}
开发者ID:whawty,项目名称:auth,代码行数:28,代码来源:main.go

示例6: getClientCredentials

func getClientCredentials(c *cli.Context) []string {
	credentials := []string{c.GlobalString("client-id"), c.GlobalString("client-secret")}

	if credentials[0] == "" || credentials[1] == "" {
		color.Yellow("No client credentials given. Fallback to builtin default...")
		color.Yellow("Keep in mind that your document might be visible to other users.")
		color.Yellow("Your unique user-id is the only secret to protect your data.\n\n")

		superSecretSecret := []byte("V;4nJvuANmoywKNYk.yewNhqwmAQctc3BvByxeozQVpiK")

		// Decode HEX default credentials
		credentialsBytes, err := hex.DecodeString(defaultClientCredentials)
		if err != nil {
			color.Red("Error: client-id and client-secret missing and fallback decoding (step 1) failed: %s\n\n", err)
			cli.ShowCommandHelp(c, c.Command.FullName())
			os.Exit(1)
		}

		decodedCredentials := strings.Split(string(xorBytes(credentialsBytes, superSecretSecret)), ":")

		if len(decodedCredentials) < 2 {
			color.Red("Error: client-id and client-secret missing and fallback decoding (step 2) failed: %s\n\n", err)
			cli.ShowCommandHelp(c, c.Command.FullName())
			os.Exit(1)
		}
		credentials = decodedCredentials
	}

	return credentials
}
开发者ID:gini,项目名称:gapicmd,代码行数:30,代码来源:utils.go

示例7: unloadPlugin

func unloadPlugin(ctx *cli.Context) {
	pType := ctx.String("plugin-type")
	pName := ctx.String("plugin-name")
	pVer := ctx.Int("plugin-version")
	if pName == "" {
		fmt.Println("Must provide plugin name")
		cli.ShowCommandHelp(ctx, ctx.Command.Name)
		os.Exit(1)
	}
	if pVer < 1 {
		fmt.Println("Must provide plugin version")
		cli.ShowCommandHelp(ctx, ctx.Command.Name)
		os.Exit(1)
	}

	r := pClient.UnloadPlugin(pType, pName, pVer)
	if r.Err != nil {
		fmt.Printf("Error unloading plugin:\n%v\n", r.Err.Error())
		os.Exit(1)
	}

	fmt.Println("Plugin unloaded")
	fmt.Printf("Name: %s\n", r.Name)
	fmt.Printf("Version: %d\n", r.Version)
	fmt.Printf("Type: %s\n", r.Type)
}
开发者ID:gitter-badger,项目名称:snap-1,代码行数:26,代码来源:plugin.go

示例8: getConfig

func getConfig(ctx *cli.Context) {
	pDetails := filepath.SplitList(ctx.Args().First())
	var ptyp string
	var pname string
	var pver int
	var err error

	if len(pDetails) == 3 {
		ptyp = pDetails[0]
		pname = pDetails[1]
		pver, err = strconv.Atoi(pDetails[2])
		if err != nil {
			fmt.Println("Can't convert version string to integer")
			cli.ShowCommandHelp(ctx, ctx.Command.Name)
			os.Exit(1)
		}
	} else {
		ptyp = ctx.String("plugin-type")
		pname = ctx.String("plugin-name")
		pver = ctx.Int("plugin-version")
	}

	if ptyp == "" {
		fmt.Println("Must provide plugin type")
		cli.ShowCommandHelp(ctx, ctx.Command.Name)
		os.Exit(1)
	}
	if pname == "" {
		fmt.Println("Must provide plugin name")
		cli.ShowCommandHelp(ctx, ctx.Command.Name)
		os.Exit(1)
	}
	if pver < 1 {
		fmt.Println("Must provide plugin version")
		cli.ShowCommandHelp(ctx, ctx.Command.Name)
		os.Exit(1)
	}
	w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
	defer w.Flush()
	printFields(w, false, 0,
		"NAME",
		"VALUE",
		"TYPE",
	)
	r := pClient.GetPluginConfig(ptyp, pname, strconv.Itoa(pver))
	for k, v := range r.Table() {
		switch t := v.(type) {
		case ctypes.ConfigValueInt:
			printFields(w, false, 0, k, t.Value, t.Type())
		case ctypes.ConfigValueBool:
			printFields(w, false, 0, k, t.Value, t.Type())
		case ctypes.ConfigValueFloat:
			printFields(w, false, 0, k, t.Value, t.Type())
		case ctypes.ConfigValueStr:
			printFields(w, false, 0, k, t.Value, t.Type())
		}
	}
}
开发者ID:jeffweiss,项目名称:snap,代码行数:58,代码来源:config.go

示例9: uploadDocument

func uploadDocument(c *cli.Context) {
	filename := c.String("filename")
	doctype := c.String("doctype")
	userid := getUserIdentifier(c)

	if len(c.Args()) < 1 {
		cli.ShowCommandHelp(c, c.Command.FullName())
		return
	}

	if _, err := os.Stat(c.Args().First()); os.IsNotExist(err) {
		color.Red("\nError: cannot find %s\n\n", c.Args().First())
		cli.ShowCommandHelp(c, c.Command.FullName())
		return
	}

	bodyBuf, err := os.Open(c.Args().First())
	if err != nil {
		color.Red("\nError: failed to read %s\n\n", c.Args().First())
		cli.ShowCommandHelp(c, c.Command.FullName())
		return
	}

	api := getApiClient(c)

	doc, err := api.Upload(bodyBuf, giniapi.UploadOptions{
		FileName:       filename,
		DocType:        doctype,
		UserIdentifier: userid,
	})

	if err != nil {
		color.Red("\nError: %s\n\n", err)
		return
	}

	done <- true
	wg.Wait()

	renderResults(doc)

	if c.GlobalBool("curl") {
		curl := curlData{
			Headers: map[string]string{
				"Accept":            "application/vnd.gini.v1+json",
				"X-User-Identifier": userid,
			},
			Body:   fmt.Sprintf("--data-binary '@%s'", c.Args().First()),
			URL:    fmt.Sprintf("%s/documents", api.Endpoints.API),
			Method: "POST",
		}

		curl.render(c)
	}
}
开发者ID:gini,项目名称:gapicmd,代码行数:55,代码来源:gini.go

示例10: doUpdate

func doUpdate(c *cli.Context) {
	conffile := c.GlobalString("conf")
	argHostIDs := c.Args()
	optName := c.String("name")
	optStatus := c.String("status")
	optRoleFullnames := c.StringSlice("roleFullname")

	if len(argHostIDs) < 1 {
		argHostIDs = make([]string, 1)
		if argHostIDs[0] = LoadHostIDFromConfig(conffile); argHostIDs[0] == "" {
			cli.ShowCommandHelp(c, "update")
			os.Exit(1)
		}
	}

	needUpdateHostStatus := optStatus != ""
	needUpdateHost := (optName != "" || len(optRoleFullnames) > 0)

	if !needUpdateHostStatus && !needUpdateHost {
		cli.ShowCommandHelp(c, "update")
		os.Exit(1)
	}

	client := newMackerel(conffile)

	var wg sync.WaitGroup
	for _, hostID := range argHostIDs {
		wg.Add(1)
		go func(hostID string) {
			defer wg.Done()

			if needUpdateHostStatus {
				err := client.UpdateHostStatus(hostID, optStatus)
				logger.DieIf(err)
			}

			if needUpdateHost {
				_, err := client.UpdateHost(hostID, &mkr.UpdateHostParam{
					Name:          optName,
					RoleFullnames: optRoleFullnames,
				})
				logger.DieIf(err)
			}

			logger.Log("updated", hostID)
		}(hostID)
	}

	wg.Wait()
}
开发者ID:syohex,项目名称:mkr,代码行数:50,代码来源:commands.go

示例11: unloadPlugin

func unloadPlugin(ctx *cli.Context) error {
	pDetails := filepath.SplitList(ctx.Args().First())
	var pType, pName string
	var pVer int
	var err error

	if len(pDetails) == 3 {
		pType = pDetails[0]
		pName = pDetails[1]
		pVer, err = strconv.Atoi(pDetails[2])
		if err != nil {
			fmt.Println("Can't convert version string to integer")
			cli.ShowCommandHelp(ctx, ctx.Command.Name)
			return errCritical
		}
	} else {
		pType = ctx.String("plugin-type")
		pName = ctx.String("plugin-name")
		pVer = ctx.Int("plugin-version")
	}
	if pType == "" {
		fmt.Println("Must provide plugin type")
		cli.ShowCommandHelp(ctx, ctx.Command.Name)
		return errCritical
	}
	if pName == "" {
		fmt.Println("Must provide plugin name")
		cli.ShowCommandHelp(ctx, ctx.Command.Name)
		return errCritical
	}
	if pVer < 1 {
		fmt.Println("Must provide plugin version")
		cli.ShowCommandHelp(ctx, ctx.Command.Name)
		return errCritical
	}

	r := pClient.UnloadPlugin(pType, pName, pVer)
	if r.Err != nil {
		fmt.Printf("Error unloading plugin:\n%v\n", r.Err.Error())
		return errCritical
	}

	fmt.Println("Plugin unloaded")
	fmt.Printf("Name: %s\n", r.Name)
	fmt.Printf("Version: %d\n", r.Version)
	fmt.Printf("Type: %s\n", r.Type)

	return nil
}
开发者ID:Collinux,项目名称:snap,代码行数:49,代码来源:plugin.go

示例12: main

func main() {
	app := cli.NewApp()
	app.Name = "spiff"
	app.Usage = "BOSH deployment manifest toolkit"
	app.Version = "1.0.8dev"

	app.Commands = []cli.Command{
		{
			Name:      "merge",
			ShortName: "m",
			Usage:     "merge stub files into a manifest template",
			Flags: []cli.Flag{
				cli.BoolFlag{
					Name:  "debug",
					Usage: "print state info",
				},
			},
			Action: func(c *cli.Context) {
				if len(c.Args()) < 1 {
					cli.ShowCommandHelp(c, "merge")
					os.Exit(1)
				}
				debug.DebugFlag = c.Bool("debug")
				merge(c.Args()[0], c.Args()[1:])
			},
		},
		{
			Name:      "diff",
			ShortName: "d",
			Usage:     "structurally compare two YAML files",
			Flags: []cli.Flag{
				cli.StringFlag{
					Name:  "separator",
					Usage: "separator to print between diffs",
				},
			},
			Action: func(c *cli.Context) {
				if len(c.Args()) < 2 {
					cli.ShowCommandHelp(c, "diff")
					os.Exit(1)
				}

				diff(c.Args()[0], c.Args()[1], c.String("separator"))
			},
		},
	}

	app.Run(os.Args)
}
开发者ID:gstackio,项目名称:spiff,代码行数:49,代码来源:spiff.go

示例13: FailWithUsage

func (c *terminalUI) FailWithUsage(context *cli.Context) {
	c.Say(FailureColor(T("FAILED")))
	c.Say(T("Incorrect Usage.\n"))
	cli.ShowCommandHelp(context, context.Command.Name)
	c.Say("")
	os.Exit(1)
}
开发者ID:raghulsid,项目名称:cli,代码行数:7,代码来源:ui.go

示例14: doGet

func doGet(c *cli.Context) {
	argURL := c.Args().Get(0)
	doUpdate := c.Bool("update")

	if argURL == "" {
		cli.ShowCommandHelp(c, "get")
		os.Exit(1)
	}

	url, err := url.Parse(argURL)
	utils.DieIf(err)

	if !url.IsAbs() {
		url.Scheme = "https"
		url.Host = "github.com"
		if url.Path[0] != '/' {
			url.Path = "/" + url.Path
		}
	}

	remote, err := NewRemoteRepository(url)
	utils.DieIf(err)

	if remote.IsValid() == false {
		utils.Log("error", fmt.Sprintf("Not a valid repository: %s", url))
		os.Exit(1)
	}

	getRemoteRepository(remote, doUpdate)
}
开发者ID:kentaro,项目名称:ghq,代码行数:30,代码来源:commands.go

示例15: cmdSquash

func (c *ServicedCli) cmdSquash(ctx *cli.Context) {

	imageName := ""
	baseLayer := ""
	newName := ""
	args := ctx.Args()
	switch len(ctx.Args()) {
	case 3:
		newName = args[2]
		fallthrough
	case 2:
		baseLayer = args[1]
		fallthrough
	case 1:
		imageName = args[0]
		break
	default:
		cli.ShowCommandHelp(ctx, "squash")
		return
	}

	imageID, err := c.driver.Squash(imageName, baseLayer, newName, ctx.String("tempdir"))
	if err != nil {
		glog.Fatalf("error squashing: %s", err)
	}
	fmt.Println(imageID)
}
开发者ID:eval01-tts,项目名称:serviced,代码行数:27,代码来源:docker.go


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