Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command alias support #494

Merged
merged 2 commits into from
Dec 6, 2020
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ copy: darwin
sudo cp bin/darwin/$(NAME) /usr/local/bin/jcli

copy-linux: linux
cp bin/linux/$(NAME) /usr/local/bin/jcli
sudo cp bin/linux/$(NAME) /usr/local/bin/jcli

get-golint:
go get -u golang.org/x/lint/golint
Expand Down
16 changes: 16 additions & 0 deletions app/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import (
"fmt"
"github.com/google/go-github/v29/github"
"github.com/jenkins-zh/jenkins-cli/app/cmd/common"
alias "github.com/linuxsuren/go-cli-alias/pkg"
"github.com/linuxsuren/go-cli-alias/pkg/cmd"
goPlugin "github.com/linuxsuren/go-cli-plugin/pkg"
"golang.org/x/net/context"
"golang.org/x/text/encoding/simplifiedchinese"
"io"
"log"
Expand Down Expand Up @@ -218,6 +221,19 @@ func init() {
// add sub-commands
NewShutdownCmd(&rootOptions)
rootCmd.AddCommand(ver.NewVersionCmd(&rootOptions, &rootOptions))

var ctx context.Context
if defMgr, err := alias.GetDefaultAliasMgrWithNameAndInitialData(rootCmd.Name(), []alias.Alias{
{Name: "cl", Command: "config list"},
}); err == nil {
ctx = context.WithValue(context.Background(), alias.AliasKey, defMgr)

rootCmd.AddCommand(cmd.NewRootCommand(ctx))

cmd.RegisterAliasCommands(ctx, rootCmd)
} else {
fmt.Println(fmt.Errorf("cannot get default alias manager, error: %v", err))
}
}

// GetRootOptions returns the root options
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174
github.com/jenkins-zh/jenkins-formulas v0.0.5
github.com/linuxsuren/cobra-extension v0.0.1
github.com/linuxsuren/go-cli-alias v0.0.3
github.com/linuxsuren/go-cli-plugin v0.0.2
github.com/magiconair/properties v1.8.1
github.com/mitchellh/go-homedir v1.1.0
Expand All @@ -26,6 +27,7 @@ require (
github.com/stretchr/testify v1.6.1
github.com/zalando/go-keyring v0.0.0-20200121091418-667557018717
go.uber.org/zap v1.16.0
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0
golang.org/x/text v0.3.4
gopkg.in/yaml.v2 v2.4.0
moul.io/http2curl v1.0.0
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jenkins-zh/jenkins-cli v0.0.32/go.mod h1:uE1mH9PNITrg0sugv6HXuM/CSddg0zxXoYu3w57I3JY=
github.com/jenkins-zh/jenkins-formulas v0.0.5 h1:6d/WoZCSdjTMRry1wHRe2rrf6zQHlfXmaPbp0Bi3I6w=
github.com/jenkins-zh/jenkins-formulas v0.0.5/go.mod h1:zS8fm8u5L6FcjZM0QznXsLV9T2UtSVK+hT6Sm76iUZ4=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
Expand Down Expand Up @@ -189,6 +190,9 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/linuxsuren/cobra-extension v0.0.1 h1:e288zsm1iWUaAOjfiw42hiWJsrrXZnJ0vKApWPyTfkQ=
github.com/linuxsuren/cobra-extension v0.0.1/go.mod h1:UqHi31q7Dj+46nzcVWNZz5Z1JcHBJcmCyPAZRoM8LXo=
github.com/linuxsuren/go-cli-alias v0.0.3 h1:IbqC+4uOTCRM27WCII7Z35pXP4bwqck0J5jg2xmIqr4=
github.com/linuxsuren/go-cli-alias v0.0.3/go.mod h1:l2/nzdvung0zorpCxI1CT+Fuuc/W1sFEWS0jt3/b2ZM=
github.com/linuxsuren/go-cli-plugin v0.0.1/go.mod h1:uyO09KK8otYfDV5LVTfcWX2UbAi3kEz3PrkdfIxnDlg=
github.com/linuxsuren/go-cli-plugin v0.0.2 h1:TASIObCEzmfOblTWt53c8g+r5kuTMcGS9KXFNOLinRU=
github.com/linuxsuren/go-cli-plugin v0.0.2/go.mod h1:ffi2sOHF6qE83rTUaWPjNBy4sPH87IYJYQldxBAdOEk=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
Expand All @@ -198,6 +202,8 @@ github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
Expand Down