本文整理汇总了Golang中github.com/spf13/cobra.Command类的典型用法代码示例。如果您正苦于以下问题:Golang Command类的具体用法?Golang Command怎么用?Golang Command使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Command类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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])
}
开发者ID:Hellblazer,项目名称:cockroach,代码行数:10,代码来源:accounting.go
示例2: initCoreCommonFlags
// initCoreCommonFlags initializes common flags used by Hugo core commands.
func initCoreCommonFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&cfgFile, "config", "", "config file (default is path/config.yaml|json|toml)")
// Set bash-completion
validConfigFilenames := []string{"json", "js", "yaml", "yml", "toml", "tml"}
cmd.Flags().SetAnnotation("config", cobra.BashCompFilenameExt, validConfigFilenames)
}
开发者ID:nitoyon,项目名称:hugo,代码行数:8,代码来源:hugo.go
示例3: serverComplexFlags
func serverComplexFlags(ccmd *cobra.Command) {
serverSimpleFlags(ccmd)
ccmd.Flags().StringVarP(&server.Forwarder, "server-forwarder", "f", "g", "Forwarder method [g i m]")
ccmd.Flags().IntVarP(&server.Weight, "server-weight", "w", 1, "weight of down-stream server")
ccmd.Flags().IntVarP(&server.UpperThreshold, "server-upper-threshold", "u", 0, "Upper threshold of down-stream server")
ccmd.Flags().IntVarP(&server.LowerThreshold, "server-lower-threshold", "l", 0, "Lower threshold of down-stream server")
}
开发者ID:nanopack,项目名称:portal,代码行数:7,代码来源:server.go
示例4: AddDestroySub
func (a *Acl) AddDestroySub(c *cobra.Command) {
destroyCmd := &cobra.Command{
Use: "destroy <token>",
Short: "Destroy an ACL",
Long: "Destroy an ACL",
RunE: func(cmd *cobra.Command, args []string) error {
return a.Destroy(args)
},
}
oldDestroyCmd := &cobra.Command{
Use: "acl-destroy <token>",
Short: "Destroy an ACL",
Long: "Destroy an ACL",
Deprecated: "Use acl destroy",
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
return a.Destroy(args)
},
}
c.AddCommand(destroyCmd)
a.AddCommand(oldDestroyCmd)
}
开发者ID:CiscoCloud,项目名称:consul-cli,代码行数:25,代码来源:acl_destroy.go
示例5: UseOptionsTemplates
func UseOptionsTemplates(cmd *cobra.Command) {
cmd.SetHelpTemplate(OptionsHelpTemplate())
templater := &templater{
UsageTemplate: OptionsUsageTemplate(),
}
cmd.SetUsageFunc(templater.UsageFunc())
}
开发者ID:cjnygard,项目名称:origin,代码行数:7,代码来源:templater.go
示例6: GetFlagBool
func GetFlagBool(cmd *cobra.Command, flag string) bool {
b, err := cmd.Flags().GetBool(flag)
if err != nil {
glog.Fatalf("err accessing flag %s for command %s: %v", flag, cmd.Name(), err)
}
return b
}
开发者ID:ncdc,项目名称:origin,代码行数:7,代码来源:helpers.go
示例7: GetFlagDuration
func GetFlagDuration(cmd *cobra.Command, flag string) time.Duration {
d, err := cmd.Flags().GetDuration(flag)
if err != nil {
glog.Fatalf("err accessing flag %s for command %s: %v", flag, cmd.Name(), err)
}
return d
}
开发者ID:ncdc,项目名称:origin,代码行数:7,代码来源:helpers.go
示例8: addServiceFlags
// addServiceFlags adds all flags that are common to both `create` and `update`.
// Any flags that are not common are added separately in the individual command
func addServiceFlags(cmd *cobra.Command, opts *serviceOptions) {
flags := cmd.Flags()
flags.StringVar(&opts.name, flagName, "", "Service name")
flags.StringVarP(&opts.workdir, flagWorkdir, "w", "", "Working directory inside the container")
flags.StringVarP(&opts.user, flagUser, "u", "", "Username or UID (format: <name|uid>[:<group|gid>])")
flags.StringSliceVar(&opts.groups, flagGroupAdd, []string{}, "Add additional user groups to the container")
flags.Var(&opts.resources.limitCPU, flagLimitCPU, "Limit CPUs")
flags.Var(&opts.resources.limitMemBytes, flagLimitMemory, "Limit Memory")
flags.Var(&opts.resources.resCPU, flagReserveCPU, "Reserve CPUs")
flags.Var(&opts.resources.resMemBytes, flagReserveMemory, "Reserve Memory")
flags.Var(&opts.stopGrace, flagStopGracePeriod, "Time to wait before force killing a container")
flags.Var(&opts.replicas, flagReplicas, "Number of tasks")
flags.StringVar(&opts.restartPolicy.condition, flagRestartCondition, "", "Restart when condition is met (none, on-failure, or any)")
flags.Var(&opts.restartPolicy.delay, flagRestartDelay, "Delay between restart attempts")
flags.Var(&opts.restartPolicy.maxAttempts, flagRestartMaxAttempts, "Maximum number of restarts before giving up")
flags.Var(&opts.restartPolicy.window, flagRestartWindow, "Window used to evaluate the restart policy")
flags.Uint64Var(&opts.update.parallelism, flagUpdateParallelism, 1, "Maximum number of tasks updated simultaneously (0 to update all at once)")
flags.DurationVar(&opts.update.delay, flagUpdateDelay, time.Duration(0), "Delay between updates")
flags.StringVar(&opts.update.onFailure, flagUpdateFailureAction, "pause", "Action on update failure (pause|continue)")
flags.StringVar(&opts.endpoint.mode, flagEndpointMode, "", "Endpoint mode (vip or dnsrr)")
flags.BoolVar(&opts.registryAuth, flagRegistryAuth, false, "Send registry authentication details to swarm agents")
flags.StringVar(&opts.logDriver.name, flagLogDriver, "", "Logging driver for service")
flags.Var(&opts.logDriver.opts, flagLogOpt, "Logging driver options")
}
开发者ID:HuKeping,项目名称:docker,代码行数:34,代码来源:opts.go
示例9: GetFlagStringList
// GetFlagStringList can be used to accept multiple argument with flag repetition (e.g. -f arg1 -f arg2 ...)
func GetFlagStringList(cmd *cobra.Command, flag string) util.StringList {
f := cmd.Flags().Lookup(flag)
if f == nil {
return util.StringList{}
}
return *f.Value.(*util.StringList)
}
开发者ID:Tlacenka,项目名称:origin,代码行数:8,代码来源:helpers.go
示例10: 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
}
开发者ID:joshix,项目名称:acbuild,代码行数:25,代码来源:run.go
示例11: runRmPerms
// runRmPerms invokes the REST API with DELETE action and key prefix as
// path.
func runRmPerms(cmd *cobra.Command, args []string) {
if len(args) != 1 {
cmd.Usage()
return
}
server.RunRmPerm(Context, args[0])
}
开发者ID:simonzhangsm,项目名称:cockroach,代码行数:9,代码来源:permission.go
示例12: runDeleteContext
func runDeleteContext(out io.Writer, configAccess clientcmd.ConfigAccess, cmd *cobra.Command) error {
config, err := configAccess.GetStartingConfig()
if err != nil {
return err
}
args := cmd.Flags().Args()
if len(args) != 1 {
cmd.Help()
return nil
}
configFile := configAccess.GetDefaultFilename()
if configAccess.IsExplicitFile() {
configFile = configAccess.GetExplicitFile()
}
name := args[0]
_, ok := config.Contexts[name]
if !ok {
return fmt.Errorf("cannot delete context %s, not in %s", name, configFile)
}
delete(config.Contexts, name)
if err := clientcmd.ModifyConfig(configAccess, *config, true); err != nil {
return err
}
fmt.Fprintf(out, "deleted context %s from %s", name, configFile)
return nil
}
开发者ID:humblec,项目名称:kubernetes,代码行数:33,代码来源:delete_context.go
示例13: tufAdd
func tufAdd(cmd *cobra.Command, args []string) {
if len(args) < 3 {
cmd.Usage()
fatalf("must specify a GUN, target, and path to target data")
}
gun := args[0]
targetName := args[1]
targetPath := args[2]
kdb := keys.NewDB()
signer := signed.NewSigner(NewCryptoService(gun))
repo := tuf.NewTufRepo(kdb, signer)
b, err := ioutil.ReadFile(targetPath)
if err != nil {
fatalf(err.Error())
}
filestore := bootstrapRepo(gun, repo)
fmt.Println("Generating metadata for target")
meta, err := data.NewFileMeta(bytes.NewBuffer(b))
if err != nil {
fatalf(err.Error())
}
fmt.Printf("Adding target \"%s\" with sha256 \"%s\" and size %d bytes.\n", targetName, meta.Hashes["sha256"], meta.Length)
_, err = repo.AddTargets("targets", data.Files{targetName: meta})
if err != nil {
fatalf(err.Error())
}
saveRepo(repo, filestore)
}
开发者ID:progrium,项目名称:notary,代码行数:34,代码来源:tuf.go
示例14: 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)
}
}
}
开发者ID:progrium,项目名称:notary,代码行数:35,代码来源:tuf.go
示例15: GetFlagStringSlice
// GetFlagStringList can be used to accept multiple argument with flag repetition (e.g. -f arg1 -f arg2 ...)
func GetFlagStringSlice(cmd *cobra.Command, flag string) []string {
s, err := cmd.Flags().GetStringSlice(flag)
if err != nil {
glog.Fatalf("err accessing flag %s for command %s: %v", flag, cmd.Name(), err)
}
return s
}
开发者ID:ncdc,项目名称:origin,代码行数:8,代码来源:helpers.go
示例16: 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)
}
}
开发者ID:jalateras,项目名称:notary,代码行数:25,代码来源:keys.go
示例17: GetWideFlag
// GetWideFlag is used to determine if "-o wide" is used
func GetWideFlag(cmd *cobra.Command) bool {
f := cmd.Flags().Lookup("output")
if f.Value.String() == "wide" {
return true
}
return false
}
开发者ID:ncdc,项目名称:origin,代码行数:8,代码来源:helpers.go
示例18: runGenManCmd
func runGenManCmd(cmd *cobra.Command, args []string) error {
info := build.GetInfo()
header := &doc.GenManHeader{
Section: "1",
Manual: "CockroachDB Manual",
Source: fmt.Sprintf("CockroachDB %s", info.Tag),
}
if !strings.HasSuffix(manPath, string(os.PathSeparator)) {
manPath += string(os.PathSeparator)
}
if _, err := os.Stat(manPath); err != nil {
if os.IsNotExist(err) {
if err := os.MkdirAll(manPath, 0755); err != nil {
return err
}
} else {
return err
}
}
if err := doc.GenManTree(cmd.Root(), header, manPath); err != nil {
return err
}
// TODO(cdo): The man page generated by the cobra package doesn't include a list of commands, so
// one has to notice the "See Also" section at the bottom of the page to know which commands
// are supported. I'd like to make this better somehow.
fmt.Println("Generated CockroachDB man pages in", manPath)
return nil
}
开发者ID:knz,项目名称:cockroach,代码行数:33,代码来源:gen.go
示例19: GetFlagInt64
// Assumes the flag has a default value.
func GetFlagInt64(cmd *cobra.Command, flag string) int64 {
i, err := cmd.Flags().GetInt64(flag)
if err != nil {
glog.Fatalf("err accessing flag %s for command %s: %v", flag, cmd.Name(), err)
}
return i
}
开发者ID:ncdc,项目名称:origin,代码行数:8,代码来源:helpers.go
示例20: runGenAutocompleteCmd
func runGenAutocompleteCmd(cmd *cobra.Command, args []string) error {
if err := cmd.Root().GenBashCompletionFile(autoCompletePath); err != nil {
return err
}
fmt.Println("Generated bash completion file", autoCompletePath)
return nil
}
开发者ID:knz,项目名称:cockroach,代码行数:7,代码来源:gen.go
注:本文中的github.com/spf13/cobra.Command类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论