本文整理汇总了Golang中github.com/spf13/cobra.Command.Help方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.Help方法的具体用法?Golang Command.Help怎么用?Golang Command.Help使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/spf13/cobra.Command
的用法示例。
在下文中一共展示了Command.Help方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewMigration
func NewMigration(cmd *cobra.Command, args []string) {
if len(args) != 1 {
cmd.Help()
os.Exit(1)
}
name := args[0]
migrationsPath := cliOptions.migrationsPath
migrations, err := migrate.FindMigrations(migrationsPath)
if err != nil {
fmt.Fprintf(os.Stderr, "Error loading migrations:\n %v\n", err)
os.Exit(1)
}
newMigrationName := fmt.Sprintf("%03d_%s.sql", len(migrations)+1, name)
// Write new migration
mPath := filepath.Join(migrationsPath, newMigrationName)
mFile, err := os.OpenFile(mPath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, os.ModePerm)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
defer mFile.Close()
_, err = mFile.WriteString(newMigrationText)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
示例2: Complete
// Complete verifies command line arguments and loads data from the command environment
func (o *RsyncOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args []string) error {
switch n := len(args); {
case n == 0:
cmd.Help()
fallthrough
case n < 2:
return kcmdutil.UsageError(cmd, "SOURCE_DIR and POD:DESTINATION_DIR are required arguments")
case n > 2:
return kcmdutil.UsageError(cmd, "only SOURCE_DIR and POD:DESTINATION_DIR should be specified as arguments")
}
// Set main command arguments
var err error
o.Source, err = parsePathSpec(args[0])
if err != nil {
return err
}
o.Destination, err = parsePathSpec(args[1])
if err != nil {
return err
}
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
o.Namespace = namespace
o.Strategy, err = o.determineStrategy(f, cmd, o.StrategyName)
if err != nil {
return err
}
return nil
}
示例3: runStatus
// runStatus is the code that implements the status command.
func runStatus(cmd *cobra.Command, args []string) {
cmd.Printf("Status User : Pid[%s] Email[%s] Active[%v]\n", status.pid, status.email, status.active)
if status.pid == "" && status.email == "" {
cmd.Help()
return
}
db := db.NewMGO()
defer db.CloseMGO()
var publicID string
if status.pid != "" {
publicID = status.pid
} else {
u, err := auth.GetUserByEmail("", db, status.email, false)
if err != nil {
cmd.Println("Status User : ", err)
return
}
publicID = u.PublicID
}
st := auth.StatusDisabled
if status.active {
st = auth.StatusActive
}
if err := auth.UpdateUserStatus("", db, publicID, st); err != nil {
cmd.Println("Status User : ", err)
return
}
cmd.Println("Status User : Updated")
}
示例4: versionInfo
// versionInfo displays the build and versioning information.
func versionInfo(cmd *cli.Command, args []string) {
if version {
fmt.Println(common.BuildInfo())
os.Exit(0)
}
cmd.Help()
}
示例5: runCreate
// runCreate is the code that implements the create command.
func runCreate(cmd *cobra.Command, args []string) {
cmd.Printf("Creating User : Name[%s] Email[%s] Pass[%s]\n", create.name, create.email, create.pass)
if create.name == "" && create.email == "" && create.pass == "" {
cmd.Help()
return
}
u, err := auth.NewUser(auth.NUser{
Status: auth.StatusActive,
FullName: create.name,
Email: create.email,
Password: create.pass,
})
if err != nil {
cmd.Println("Creating User : ", err)
return
}
if err := auth.CreateUser("", conn, u); err != nil {
cmd.Println("Creating User : ", err)
return
}
webTok, err := auth.CreateWebToken("", conn, u, 24*365*time.Hour)
if err != nil {
cmd.Println("Creating User : ", err)
return
}
cmd.Printf("\nToken: %s\n\n", webTok)
}
示例6: performCommand
// Where all the work happens.
func performCommand(cmd *cobra.Command, args []string) error {
if displayVersion {
fmt.Printf("%s %s\n", appName, version)
return nil
}
if listProviders {
fmt.Printf(providers.DisplayProviders())
return nil
}
query := strings.Join(args, " ")
if query != "" {
err := providers.Search(binary, provider, query, verbose)
if err != nil {
return err
}
} else {
// Don't return an error, help screen is more appropriate.
cmd.Help()
}
return nil
}
示例7: 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
}
示例8: complete
func (o *NewProjectOptions) complete(cmd *cobra.Command, f *clientcmd.Factory) error {
args := cmd.Flags().Args()
if len(args) != 1 {
cmd.Help()
return errors.New("must have exactly one argument")
}
o.ProjectName = args[0]
if !o.SkipConfigWrite {
o.ProjectOptions = &ProjectOptions{}
o.ProjectOptions.PathOptions = cliconfig.NewPathOptions(cmd)
if err := o.ProjectOptions.Complete(f, []string{""}, o.Out); err != nil {
return err
}
} else {
clientConfig, err := f.OpenShiftClientConfig.ClientConfig()
if err != nil {
return err
}
o.Server = clientConfig.Host
}
return nil
}
示例9: CommandSave
func CommandSave(cmd *cobra.Command, args []string) {
mustLoadConfig(cmd)
now := time.Now()
// find the directory
dir := ""
switch len(args) {
case 0:
dir = "."
case 1:
dir = args[0]
default:
cmd.Help()
return
}
problem, _, commit, _ := gather(now, dir)
commit.Action = ""
commit.Note = "saving from grind tool"
unsigned := &CommitBundle{Commit: commit}
// send the commit to the server
signed := new(CommitBundle)
mustPostObject("/commit_bundles/unsigned", nil, unsigned, signed)
log.Printf("problem %s step %d saved", problem.Unique, commit.Step)
}
示例10: login
func login(cmd *cobra.Command, args []string) {
if len(args) != 2 {
cmd.Help()
os.Exit(1)
}
con, err := grpc.Dial(authAddr, grpc.WithInsecure())
if err != nil {
log.Error(err)
fmt.Println("Cannot connect to authentication unit")
os.Exit(1)
}
defer con.Close()
c := pb.NewAuthClient(con)
in := &pb.AuthRequest{}
in.Username = args[0]
in.Password = args[1]
ctx := context.Background()
res, err := c.Authenticate(ctx, in)
if err != nil {
if grpc.Code(err) == codes.Unauthenticated {
fmt.Println("Invalid username or password")
os.Exit(1)
}
fmt.Println("Cannot connect to authentication unit")
os.Exit(1)
}
// Save token into $HOME/.clawiobench/credentials
u, err := user.Current()
if err != nil {
log.Error(err)
fmt.Println("Cannot access your home directory")
os.Exit(1)
}
err = os.MkdirAll(path.Join(u.HomeDir, ".clawiobench"), 0755)
if err != nil {
log.Error(err)
fmt.Println("Cannot create $HOME/.clawiobench configuration directory")
os.Exit(1)
}
err = ioutil.WriteFile(path.Join(u.HomeDir, ".clawiobench", "credentials"), []byte(res.Token), 0644)
if err != nil {
log.Error(err)
fmt.Println("Cannot save credentials into $HOME/.clawiobench/credentials")
os.Exit(1)
}
fmt.Println("You are logged in as " + in.Username)
os.Exit(0)
}
示例11: MakeChain
func MakeChain(cmd *cobra.Command, args []string) {
argsMin := 1
if len(args) < argsMin {
cmd.Help()
IfExit(fmt.Errorf("\n**Note** you sent our marmots the wrong number of arguments.\nPlease send the marmots at least %d argument(s).", argsMin))
}
do.Name = args[0]
IfExit(maker.MakeChain(do))
}
示例12: preRun
func (c *CLI) preRun(cmd *cobra.Command, args []string) {
if c.cfgFile != "" && gotil.FileExists(c.cfgFile) {
if err := c.r.Config.ReadConfigFile(c.cfgFile); err != nil {
panic(err)
}
cmd.Flags().Parse(os.Args[1:])
}
c.updateLogLevel()
c.r.Config = c.r.Config.Scope("rexray.modules.default-docker")
if isHelpFlag(cmd) {
cmd.Help()
panic(&helpFlagPanic{})
}
if permErr := c.checkCmdPermRequirements(cmd); permErr != nil {
if term.IsTerminal() {
printColorizedError(permErr)
} else {
printNonColorizedError(permErr)
}
fmt.Println()
cmd.Help()
panic(&printedErrorPanic{})
}
if c.isInitDriverManagersCmd(cmd) {
if err := c.r.InitDrivers(); err != nil {
if term.IsTerminal() {
printColorizedError(err)
} else {
printNonColorizedError(err)
}
fmt.Println()
helpCmd := cmd
if cmd == c.volumeCmd {
helpCmd = c.volumeGetCmd
} else if cmd == c.snapshotCmd {
helpCmd = c.snapshotGetCmd
} else if cmd == c.deviceCmd {
helpCmd = c.deviceGetCmd
} else if cmd == c.adapterCmd {
helpCmd = c.adapterGetTypesCmd
}
helpCmd.Help()
panic(&printedErrorPanic{})
}
}
}
示例13: complete
func (o *useContextOptions) complete(cmd *cobra.Command) bool {
endingArgs := cmd.Flags().Args()
if len(endingArgs) != 1 {
cmd.Help()
return false
}
o.contextName = endingArgs[0]
return true
}
示例14: Assigned
func Assigned(cmd *cobra.Command, args []string) {
if len(args) == 1 {
cmd.Help()
} else if len(args) == 0 {
fip := AssignedFIP(cmd)
fmt.Println(fip)
} else {
os.Exit(1)
}
}
示例15: complete
func (o *createClusterOptions) complete(cmd *cobra.Command) bool {
args := cmd.Flags().Args()
if len(args) != 1 {
cmd.Help()
return false
}
o.name = args[0]
return true
}