bash

package
v2.0.0-pre3 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2020 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &command.Command{
	Cobra: &cobra.Command{
		Use:   "bash",
		Short: "Generates shell autocompletion file for Triton",
		Long: `Generates a shell autocompletion script for Triton.

By default, the file is written directly to /etc/bash_completion.d
for convenience, and the command may need superuser rights, e.g.:

	$ sudo triton shell autocomplete bash

Add ` + "`--bash-autocomplete-dir=/path/to/file`" + ` flag to set alternative
folder location.

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

	$ . /etc/bash_completion`,

		PreRunE: func(cmd *cobra.Command, args []string) error {
			return nil
		},
		RunE: func(cmd *cobra.Command, args []string) error {
			target := viper.GetString(config.KeyBashAutoCompletionTarget)
			if _, err := os.Stat(target); os.IsNotExist(err) {
				if err := os.MkdirAll(target, 0777); err != nil {
					return errors.Wrapf(err, "unable to make bash-autocomplete-target %q", target)
				}
			}
			bashFile := fmt.Sprintf("%s/triton.sh", target)
			err := cmd.Root().GenBashCompletionFile(bashFile)
			if err != nil {
				return err
			}

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

			return nil
		},
	},
	Setup: func(parent *command.Command) error {

		{
			const (
				key          = config.KeyBashAutoCompletionTarget
				longName     = "bash-autocomplete-dir"
				defaultValue = "/etc/bash_completion.d"
				description  = "autocompletion directory"
			)

			flags := parent.Cobra.PersistentFlags()
			flags.String(longName, defaultValue, description)
			viper.BindPFlag(key, flags.Lookup(longName))
		}

		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