Golang Command.Usage Examples

Golang Command.Usage - 30 examples found. These are the top rated real world Golang examples of github.com/spf13/cobra.Command.Usage extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
func runAddMount(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 2 {
		stderr("mount add: incorrect number of arguments")
		return 1
	}

	if debug {
		if readOnly {
			stderr("Adding read only mount point %q=%q", args[0], args[1])
		} else {
			stderr("Adding mount point %q=%q", args[0], args[1])
		}
	}

	err := newACBuild().AddMount(args[0], args[1], readOnly)

	if err != nil {
		stderr("mount add: %v", err)
		return getErrorCode(err)
	}

	return 0
}
Example #2
0
func runRun(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}

	if debug {
		stderr("Running: %v", args)
	}

	engine, ok := engines[engineName]
	if !ok {
		stderr("run: no such engine %q", engineName)
		return 1
	}

	err := newACBuild().Run(args, workingdir, insecure, engine)

	if err != nil {
		stderr("run: %v", err)
		return getErrorCode(err)
	}

	return 0
}
Example #3
0
func keysList(cmd *cobra.Command, args []string) {
	if len(args) > 0 {
		cmd.Usage()
		os.Exit(1)
	}

	fmt.Println("# Trusted CAs:")
	trustedCAs := caStore.GetCertificates()
	for _, c := range trustedCAs {
		printCert(c)
	}

	fmt.Println("")
	fmt.Println("# Trusted Certificates:")
	trustedCerts := certificateStore.GetCertificates()
	for _, c := range trustedCerts {
		printCert(c)
	}

	fmt.Println("")
	fmt.Println("# Signing keys: ")
	for _, k := range privKeyStore.ListFiles(true) {
		printKey(k)
	}
}
Example #4
0
File: new.go Project: maruel/hugo
// NewContent adds new content to a Hugo site.
func NewContent(cmd *cobra.Command, args []string) {
	InitializeConfig()

	if cmd.Flags().Lookup("format").Changed {
		viper.Set("MetaDataFormat", configFormat)
	}

	if len(args) < 1 {
		cmd.Usage()
		jww.FATAL.Fatalln("path needs to be provided")
	}

	createpath := args[0]

	var kind string

	createpath, kind = newContentPathSection(createpath)

	if contentType != "" {
		kind = contentType
	}

	err := create.NewContent(kind, createpath)
	if err != nil {
		jww.ERROR.Println(err)
	}
}
Example #5
0
func tufList(cmd *cobra.Command, args []string) {
	if len(args) < 1 {
		cmd.Usage()
		fatalf("must specify a GUN")
	}
	gun := args[0]
	kdb := keys.NewDB()
	repo := tuf.NewTufRepo(kdb, nil)

	remote, err := store.NewHTTPStore(
		"https://notary:4443/v2/"+gun+"/_trust/tuf/",
		"",
		"json",
		"",
	)
	c, err := bootstrapClient(remote, repo, kdb)
	if err != nil {
		return
	}
	err = c.Update()
	if err != nil {
		logrus.Error("Error updating client: ", err.Error())
		return
	}

	if rawOutput {
		for name, meta := range repo.Targets["targets"].Signed.Targets {
			fmt.Println(name, " ", meta.Hashes["sha256"], " ", meta.Length)
		}
	} else {
		for name, meta := range repo.Targets["targets"].Signed.Targets {
			fmt.Println(name, " ", meta.Hashes["sha256"], " ", meta.Length)
		}
	}
}
Example #6
0
func runInc(cmd *cobra.Command, args []string) {
	if len(args) > 2 {
		cmd.Usage()
		return
	}

	kvDB := makeDBClient()
	if kvDB == nil {
		return
	}
	amount := 1
	if len(args) >= 2 {
		var err error
		if amount, err = strconv.Atoi(args[1]); err != nil {
			fmt.Fprintf(osStderr, "invalid increment: %s: %s\n", args[1], err)
			osExit(1)
			return
		}
	}

	key := proto.Key(unquoteArg(args[0], true /* disallow system keys */))
	if r, err := kvDB.Inc(key, int64(amount)); err != nil {
		fmt.Fprintf(osStderr, "increment failed: %s\n", err)
		osExit(1)
	} else {
		fmt.Printf("%d\n", r.ValueInt())
	}
}