Skip to content

Commit

Permalink
change flat '--refresh' to '--force/-f'
Browse files Browse the repository at this point in the history
  • Loading branch information
shihyuho committed Dec 8, 2018
1 parent 84eff0f commit c758685
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ $ slctl init -u GITHUB_USERNAME -p GITHUB_PASSWORD
$ slctl init scopes
```

使用 `--refresh` 讓 slctl 發現有重複的 Token 時, 自動的刪除既有的並產生一個全新的 Access Token, 若你想自己維護 Access Token (請務必確保有足夠的權限), 可以使用 `--token` 讓 slctl 驗證後直接儲存起來
使用 `--force` 讓 slctl 發現有重複的 Token 時, 強制刪除既有的並產生一個全新的 Access Token, 若你想自己維護 Access Token (請務必確保有足夠的權限), 可以使用 `--token` 讓 slctl 驗證後直接儲存起來

```sh
$ slctl init --refresh
$ slctl init -f
$ slctl init --token GITHUB_TOKEN
```

Expand Down
10 changes: 5 additions & 5 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ This command grants Github access token and sets up local configuration in $SL_H
$ {{.}} init scopes
使用 '--refresh' 讓 {{.}} 發現有重複的 Token 時, 自動的刪除既有的並產生一個全新的 Access Token
使用 '--force' 讓 {{.}} 發現有重複的 Token 時, 強制刪除既有的並產生一個全新的 Access Token
若你想自己維護 Access Token (請務必確保有足夠的權限), 可以使用 '--token' 讓 {{.}} 驗證後直接儲存起來
$ {{.}} init --refresh
$ {{.}} init -f
$ {{.}} init --token GITHUB_TOKEN
使用 '--offline' 則 {{.}} 不會跟 GitHub API 有任何互動, 只會配置 $SL_HOME 環境目錄.
Expand All @@ -42,7 +42,7 @@ type initCmd struct {
username string
password string
token string
refresh bool
force bool
}

func newInitCmd(out io.Writer) *cobra.Command {
Expand All @@ -59,7 +59,7 @@ func newInitCmd(out io.Writer) *cobra.Command {
}

f := cmd.Flags()
f.BoolVar(&i.refresh, "refresh", false, "automatically re-generate a new one if token already exists")
f.BoolVarP(&i.force, "force", "f", false, "force to re-generate a new one if token already exists")
f.StringVar(&i.token, "token", "", "github access token")
f.StringVarP(&i.username, "username", "u", "", "github username")
f.StringVarP(&i.password, "password", "p", "", "github password")
Expand Down Expand Up @@ -90,7 +90,7 @@ for more details: https://github.com/softleader/slctl/wiki/Home-Path
var username string
if !environment.Settings.Offline {
if c.token == "" {
if c.token, err = token.Grant(c.username, c.password, c.out, c.refresh); err != nil {
if c.token, err = token.Grant(c.username, c.password, c.out, c.force); err != nil {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/plugin_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Plugin 也可以是一個 GitHub repo, 傳入 'github.com/OWNER/REPO', {{.}} 會
$ slctl plugin install github.com/softleader/slctl-whereis --tag 1.0.0 --asset 2
傳入 '--force' 在 install 時自動刪除已存在的 plugin
傳入 '--force' 在 install 時強制刪除已存在的 plugin
$ slctl plugin install github.com/softleader/slctl-whereis -f
`
Expand All @@ -66,7 +66,7 @@ func newPluginInstallCmd(out io.Writer) *cobra.Command {
}
cmd.Flags().StringVar(&pcmd.tag, "tag", "", "specify a tag constraint. If this is not specified, the latest release tag is installed")
cmd.Flags().IntVar(&pcmd.asset, "asset", -1, "specify a asset number, start from zero, to download")
cmd.Flags().BoolVarP(&pcmd.force, "force", "f", false, "if the plugin already exists, force to remove it so that the new one may install.")
cmd.Flags().BoolVarP(&pcmd.force, "force", "f", false, "force to re-install if plugin already exists")
return cmd
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/config/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func contains(base []github.Scope, target github.Scope) bool {
return false
}

func Grant(username, password string, out io.Writer, refresh bool) (token string, err error) {
func Grant(username, password string, out io.Writer, force bool) (token string, err error) {
r := bufio.NewReader(os.Stdin)
if username == "" {
fmt.Fprint(out, "GitHub Username: ")
Expand Down Expand Up @@ -166,7 +166,7 @@ func Grant(username, password string, out io.Writer, refresh bool) (token string

for _, auth := range auths {
if auth.GetNote() == note {
if !refresh {
if !force {
return "", ErrOauthAccessAlreadyExists
}
v.Fprintln(out, "\nRemoving exist token")
Expand Down

0 comments on commit c758685

Please sign in to comment.