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


Golang Command.Help方法代码示例

本文整理汇总了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)
	}

}
开发者ID:jackc,项目名称:tern,代码行数:33,代码来源:main.go

示例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
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:36,代码来源:rsync.go

示例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")
}
开发者ID:ramakrishna580,项目名称:kit,代码行数:36,代码来源:status.go

示例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()
}
开发者ID:romana,项目名称:core,代码行数:8,代码来源:root.go

示例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)
}
开发者ID:taotetek,项目名称:kit,代码行数:33,代码来源:create.go

示例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
}
开发者ID:tw4dl,项目名称:s,代码行数:26,代码来源:search.go

示例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
}
开发者ID:humblec,项目名称:kubernetes,代码行数:33,代码来源:delete_context.go

示例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
}
开发者ID:abhgupta,项目名称:origin,代码行数:25,代码来源:request_project.go

示例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)
}
开发者ID:RidleyLarsen,项目名称:codegrinder,代码行数:26,代码来源:save.go

示例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)
}
开发者ID:clawio,项目名称:clawiobench,代码行数:59,代码来源:login.go

示例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))
}
开发者ID:eris-ltd,项目名称:eris-cm,代码行数:9,代码来源:maker.go

示例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{})
		}
	}
}
开发者ID:luk5,项目名称:rexray,代码行数:56,代码来源:cli.go

示例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
}
开发者ID:ttysteale,项目名称:kubernetes-api,代码行数:10,代码来源:use_context.go

示例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)
	}
}
开发者ID:andrewsomething,项目名称:floatctl,代码行数:10,代码来源:assigned.go

示例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
}
开发者ID:40a,项目名称:bootkube,代码行数:10,代码来源:create_cluster.go


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