commands

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: Apache-2.0 Copyright © 2022 Roberto Hidalgo <chinampa@un.rob.mx>

Copyright © 2022 Roberto Hidalgo <chinampa@un.rob.mx> SPDX-License-Identifier: Apache-2.0

Copyright © 2022 Roberto Hidalgo <chinampa@un.rob.mx> SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

View Source
var GenerateCompletions = &cobra.Command{
	Use:               "__generate_completions [bash|zsh|fish]",
	Short:             "Outputs a shell-specific script for autocompletions that can be piped into a file",
	Hidden:            true,
	DisableAutoGenTag: true,
	SilenceUsage:      true,
	Args:              cobra.ExactArgs(1),
	ValidArgs:         []string{"bash", "fish", "zsh"},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		switch args[0] {
		case "bash":
			err = cmd.Root().GenBashCompletionV2(os.Stdout, true)
		case "zsh":
			err = cmd.Root().GenZshCompletion(os.Stdout)
		case "fish":
			err = cmd.Root().GenFishCompletion(os.Stdout, true)
		}
		return
	},
}
View Source
var Help = &cobra.Command{
	Use:   _c.HelpCommandName,
	Short: "Display usage information for any command",
	Long: `Provides documentation for any command known to ﹅@chinampa@﹅, including its known arguments and options.

### Colorized output

By default, and unless ﹅` + env.NoColor + `﹅ is set, ﹅@chinampa@ help﹅ will query the environment variable ﹅COLORFGBG﹅ to decide which style to use when rendering help, unless if ﹅` + env.HelpStyle + `﹅ is set to any of the following values: **light**, **dark**, **markdown**, or **auto**. 24-bit color is available when ﹅COLORTERM﹅ is set to ﹅truecolor﹅.`,
	ValidArgsFunction: func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		var completions []string
		cmd, _, e := c.Root().Find(args)
		if e != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}
		if cmd == nil {

			cmd = c.Root()
		}
		for _, subCmd := range cmd.Commands() {
			if subCmd.IsAvailableCommand() || subCmd.Name() == _c.HelpCommandName {
				if strings.HasPrefix(subCmd.Name(), toComplete) {
					completions = append(completions, fmt.Sprintf("%s\t%s", subCmd.Name(), subCmd.Short))
				}
			}
		}
		return completions, cobra.ShellCompDirectiveNoFileComp
	},
	Run: func(c *cobra.Command, args []string) {
		if len(args) > 0 && c != nil && c.Name() != args[len(args)-1] {
			c, topicArgs, err := c.Root().Find(args)
			if err == nil && c != nil && len(topicArgs) == 0 {

				cobra.CheckErr(c.Help())
				os.Exit(statuscode.RenderHelp)
				return
			}

			if err != nil {
				logrus.Error(err)
				os.Exit(statuscode.ProgrammerError)
			}

			fullName := strings.Join(cobraCommandFullName(c), " ")
			cobra.CheckErr(c.Help())
			if len(topicArgs) > 0 {
				logrus.Errorf("Unknown help topic \"%s\" for %s", topicArgs[0], fullName)
			} else {
				logrus.Errorf("Unknown help topic \"%s\"", args[0])
			}
			os.Exit(statuscode.NotFound)
		}

		c.InitDefaultHelpFlag()
		cobra.CheckErr(c.Help())

		os.Exit(statuscode.RenderHelp)
	},
}
View Source
var Version = &cobra.Command{
	Use:               VersionCommandName,
	Short:             "Display program version",
	Hidden:            false,
	DisableAutoGenTag: true,
	SilenceUsage:      true,
	RunE: func(cmd *cobra.Command, args []string) error {
		output := cmd.ErrOrStderr()
		version := cmd.Root().Annotations["version"]
		if cmd.CalledAs() == "" {

			output = cmd.OutOrStderr()
			version += "\n"
		}

		_, err := output.Write([]byte(version))
		if err != nil {
			logger.Main.Errorf("version error: %s", err)
			return err
		}

		os.Exit(statuscode.Ok)
		return nil
	},
}
View Source
var VersionCommandName = "version"

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL