cmd

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2021 License: NCSA Imports: 18 Imported by: 2

README

#cmd Build Status

Tools for the command line for both RAI and CarML

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuildTimeCmd = &cobra.Command{
	Use:   "buildtime",
	Short: "Print the time the binary was compiled",
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("BuildDate: ", Version.BuildDate)
	},
}

BuildTimeCmd represents the version command

View Source
var CompletionCmd = &cobra.Command{
	Use:   "completion",
	Short: "Generate bash completition files.",
	Long: `Output shell completion code for the specified shell (bash or zsh).
The shell code must be evalutated to provide interactive
completion of kubectl commands.  This can be done by sourcing it from
the .bash_profile.
Note: this requires the bash-completion framework, which is not installed
by default on Mac.  This can be installed by using homebrew:

    $ brew install bash-completion

Once installed, bash_completion must be evaluated.  This can be done by adding the
following line to the .bash_profile

    $ source $(brew --prefix)/etc/bash_completion

Note for zsh users: [1] zsh completions are only supported in versions of zsh >= 5.2

# Install bash completion on a Mac using homebrew
brew install bash-completion
printf "\n# Bash completion support\nsource $(brew --prefix)/etc/bash_completion\n" >> $HOME/.bash_profile
source $HOME/.bash_profile

# Load the rai completion code for bash into the current shell
  source <(rai completion)

# Write bash completion code to a file and source if from .bash_profile
  rai completion bash > ~/.kube/completion.bash.inc
  printf "\n# Rai shell completion\nsource '$HOME/.rai/completion.bash.inc'\n" >> $HOME/.bash_profile
  source $HOME/.bash_profile

# Load the rai completion code for zsh[1] into the current shell
  source <(rai completion)`,
	Run: func(cmd *cobra.Command, args []string) {
		cmd.Root().GenBashCompletion(os.Stdout)
	},
}

CompletionCmd ...

View Source
var EnvCmd = &cobra.Command{
	Use:    "env",
	Short:  "Print the environment variables.",
	Hidden: false,
	Run: func(cmd *cobra.Command, args []string) {
		for _, env := range os.Environ() {
			fmt.Println(env)
		}
	},
}

EnvCmd ...

View Source
var GendocCmd = &cobra.Command{
	Use:   "doc",
	Short: "Generate Markdown documentation for the RAI CLI.",
	Long: `Generate Markdown documentation for the RAI CLI.
This command is, mostly, used to create up-to-date documentation
of RAI's command-line interface.
It creates one Markdown file per command with front matter suitable
for rendering in Hugo.`,
	Hidden: true,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.DisableAutoGenTag = true
		gendocdir = filepath.Clean(gendocdir)
		if !strings.HasSuffix(gendocdir, string(os.PathSeparator)) {
			gendocdir += string(os.PathSeparator)
		}
		if !com.IsDir(gendocdir) {
			jww.FEEDBACK.Println("Directory", gendocdir, "does not exist, creating...")
			os.MkdirAll(gendocdir, os.ModePerm)
		}
		now := time.Now().Format(time.RFC3339)
		prepender := func(filename string) string {
			name := filepath.Base(filename)
			base := strings.TrimSuffix(name, path.Ext(name))
			url := "/commands/" + strings.ToLower(base) + "/"
			return fmt.Sprintf(gendocFrontmatterTemplate, now, strings.Replace(base, "_", " ", -1), base, url)
		}

		linkHandler := func(name string) string {
			base := strings.TrimSuffix(name, path.Ext(name))
			return "/commands/" + strings.ToLower(base) + "/"
		}

		jww.FEEDBACK.Println("Generating RAI command-line documentation in", gendocdir, "...")
		doc.GenMarkdownTreeCustom(cmd.Root(), gendocdir, prepender, linkHandler)
		jww.FEEDBACK.Println("Done.")

		return nil
	},
}

GendocCmd ...

View Source
var LicenseCmd = &cobra.Command{
	Use:   "license",
	Short: "Display the project license.",
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println(_escFSMustString(false, "/LICENSE.TXT"))
	},
}

licenseCmd represents the license command

View Source
var Version = &config.App.Version

Version ...

View Source
var VersionCmd = &cobra.Command{
	Use:     "version",
	Aliases: []string{"buildinfo"},
	Short:   "Print a the version information",
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("BuildDate: ", Version.BuildDate)
		fmt.Println("GitCommit: ", Version.GitCommit)
		if Version.GitBranch != "" {
			fmt.Println("GitBranch: ", Version.GitBranch)
		}
		if Version.GitState != "" {
			fmt.Println("GitState: ", Version.GitState)
		}
		if Version.GitSummary != "" {
			fmt.Println("GitSummary: ", Version.GitSummary)
		}
	},
}

versionCmd represents the version command

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