Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"os"

"github.com/spf13/cobra"
)

var completionCmd = &cobra.Command{
Use: "completion [shell]",
Args: cobra.OnlyValidArgs,
ValidArgs: []string{"bash", "zsh"},
Short: "Generate shell completions",
Long: `To load completion run

. <(jk completion)

To configure your bash shell to load completions for each session add to your bashrc

# ~/.bashrc or ~/.profile
. <(jk completion)

If you want to use zsh instead, do the following:

$ jk completion zsh > _jk
Then move _jk into $fpath and run compinit.
`,
Run: func(cmd *cobra.Command, args []string) {
shell := "bash"
if len(args) > 0 {
shell = args[0]
}

switch shell {
case "zsh":
jk.GenZshCompletion(os.Stdout)
default:
jk.GenBashCompletion(os.Stdout)
}
},
}

func init() {
jk.AddCommand(completionCmd)
}
5 changes: 4 additions & 1 deletion run.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ func init() {
runCmd.PersistentFlags().BoolVarP(&runOptions.verbose, "verbose", "v", false, "verbose output")
runCmd.PersistentFlags().StringVarP(&runOptions.outputDirectory, "output-directory", "o", "", "where to output generated files")
runCmd.PersistentFlags().StringVarP(&runOptions.inputDirectory, "input-directory", "i", "", "where to find files read in the script; if not set, the directory containing the script is used")
runCmd.PersistentFlags().VarP(parameters(paramSourceFile), "parameters", "f", "load parameters from a JSON or YAML file")
runCmd.PersistentFlags().VarP(parameters(paramSourceCommandLine), "parameter", "p", "boolean input parameter")
parameterFlag := runCmd.PersistentFlags().VarPF(parameters(paramSourceFile), "parameters", "f", "load parameters from a JSON or YAML file")
parameterFlag.Annotations = map[string][]string{
cobra.BashCompFilenameExt: {"json", "yaml", "yml"},
}
jk.AddCommand(runCmd)
}

Expand Down