本文整理汇总了Golang中github.com/spf13/cobra.Command.Usage方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.Usage方法的具体用法?Golang Command.Usage怎么用?Golang Command.Usage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/spf13/cobra.Command
的用法示例。
在下文中一共展示了Command.Usage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runSetAcct
// runSetAcct invokes the REST API with POST action and key prefix as
// path. The specified configuration file is read from disk and sent
// as the POST body.
func runSetAcct(cmd *cobra.Command, args []string) {
if len(args) != 2 {
cmd.Usage()
return
}
server.RunSetAcct(Context, args[0], args[1])
}
示例2: runAddMount
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
}
示例3: keysList
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)
}
}
示例4: runRun
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
}
示例5: rangeFunc
func rangeFunc(cmd *cobra.Command, args []string) {
if len(args) == 0 || len(args) > 2 {
fmt.Fprintln(os.Stderr, cmd.Usage())
os.Exit(1)
}
k := args[0]
end := ""
if len(args) == 2 {
end = args[1]
}
if rangeConsistency == "l" {
fmt.Println("bench with linearizable range")
} else if rangeConsistency == "s" {
fmt.Println("bench with serializable range")
} else {
fmt.Fprintln(os.Stderr, cmd.Usage())
os.Exit(1)
}
requests := make(chan v3.Op, totalClients)
clients := mustCreateClients(totalClients, totalConns)
bar = pb.New(rangeTotal)
bar.Format("Bom !")
bar.Start()
r := newReport()
for i := range clients {
wg.Add(1)
go func(c *v3.Client) {
defer wg.Done()
for op := range requests {
st := time.Now()
_, err := c.Do(context.Background(), op)
r.Results() <- report.Result{Err: err, Start: st, End: time.Now()}
bar.Increment()
}
}(clients[i])
}
go func() {
for i := 0; i < rangeTotal; i++ {
opts := []v3.OpOption{v3.WithRange(end)}
if rangeConsistency == "s" {
opts = append(opts, v3.WithSerializable())
}
op := v3.OpGet(k, opts...)
requests <- op
}
close(requests)
}()
rc := r.Run()
wg.Wait()
close(r.Results())
bar.Finish()
fmt.Printf("%s", <-rc)
}
示例6: tufList
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)
}
}
}
示例7: NewContent
// 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)
}
}
示例8: runTerm
func runTerm(cmd *cobra.Command, args []string) {
if len(args) != 0 {
cmd.Usage()
return
}
db := makeSQLClient()
liner := liner.NewLiner()
defer func() {
_ = liner.Close()
}()
for {
l, err := liner.Prompt("> ")
if err != nil {
if err != io.EOF {
fmt.Fprintf(os.Stderr, "Input error: %s\n", err)
}
break
}
if len(l) == 0 {
continue
}
liner.AppendHistory(l)
if err := processOneLine(db, l); err != nil {
fmt.Printf("Error: %s\n", err)
}
}
}
示例9: runInc
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())
}
}
示例10: lightColor
func lightColor(c *cobra.Command, args []string) {
if flagLightHue == 0 && flagLightSaturation == 0 && flagLightBrightness == 0 && flagLightKelvin == 0 {
if err := c.Usage(); err != nil {
logger.WithField(`error`, err).Fatalln(`Failed to print usage`)
}
fmt.Println()
logger.Fatalln(`Missing color definition`)
}
lights := getLights()
color := common.Color{
Hue: flagLightHue,
Saturation: flagLightSaturation,
Brightness: flagLightBrightness,
Kelvin: flagLightKelvin,
}
if len(lights) > 0 {
for _, light := range lights {
if err := light.SetColor(color, flagLightDuration); err != nil {
logger.WithFields(logrus.Fields{
`light-id`: light.ID(),
`error`: err,
}).Fatalln(`Failed setting color for light`)
}
}
} else {
if err := client.SetColor(color, flagLightDuration); err != nil {
logger.WithField(`error`, err).Fatalln(`Failed setting color for lights`)
}
}
}
示例11: tunnelDisconnectCmd
func tunnelDisconnectCmd(cmd *cobra.Command, args []string) {
if len(args) != 1 {
cmd.Usage()
os.Exit(1)
}
key, err := key.DecodePublic(args[0])
if err != nil {
fmt.Println("Error reading server public key,", err)
}
c := Connect()
indexes, err := c.IpTunnel_listConnections()
if err != nil {
fmt.Println("Error getting tunnel information,", err)
os.Exit(1)
}
for _, i := range indexes {
info, err := c.IpTunnel_showConnection(i)
if err != nil {
fmt.Println(err)
continue
}
if info.Key.Equal(key) {
if err = c.IpTunnel_removeConnection(i); err != nil {
fmt.Println("Failed to remove tunnel,", err)
os.Exit(1)
}
return
}
}
fmt.Println("tunnel not found")
}
示例12: tufLookup
func (t *tufCommander) tufLookup(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
cmd.Usage()
return fmt.Errorf("Must specify a GUN and target")
}
config, err := t.configGetter()
if err != nil {
return err
}
gun := args[0]
targetName := args[1]
rt, err := getTransport(config, gun, true)
if err != nil {
return err
}
nRepo, err := notaryclient.NewNotaryRepository(
config.GetString("trust_dir"), gun, getRemoteTrustServer(config), rt, t.retriever)
if err != nil {
return err
}
target, err := nRepo.GetTargetByName(targetName)
if err != nil {
return err
}
cmd.Println(target.Name, fmt.Sprintf("sha256:%x", target.Hashes["sha256"]), target.Length)
return nil
}
示例13: tufList
func (t *tufCommander) tufList(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmd.Usage()
return fmt.Errorf("Must specify a GUN")
}
config, err := t.configGetter()
if err != nil {
return err
}
gun := args[0]
rt, err := getTransport(config, gun, true)
if err != nil {
return err
}
nRepo, err := notaryclient.NewNotaryRepository(
config.GetString("trust_dir"), gun, getRemoteTrustServer(config), rt, t.retriever)
if err != nil {
return err
}
// Retrieve the remote list of signed targets, prioritizing the passed-in list over targets
roles := append(t.roles, data.CanonicalTargetsRole)
targetList, err := nRepo.ListTargets(roles...)
if err != nil {
return err
}
prettyPrintTargets(targetList, cmd.Out())
return nil
}
示例14: tufAdd
func (t *tufCommander) tufAdd(cmd *cobra.Command, args []string) error {
if len(args) < 3 {
cmd.Usage()
return fmt.Errorf("Must specify a GUN, target, and path to target data")
}
config, err := t.configGetter()
if err != nil {
return err
}
gun := args[0]
targetName := args[1]
targetPath := args[2]
// no online operations are performed by add so the transport argument
// should be nil
nRepo, err := notaryclient.NewNotaryRepository(
config.GetString("trust_dir"), gun, getRemoteTrustServer(config), nil, t.retriever)
if err != nil {
return err
}
target, err := notaryclient.NewTarget(targetName, targetPath)
if err != nil {
return err
}
// If roles is empty, we default to adding to targets
if err = nRepo.AddTarget(target, t.roles...); err != nil {
return err
}
cmd.Printf(
"Addition of target \"%s\" to repository \"%s\" staged for next publish.\n",
targetName, gun)
return nil
}
示例15: groupColor
func groupColor(c *cobra.Command, args []string) {
if flagGroupHue == 0 && flagGroupSaturation == 0 && flagGroupBrightness == 0 && flagGroupKelvin == 0 {
if err := c.Usage(); err != nil {
logger.WithField(`error`, err).Fatalln(`Failed to print usage`)
}
fmt.Println()
logger.Fatalln(`Missing color definition`)
}
groups := getGroups()
color := common.Color{
Hue: flagGroupHue,
Saturation: flagGroupSaturation,
Brightness: flagGroupBrightness,
Kelvin: flagGroupKelvin,
}
if len(groups) > 0 {
for _, group := range groups {
if err := group.SetColor(color, flagGroupDuration); err != nil {
logger.WithFields(logrus.Fields{
`group-id`: group.ID(),
`error`: err,
}).Fatalln(`Failed setting color for group`)
}
}
} else {
if err := client.SetColor(color, flagGroupDuration); err != nil {
logger.WithField(`error`, err).Fatalln(`Failed setting color for groups`)
}
}
}