bash

package
v0.0.0-...-b801540 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2018 License: BSD-2-Clause Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &command.Command{
	Name: cmdName,

	Cobra: &cobra.Command{
		Use:   cmdName,
		Short: "Generates and install " + buildtime.PROGNAME + " bash autocompletion script",
		Long: `Generates a bash autocompletion script for ` + buildtime.PROGNAME + `

By default, the file is written directly to ` + config.DefaultBashAutoCompletionDir + `
for convenience, and the command may need superuser rights, e.g.:

	$ sudo vpc shell autocomplete bash

Add ` + "`--bash-autocomplete-dir=/path/to/file`" + `. The default file name
is ` + buildtime.PROGNAME + `.sh.

Logout and in again to reload the completion scripts,
or just source them in directly:

	$ . /bash_completion.d`,

		PreRunE: func(cmd *cobra.Command, args []string) error {
			return nil
		},

		RunE: func(cmd *cobra.Command, args []string) error {
			bashDir := viper.GetString(config.KeyShellAutoCompBashDir)
			if _, err := os.Stat(bashDir); os.IsNotExist(err) {
				if err := os.MkdirAll(bashDir, 0777); err != nil {
					return errors.Wrapf(err, "unable to create bash autocomplete directory %q", bashDir)
				}
			}

			bashFile := path.Join(bashDir, buildtime.PROGNAME+".sh")
			err := cmd.Root().GenBashCompletionFile(bashFile)
			if err != nil {
				return errors.Wrap(err, "unable to generate bash completion")
			}

			log.Info().Msg("Installation completed successfully.")

			return nil
		},
	},

	Setup: func(self *command.Command) error {
		{
			const (
				key               = config.KeyShellAutoCompBashDir
				shortOpt, longOpt = "d", "dir"
				defaultValue      = config.DefaultBashAutoCompletionDir
				description       = "autocompletion directory"
			)

			flags := self.Cobra.Flags()
			flags.StringP(longOpt, shortOpt, defaultValue, description)
			viper.BindPFlag(key, flags.Lookup(longOpt))
		}

		return nil
	},
}

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