未验证 提交 f5a3ff88 编写于 作者: LinuxSuRen's avatar LinuxSuRen 提交者: GitHub

Commnd documentation improments (#392)

上级 1f3587db
......@@ -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
......
......@@ -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) {
......
......@@ -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 {
......
......@@ -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]
}
......
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册