diff --git a/Makefile b/Makefile index 798de92b7c6e0f0b9896c6e5eeb4bb54e569b5df..34124b3172ba07e5560647086a4620c71e148de4 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,9 @@ BUILD_TARGET = build COMMIT := $(shell git rev-parse --short HEAD) # CHANGE_LOG := $(shell echo -n "$(shell hub release show $(shell hub release --include-drafts -L 1))" | base64) VERSION := dev-$(shell git describe --tags $(shell git rev-list --tags --max-count=1)) -BUILDFLAGS = -ldflags "-X github.com/jenkins-zh/jenkins-cli/app.version=$(VERSION) -X github.com/jenkins-zh/jenkins-cli/app.commit=$(COMMIT)" +BUILDFLAGS = -ldflags "-X github.com/jenkins-zh/jenkins-cli/app.version=$(VERSION) \ + -X github.com/jenkins-zh/jenkins-cli/app.commit=$(COMMIT) \ + -X github.com/jenkins-zh/jenkins-cli/app.date=$(shell date +'%Y-%m-%d')" COVERED_MAIN_SRC_FILE=./main PATH := $(PATH):$(PWD)/bin diff --git a/app/cmd/casc_open.go b/app/cmd/casc_open.go index 4054030be4772f463541700a9f78a604666cd476..8bfb0c8b6b52f3fe3a4282f6a5d631588cc94353 100644 --- a/app/cmd/casc_open.go +++ b/app/cmd/casc_open.go @@ -32,7 +32,7 @@ var cascOpenCmd = &cobra.Command{ Long: i18n.T("Open Configuration as Code page in browser"), PreRun: func(_ *cobra.Command, _ []string) { if cascOpenOption.Browser == "" { - cascOpenOption.Browser = os.Getenv("BROWSER") + cascOpenOption.Browser = os.Getenv("JCLI_BROWSER") } }, RunE: func(_ *cobra.Command, _ []string) (err error) { diff --git a/app/cmd/completion.go b/app/cmd/completion.go index 166009a2ef6696d332f786fab5ba8c35abc099d5..4fa829b1b57ca36b851a7c3e80246694a4ee0f4f 100644 --- a/app/cmd/completion.go +++ b/app/cmd/completion.go @@ -20,27 +20,43 @@ var completionOptions CompletionOptions func init() { rootCmd.AddCommand(completionCmd) - completionCmd.Flags().StringVarP(&completionOptions.Type, "type", "", "bash", + + flags := completionCmd.Flags() + flags.StringVarP(&completionOptions.Type, "type", "", "bash", i18n.T(fmt.Sprintf("Generate different types of shell which are %v", ShellTypes))) + + err := completionCmd.RegisterFlagCompletionFunc("type", func(cmd *cobra.Command, args []string, toComplete string) ( + i []string, directive cobra.ShellCompDirective) { + return ShellTypes, cobra.ShellCompDirectiveDefault + }) + if err != nil { + completionCmd.PrintErrf("register flag type for sub-command doc failed %#v\n", err) + } } var completionCmd = &cobra.Command{ Use: "completion", - Short: i18n.T("Generate bash completion scripts"), - Long: i18n.T("Generate bash completion scripts"), - Example: `# Installing bash completion on macOS using homebrew - ## If running Bash 3.2 included with macOS - brew install bash-completion - ## or, if running Bash 4.1+ - brew install bash-completion@2 - ## you may need add the completion to your completion directory - jcli completion > $(brew --prefix)/etc/bash_completion.d/jcli - ## If you get trouble, please visit https://github.com/jenkins-zh/jenkins-cli/issues/83. - - # Load the jcli completion code for zsh[1] into the current shell - source <(jcli completion --type zsh) - # Set the jcli completion code for zsh[1] to autoload on startup - jcli completion --type zsh > "${fpath[1]}/_jcli"`, + Short: i18n.T("Generate shell completion scripts"), + Long: i18n.T(`Generate shell completion scripts +Normally you don't need to do more extra work to have this feature if you've installed jcli by brew`), + Example: `Installing bash completion on macOS using homebrew +If running Bash 3.2 included with macOS +brew install bash-completion +or, if running Bash 4.1+ +brew install bash-completion@2 +You may need to add the completion to your completion directory by the following command +jcli completion > $(brew --prefix)/etc/bash_completion.d/jcli +If you get trouble, please visit https://github.com/jenkins-zh/jenkins-cli/issues/83. + +In order to have good experience on zsh completion, ohmyzsh is a good choice. +Please install ohmyzsh by the following command +sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" +Get more details about onmyzsh from https://github.com/ohmyzsh/ohmyzsh + +Load the jcli completion code for zsh[1] into the current shell +source <(jcli completion --type zsh) +Set the jcli completion code for zsh[1] to autoload on startup +jcli completion --type zsh > "${fpath[1]}/_jcli"`, RunE: func(cmd *cobra.Command, _ []string) (err error) { shellType := completionOptions.Type switch shellType { diff --git a/app/cmd/open.go b/app/cmd/open.go index 92679c363ca1adceb892644471b68974ba1f9400..59090ff59f0200a6ee2dbf90a1bbaa3fc734a0c7 100644 --- a/app/cmd/open.go +++ b/app/cmd/open.go @@ -42,13 +42,17 @@ func init() { } var openCmd = &cobra.Command{ - Use: "open", - Short: i18n.T("Open your Jenkins with a browser"), - Long: i18n.T(`Open your Jenkins with a browser`), - Example: `jcli open -n [config name]`, + Use: "open", + Short: i18n.T("Open your Jenkins with a browser"), + Long: i18n.T(`Open your Jenkins with a browser`), + Example: `jcli open -n [config name] +Open Jenkins with a specific browser is useful in some use cases. For example, one browser has a proxy setting. +There are two ways to achieve this: +jcli open --browser "Google-Chrome" +JCLI_BROWSER="Google Chrome" jcli open`, PreRun: func(_ *cobra.Command, _ []string) { if openOption.Browser == "" { - openOption.Browser = os.Getenv("BROWSER") + openOption.Browser = os.Getenv("JCLI_BROWSER") } }, RunE: openOption.run, @@ -99,7 +103,6 @@ func (o *OpenOption) run(_ *cobra.Command, args []string) (err error) { // parseName the string expect likes name or name.external func (o *OpenOption) parseName(configName string) (jenkins, external string) { array := strings.SplitN(configName, ".", 2) - fmt.Println(array) if len(array) > 0 { jenkins = array[0] } diff --git a/app/cmd/plugin_open.go b/app/cmd/plugin_open.go index b6522ec329d3829d4e44dc0454108ff156163562..3d417a2838e485ba92569c4c1bf93758e0c3d306 100644 --- a/app/cmd/plugin_open.go +++ b/app/cmd/plugin_open.go @@ -30,7 +30,7 @@ var pluginOpenCmd = &cobra.Command{ Long: `Open update center server in browser`, PreRun: func(_ *cobra.Command, _ []string) { if pluginOpenOption.Browser == "" { - pluginOpenOption.Browser = os.Getenv("BROWSER") + pluginOpenOption.Browser = os.Getenv("JCLI_BROWSER") } }, RunE: func(_ *cobra.Command, _ []string) (err error) {