From a6ce534403986df61a7865324c897bcb7a6c6551 Mon Sep 17 00:00:00 2001 From: Amine Date: Mon, 16 Sep 2019 22:16:33 +0200 Subject: bridge/core: Implement token functionalities --- bridge/core/token.go | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 bridge/core/token.go diff --git a/bridge/core/token.go b/bridge/core/token.go new file mode 100644 index 00000000..6cf2fbd5 --- /dev/null +++ b/bridge/core/token.go @@ -0,0 +1,211 @@ +package core + +import ( + "fmt" + "regexp" + "strconv" + "strings" + + "github.com/MichaelMure/git-bug/cache" +) + +const ( + tokenConfigKeyPrefix = "git-bug.token" + tokenKeyValue = "value" + tokenKeyTarget = "target" + tokenKeyGlobal = "global" + tokenKeyScopes = "scopes" +) + +type Token struct { + Name string + Value string + Target string + Global bool + Scopes []string +} + +func NewToken(name, value, target string, global bool, scopes []string) *Token { + return &Token{ + Name: name, + Value: value, + Target: target, + Global: global, + Scopes: scopes, + } +} + +func (t *Token) Valnameate() error { + if t.Name == "" { + return fmt.Errorf("missing token name") + } + if t.Value == "" { + return fmt.Errorf("missing token value") + } + if t.Target == "" { + return fmt.Errorf("missing token target") + } + return nil +} + +func loadToken(repo *cache.RepoCache, name string, global bool) (*Token, error) { + keyPrefix := fmt.Sprintf("git-bug.token.%s", name) + var pairs map[string]string + var err error + if global { + pairs, err = repo.ReadGlobalConfigs(keyPrefix) + if err != nil { + return nil, err + } + + } else { + pairs, err = repo.ReadConfigs(keyPrefix) + if err != nil { + return nil, err + } + } + + result := make(Configuration, len(pairs)) + for key, value := range pairs { + key := strings.TrimPrefix(key, keyPrefix) + result[key] = value + } + + var ok bool + token := &Token{Name: name} + token.Value, ok = result[tokenKeyValue] + if !ok { + return nil, fmt.Errorf("nil value") + } + + token.Target, ok = result[tokenKeyTarget] + if !ok { + return nil, fmt.Errorf("nil value") + } + + if g, ok := result[tokenKeyGlobal]; !ok { + return nil, fmt.Errorf("nil value") + } else if g == "true" { + token.Global = true + } + + scopesString, ok := result[tokenKeyScopes] + if !ok { + return nil, fmt.Errorf("missing scopes config") + } + + token.Scopes = strings.Split(scopesString, ",") + return token, nil +} + +func GetToken(repo *cache.RepoCache, name string) (*Token, error) { + return loadToken(repo, name, false) +} + +func GetGlobalToken(repo *cache.RepoCache, name string) (*Token, error) { + return loadToken(repo, name, true) +} + +func listTokens(repo *cache.RepoCache, global bool) ([]string, error) { + var configs map[string]string + var err error + if global { + configs, err = repo.ReadConfigs(tokenConfigKeyPrefix + ".") + if err != nil { + return nil, err + } + } else { + configs, err = repo.ReadGlobalConfigs(tokenConfigKeyPrefix + ".") + if err != nil { + return nil, err + } + } + + re, err := regexp.Compile(tokenConfigKeyPrefix + `.([^.]+)`) + if err != nil { + panic(err) + } + + set := make(map[string]interface{}) + + for key := range configs { + res := re.FindStringSubmatch(key) + + if res == nil { + continue + } + + set[res[1]] = nil + } + + result := make([]string, len(set)) + i := 0 + for key := range set { + result[i] = key + i++ + } + + return result, nil +} + +func ListTokens(repo *cache.RepoCache) ([]string, error) { + return listTokens(repo, false) +} + +func ListGlobalTokens(repo *cache.RepoCache) ([]string, error) { + return listTokens(repo, true) +} + +func storeToken(repo *cache.RepoCache, token *Token) error { + var store func(key, value string) error + if token.Global { + store = repo.StoreGlobalConfig + } else { + store = repo.StoreConfig + } + + var err error + storeValueKey := fmt.Sprintf("git-bug.token.%s.%s", token.Name, tokenKeyValue) + err = store(storeValueKey, token.Value) + if err != nil { + return err + } + + storeTargetKey := fmt.Sprintf("git-bug.token.%s.%s", token.Name, tokenKeyTarget) + err = store(storeTargetKey, token.Target) + if err != nil { + return err + } + + storeGlobalKey := fmt.Sprintf("git-bug.token.%s.%s", token.Name, tokenKeyGlobal) + err = store(storeGlobalKey, strconv.FormatBool(token.Global)) + if err != nil { + return err + } + + storeScopesKey := fmt.Sprintf("git-bug.token.%s.%s", token.Name, tokenKeyScopes) + err = store(storeScopesKey, strings.Join(token.Scopes, ",")) + if err != nil { + return err + } + + return nil +} + +func StoreToken(repo *cache.RepoCache, name, value, target string, global bool, scopes []string) error { + return storeToken(repo, NewToken(name, value, target, global, scopes)) +} + +func StoreGlobalToken(repo *cache.RepoCache, name, value, target string, global bool, scopes []string) error { + return storeToken(repo, NewToken(name, value, target, global, scopes)) +} + +func RemoveToken(repo *cache.RepoCache, name string) error { + keyPrefix := fmt.Sprintf("git-bug.token.%s", name) + return repo.RmConfigs(keyPrefix) +} + +func RemoveGlobalToken(repo *cache.RepoCache, name string) error { + keyPrefix := fmt.Sprintf("git-bug.token.%s", name) + return repo.RmGlobalConfigs(keyPrefix) +} -- cgit From 56551b6a2232e52e03765e90d4504391e30a824a Mon Sep 17 00:00:00 2001 From: Amine Date: Tue, 17 Sep 2019 13:59:40 +0200 Subject: bridge/core: comment token functionalities --- bridge/core/token.go | 50 ++++++++++++++++++++++++++++++++------------------ repository/repo.go | 6 ++++-- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/bridge/core/token.go b/bridge/core/token.go index 6cf2fbd5..9e393642 100644 --- a/bridge/core/token.go +++ b/bridge/core/token.go @@ -6,7 +6,7 @@ import ( "strconv" "strings" - "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/repository" ) const ( @@ -17,6 +17,7 @@ const ( tokenKeyScopes = "scopes" ) +// Token represent token related informations type Token struct { Name string Value string @@ -25,6 +26,7 @@ type Token struct { Scopes []string } +// NewToken instantiate a new token func NewToken(name, value, target string, global bool, scopes []string) *Token { return &Token{ Name: name, @@ -35,7 +37,8 @@ func NewToken(name, value, target string, global bool, scopes []string) *Token { } } -func (t *Token) Valnameate() error { +// Validate ensure token important fields are valid +func (t *Token) Validate() error { if t.Name == "" { return fmt.Errorf("missing token name") } @@ -48,10 +51,12 @@ func (t *Token) Valnameate() error { return nil } -func loadToken(repo *cache.RepoCache, name string, global bool) (*Token, error) { +func loadToken(repo repository.RepoConfig, name string, global bool) (*Token, error) { keyPrefix := fmt.Sprintf("git-bug.token.%s", name) var pairs map[string]string var err error + + // read token config pairs if global { pairs, err = repo.ReadGlobalConfigs(keyPrefix) if err != nil { @@ -65,6 +70,7 @@ func loadToken(repo *cache.RepoCache, name string, global bool) (*Token, error) } } + // trim key prefix result := make(Configuration, len(pairs)) for key, value := range pairs { key := strings.TrimPrefix(key, keyPrefix) @@ -75,16 +81,16 @@ func loadToken(repo *cache.RepoCache, name string, global bool) (*Token, error) token := &Token{Name: name} token.Value, ok = result[tokenKeyValue] if !ok { - return nil, fmt.Errorf("nil value") + return nil, fmt.Errorf("empty token value") } token.Target, ok = result[tokenKeyTarget] if !ok { - return nil, fmt.Errorf("nil value") + return nil, fmt.Errorf("empty token key") } if g, ok := result[tokenKeyGlobal]; !ok { - return nil, fmt.Errorf("nil value") + return nil, fmt.Errorf("empty token global") } else if g == "true" { token.Global = true } @@ -98,15 +104,17 @@ func loadToken(repo *cache.RepoCache, name string, global bool) (*Token, error) return token, nil } -func GetToken(repo *cache.RepoCache, name string) (*Token, error) { +// GetToken loads a token from repo config +func GetToken(repo repository.RepoConfig, name string) (*Token, error) { return loadToken(repo, name, false) } -func GetGlobalToken(repo *cache.RepoCache, name string) (*Token, error) { +// GetGlobalToken loads a token from the global config +func GetGlobalToken(repo repository.RepoConfig, name string) (*Token, error) { return loadToken(repo, name, true) } -func listTokens(repo *cache.RepoCache, global bool) ([]string, error) { +func listTokens(repo repository.RepoConfig, global bool) ([]string, error) { var configs map[string]string var err error if global { @@ -148,15 +156,17 @@ func listTokens(repo *cache.RepoCache, global bool) ([]string, error) { return result, nil } -func ListTokens(repo *cache.RepoCache) ([]string, error) { +// ListTokens return the list of stored tokens in the repo config +func ListTokens(repo repository.RepoConfig) ([]string, error) { return listTokens(repo, false) } -func ListGlobalTokens(repo *cache.RepoCache) ([]string, error) { +// ListGlobalTokens return the list of stored tokens in the global config +func ListGlobalTokens(repo repository.RepoConfig) ([]string, error) { return listTokens(repo, true) } -func storeToken(repo *cache.RepoCache, token *Token) error { +func storeToken(repo repository.RepoConfig, token *Token) error { var store func(key, value string) error if token.Global { store = repo.StoreGlobalConfig @@ -192,20 +202,24 @@ func storeToken(repo *cache.RepoCache, token *Token) error { return nil } -func StoreToken(repo *cache.RepoCache, name, value, target string, global bool, scopes []string) error { - return storeToken(repo, NewToken(name, value, target, global, scopes)) +// StoreToken stores a token in the repo config +func StoreToken(repo repository.RepoConfig, name, value, target string, scopes []string) error { + return storeToken(repo, NewToken(name, value, target, false, scopes)) } -func StoreGlobalToken(repo *cache.RepoCache, name, value, target string, global bool, scopes []string) error { - return storeToken(repo, NewToken(name, value, target, global, scopes)) +// StoreGlobalToken stores a token in global config +func StoreGlobalToken(repo repository.RepoConfig, name, value, target string, scopes []string) error { + return storeToken(repo, NewToken(name, value, target, true, scopes)) } -func RemoveToken(repo *cache.RepoCache, name string) error { +// RemoveToken removes a token from the repo config +func RemoveToken(repo repository.RepoConfig, name string) error { keyPrefix := fmt.Sprintf("git-bug.token.%s", name) return repo.RmConfigs(keyPrefix) } -func RemoveGlobalToken(repo *cache.RepoCache, name string) error { +// RemoveGlobalToken removes a token from the repo config +func RemoveGlobalToken(repo repository.RepoConfig, name string) error { keyPrefix := fmt.Sprintf("git-bug.token.%s", name) return repo.RmGlobalConfigs(keyPrefix) } diff --git a/repository/repo.go b/repository/repo.go index 7d655bde..e8c67a5e 100644 --- a/repository/repo.go +++ b/repository/repo.go @@ -10,8 +10,10 @@ import ( "github.com/MichaelMure/git-bug/util/lamport" ) -var ErrNoConfigEntry = errors.New("no config entry for the given key") -var ErrMultipleConfigEntry = errors.New("multiple config entry for the given key") +var ( + ErrNoConfigEntry = errors.New("no config entry for the given key") + ErrMultipleConfigEntry = errors.New("multiple config entry for the given key") +) // RepoCommon represent the common function the we want all the repo to implement type RepoCommon interface { -- cgit From 9370e1292b99bc443fe9128d670f36a94f996ca9 Mon Sep 17 00:00:00 2001 From: Amine Date: Tue, 17 Sep 2019 14:11:16 +0200 Subject: commands: add bridge token subcommand --- commands/bridge_token.go | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 commands/bridge_token.go diff --git a/commands/bridge_token.go b/commands/bridge_token.go new file mode 100644 index 00000000..6cb6c4b7 --- /dev/null +++ b/commands/bridge_token.go @@ -0,0 +1,64 @@ +package commands + +import ( + "fmt" + + "github.com/spf13/cobra" + + "github.com/MichaelMure/git-bug/bridge/core" + "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/util/interrupt" +) + +var ( + bridgeTokenAll bool + bridgeTokenLocalOnly bool + bridgeTokenGlobalOnly bool +) + +func runTokenBridge(cmd *cobra.Command, args []string) error { + backend, err := cache.NewRepoCache(repo) + if err != nil { + return err + } + defer backend.Close() + interrupt.RegisterCleaner(backend.Close) + + var tokens []string + if bridgeTokenLocalOnly || bridgeTokenAll { + localTokens, err := core.ListTokens(backend) + if err != nil { + return err + } + tokens = localTokens + } + + if bridgeTokenGlobalOnly || bridgeTokenAll { + globalTokens, err := core.ListGlobalTokens(backend) + if err != nil { + return err + } + tokens = append(tokens, globalTokens...) + } + + for _, c := range tokens { + fmt.Println(c) + } + return nil +} + +var bridgeTokenCmd = &cobra.Command{ + Use: "token", + Short: "Configure and use bridge tokens.", + PreRunE: loadRepo, + RunE: runTokenBridge, + Args: cobra.NoArgs, +} + +func init() { + bridgeCmd.AddCommand(bridgeTokenCmd) + bridgeTokenCmd.Flags().BoolVarP(&bridgeTokenAll, "all", "a", false, "") + bridgeTokenCmd.Flags().BoolVarP(&bridgeTokenLocalOnly, "local", "l", true, "") + bridgeTokenCmd.Flags().BoolVarP(&bridgeTokenGlobalOnly, "global", "g", false, "") + bridgeTokenCmd.Flags().SortFlags = false +} -- cgit From 967e168333a7c3057cf77f9c3f890ea1bbf7a1df Mon Sep 17 00:00:00 2001 From: Amine Date: Wed, 18 Sep 2019 21:00:07 +0200 Subject: bridge/core: use token id instead of name commands: add bridge token rm/add commands: improve bridge token printing --- bridge/core/token.go | 65 +++++++++++++++++--------------------------- commands/bridge_token.go | 45 +++++++++++++++++++++++------- commands/bridge_token_add.go | 44 ++++++++++++++++++++++++++++++ commands/bridge_token_rm.go | 29 ++++++++++++++++++++ 4 files changed, 133 insertions(+), 50 deletions(-) create mode 100644 commands/bridge_token_add.go create mode 100644 commands/bridge_token_rm.go diff --git a/bridge/core/token.go b/bridge/core/token.go index 9e393642..5e629c51 100644 --- a/bridge/core/token.go +++ b/bridge/core/token.go @@ -3,7 +3,6 @@ package core import ( "fmt" "regexp" - "strconv" "strings" "github.com/MichaelMure/git-bug/repository" @@ -13,13 +12,12 @@ const ( tokenConfigKeyPrefix = "git-bug.token" tokenKeyValue = "value" tokenKeyTarget = "target" - tokenKeyGlobal = "global" tokenKeyScopes = "scopes" ) // Token represent token related informations type Token struct { - Name string + Id string Value string Target string Global bool @@ -27,9 +25,9 @@ type Token struct { } // NewToken instantiate a new token -func NewToken(name, value, target string, global bool, scopes []string) *Token { +func NewToken(id, value, target string, global bool, scopes []string) *Token { return &Token{ - Name: name, + Id: id, Value: value, Target: target, Global: global, @@ -39,8 +37,8 @@ func NewToken(name, value, target string, global bool, scopes []string) *Token { // Validate ensure token important fields are valid func (t *Token) Validate() error { - if t.Name == "" { - return fmt.Errorf("missing token name") + if t.Id == "" { + return fmt.Errorf("missing token id") } if t.Value == "" { return fmt.Errorf("missing token value") @@ -51,8 +49,8 @@ func (t *Token) Validate() error { return nil } -func loadToken(repo repository.RepoConfig, name string, global bool) (*Token, error) { - keyPrefix := fmt.Sprintf("git-bug.token.%s", name) +func loadToken(repo repository.RepoConfig, id string, global bool) (*Token, error) { + keyPrefix := fmt.Sprintf("git-bug.token.%s.", id) var pairs map[string]string var err error @@ -62,7 +60,6 @@ func loadToken(repo repository.RepoConfig, name string, global bool) (*Token, er if err != nil { return nil, err } - } else { pairs, err = repo.ReadConfigs(keyPrefix) if err != nil { @@ -78,7 +75,7 @@ func loadToken(repo repository.RepoConfig, name string, global bool) (*Token, er } var ok bool - token := &Token{Name: name} + token := &Token{Id: id, Global: global} token.Value, ok = result[tokenKeyValue] if !ok { return nil, fmt.Errorf("empty token value") @@ -89,12 +86,6 @@ func loadToken(repo repository.RepoConfig, name string, global bool) (*Token, er return nil, fmt.Errorf("empty token key") } - if g, ok := result[tokenKeyGlobal]; !ok { - return nil, fmt.Errorf("empty token global") - } else if g == "true" { - token.Global = true - } - scopesString, ok := result[tokenKeyScopes] if !ok { return nil, fmt.Errorf("missing scopes config") @@ -105,25 +96,25 @@ func loadToken(repo repository.RepoConfig, name string, global bool) (*Token, er } // GetToken loads a token from repo config -func GetToken(repo repository.RepoConfig, name string) (*Token, error) { - return loadToken(repo, name, false) +func GetToken(repo repository.RepoConfig, id string) (*Token, error) { + return loadToken(repo, id, false) } // GetGlobalToken loads a token from the global config -func GetGlobalToken(repo repository.RepoConfig, name string) (*Token, error) { - return loadToken(repo, name, true) +func GetGlobalToken(repo repository.RepoConfig, id string) (*Token, error) { + return loadToken(repo, id, true) } func listTokens(repo repository.RepoConfig, global bool) ([]string, error) { var configs map[string]string var err error if global { - configs, err = repo.ReadConfigs(tokenConfigKeyPrefix + ".") + configs, err = repo.ReadGlobalConfigs(tokenConfigKeyPrefix + ".") if err != nil { return nil, err } } else { - configs, err = repo.ReadGlobalConfigs(tokenConfigKeyPrefix + ".") + configs, err = repo.ReadConfigs(tokenConfigKeyPrefix + ".") if err != nil { return nil, err } @@ -175,25 +166,19 @@ func storeToken(repo repository.RepoConfig, token *Token) error { } var err error - storeValueKey := fmt.Sprintf("git-bug.token.%s.%s", token.Name, tokenKeyValue) + storeValueKey := fmt.Sprintf("git-bug.token.%s.%s", token.Id, tokenKeyValue) err = store(storeValueKey, token.Value) if err != nil { return err } - storeTargetKey := fmt.Sprintf("git-bug.token.%s.%s", token.Name, tokenKeyTarget) + storeTargetKey := fmt.Sprintf("git-bug.token.%s.%s", token.Id, tokenKeyTarget) err = store(storeTargetKey, token.Target) if err != nil { return err } - storeGlobalKey := fmt.Sprintf("git-bug.token.%s.%s", token.Name, tokenKeyGlobal) - err = store(storeGlobalKey, strconv.FormatBool(token.Global)) - if err != nil { - return err - } - - storeScopesKey := fmt.Sprintf("git-bug.token.%s.%s", token.Name, tokenKeyScopes) + storeScopesKey := fmt.Sprintf("git-bug.token.%s.%s", token.Id, tokenKeyScopes) err = store(storeScopesKey, strings.Join(token.Scopes, ",")) if err != nil { return err @@ -203,23 +188,23 @@ func storeToken(repo repository.RepoConfig, token *Token) error { } // StoreToken stores a token in the repo config -func StoreToken(repo repository.RepoConfig, name, value, target string, scopes []string) error { - return storeToken(repo, NewToken(name, value, target, false, scopes)) +func StoreToken(repo repository.RepoConfig, token *Token) error { + return storeToken(repo, token) } // StoreGlobalToken stores a token in global config -func StoreGlobalToken(repo repository.RepoConfig, name, value, target string, scopes []string) error { - return storeToken(repo, NewToken(name, value, target, true, scopes)) +func StoreGlobalToken(repo repository.RepoConfig, token *Token) error { + return storeToken(repo, token) } // RemoveToken removes a token from the repo config -func RemoveToken(repo repository.RepoConfig, name string) error { - keyPrefix := fmt.Sprintf("git-bug.token.%s", name) +func RemoveToken(repo repository.RepoConfig, id string) error { + keyPrefix := fmt.Sprintf("git-bug.token.%s", id) return repo.RmConfigs(keyPrefix) } // RemoveGlobalToken removes a token from the repo config -func RemoveGlobalToken(repo repository.RepoConfig, name string) error { - keyPrefix := fmt.Sprintf("git-bug.token.%s", name) +func RemoveGlobalToken(repo repository.RepoConfig, id string) error { + keyPrefix := fmt.Sprintf("git-bug.token.%s", id) return repo.RmGlobalConfigs(keyPrefix) } diff --git a/commands/bridge_token.go b/commands/bridge_token.go index 6cb6c4b7..52dea9a9 100644 --- a/commands/bridge_token.go +++ b/commands/bridge_token.go @@ -2,16 +2,18 @@ package commands import ( "fmt" + "strings" "github.com/spf13/cobra" "github.com/MichaelMure/git-bug/bridge/core" "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/util/colors" "github.com/MichaelMure/git-bug/util/interrupt" + "github.com/MichaelMure/git-bug/util/text" ) var ( - bridgeTokenAll bool bridgeTokenLocalOnly bool bridgeTokenGlobalOnly bool ) @@ -24,25 +26,49 @@ func runTokenBridge(cmd *cobra.Command, args []string) error { defer backend.Close() interrupt.RegisterCleaner(backend.Close) - var tokens []string - if bridgeTokenLocalOnly || bridgeTokenAll { + var tokens []*core.Token + if !bridgeTokenGlobalOnly { localTokens, err := core.ListTokens(backend) if err != nil { return err } - tokens = localTokens + + for _, id := range localTokens { + token, err := core.GetToken(repo, id) + if err != nil { + return err + } + tokens = append(tokens, token) + } } - if bridgeTokenGlobalOnly || bridgeTokenAll { + if !bridgeTokenLocalOnly { globalTokens, err := core.ListGlobalTokens(backend) if err != nil { return err } - tokens = append(tokens, globalTokens...) + + for _, id := range globalTokens { + token, err := core.GetGlobalToken(repo, id) + if err != nil { + return err + } + tokens = append(tokens, token) + } } - for _, c := range tokens { - fmt.Println(c) + for _, token := range tokens { + valueFmt := text.LeftPadMaxLine(token.Value, 20, 0) + targetFmt := text.LeftPadMaxLine(token.Target, 10, 0) + scopesFmt := text.LeftPadMaxLine(strings.Join(token.Scopes, ","), 20, 0) + + fmt.Printf("%s %s %s %s %s\n", + colors.Cyan(token.Id), + colors.Magenta(targetFmt), + colors.Yellow(token.Global), + valueFmt, + scopesFmt, + ) } return nil } @@ -57,8 +83,7 @@ var bridgeTokenCmd = &cobra.Command{ func init() { bridgeCmd.AddCommand(bridgeTokenCmd) - bridgeTokenCmd.Flags().BoolVarP(&bridgeTokenAll, "all", "a", false, "") - bridgeTokenCmd.Flags().BoolVarP(&bridgeTokenLocalOnly, "local", "l", true, "") + bridgeTokenCmd.Flags().BoolVarP(&bridgeTokenLocalOnly, "local", "l", false, "") bridgeTokenCmd.Flags().BoolVarP(&bridgeTokenGlobalOnly, "global", "g", false, "") bridgeTokenCmd.Flags().SortFlags = false } diff --git a/commands/bridge_token_add.go b/commands/bridge_token_add.go new file mode 100644 index 00000000..8b3fc5ce --- /dev/null +++ b/commands/bridge_token_add.go @@ -0,0 +1,44 @@ +package commands + +import ( + "github.com/spf13/cobra" + + "github.com/MichaelMure/git-bug/bridge/core" +) + +var ( + bridgeToken core.Token +) + +func runBridgeTokenAdd(cmd *cobra.Command, args []string) error { + if bridgeToken.Global { + return core.StoreToken( + repo, + &bridgeToken, + ) + } + + return core.StoreGlobalToken( + repo, + &bridgeToken, + ) +} + +var bridgeTokenAddCmd = &cobra.Command{ + Use: "add", + Short: "Configure and use bridge tokens.", + PreRunE: loadRepo, + RunE: runBridgeTokenAdd, + Args: cobra.NoArgs, +} + +func init() { + bridgeTokenCmd.AddCommand(bridgeTokenAddCmd) + bridgeTokenAddCmd.Flags().StringVarP(&bridgeToken.Id, "id", "i", "", "") + bridgeTokenAddCmd.Flags().BoolVarP(&bridgeToken.Global, "global", "g", false, "") + bridgeTokenAddCmd.Flags().StringVarP(&bridgeToken.Value, "value", "v", "", "") + bridgeTokenAddCmd.Flags().StringVarP(&bridgeToken.Target, "target", "t", "", "") + bridgeTokenAddCmd.Flags().StringArrayVarP(&bridgeToken.Scopes, "scopes", "s", []string{}, "") + bridgeTokenAddCmd.Flags().SortFlags = false + +} diff --git a/commands/bridge_token_rm.go b/commands/bridge_token_rm.go new file mode 100644 index 00000000..7fd79126 --- /dev/null +++ b/commands/bridge_token_rm.go @@ -0,0 +1,29 @@ +package commands + +import ( + "github.com/spf13/cobra" + + "github.com/MichaelMure/git-bug/bridge/core" +) + +func runBridgeTokenRm(cmd *cobra.Command, args []string) error { + err := core.RemoveToken(repo, args[0]) + if err == nil { + return nil + } + + err = core.RemoveGlobalToken(repo, args[0]) + return err +} + +var bridgeTokenRmCmd = &cobra.Command{ + Use: "rm", + Short: "Configure and use bridge tokens.", + PreRunE: loadRepo, + RunE: runBridgeTokenRm, + Args: cobra.ExactArgs(1), +} + +func init() { + bridgeTokenCmd.AddCommand(bridgeTokenRmCmd) +} -- cgit From 3433fa5def3fb3c2707bae1aeb4ae1bd62c930de Mon Sep 17 00:00:00 2001 From: Amine Date: Sun, 22 Sep 2019 11:48:48 +0200 Subject: commands: use token value as identifier --- bridge/core/token.go | 45 ++++++++++++++------------------------------ commands/bridge_token.go | 7 +++---- commands/bridge_token_add.go | 2 -- repository/git.go | 12 ++++++++---- 4 files changed, 25 insertions(+), 41 deletions(-) diff --git a/bridge/core/token.go b/bridge/core/token.go index 5e629c51..0147f747 100644 --- a/bridge/core/token.go +++ b/bridge/core/token.go @@ -10,14 +10,12 @@ import ( const ( tokenConfigKeyPrefix = "git-bug.token" - tokenKeyValue = "value" tokenKeyTarget = "target" tokenKeyScopes = "scopes" ) // Token represent token related informations type Token struct { - Id string Value string Target string Global bool @@ -25,9 +23,8 @@ type Token struct { } // NewToken instantiate a new token -func NewToken(id, value, target string, global bool, scopes []string) *Token { +func NewToken(value, target string, global bool, scopes []string) *Token { return &Token{ - Id: id, Value: value, Target: target, Global: global, @@ -37,9 +34,6 @@ func NewToken(id, value, target string, global bool, scopes []string) *Token { // Validate ensure token important fields are valid func (t *Token) Validate() error { - if t.Id == "" { - return fmt.Errorf("missing token id") - } if t.Value == "" { return fmt.Errorf("missing token value") } @@ -49,8 +43,8 @@ func (t *Token) Validate() error { return nil } -func loadToken(repo repository.RepoConfig, id string, global bool) (*Token, error) { - keyPrefix := fmt.Sprintf("git-bug.token.%s.", id) +func loadToken(repo repository.RepoConfig, value string, global bool) (*Token, error) { + keyPrefix := fmt.Sprintf("git-bug.token.%s.", value) var pairs map[string]string var err error @@ -75,12 +69,7 @@ func loadToken(repo repository.RepoConfig, id string, global bool) (*Token, erro } var ok bool - token := &Token{Id: id, Global: global} - token.Value, ok = result[tokenKeyValue] - if !ok { - return nil, fmt.Errorf("empty token value") - } - + token := &Token{Value: value, Global: global} token.Target, ok = result[tokenKeyTarget] if !ok { return nil, fmt.Errorf("empty token key") @@ -96,13 +85,13 @@ func loadToken(repo repository.RepoConfig, id string, global bool) (*Token, erro } // GetToken loads a token from repo config -func GetToken(repo repository.RepoConfig, id string) (*Token, error) { - return loadToken(repo, id, false) +func GetToken(repo repository.RepoConfig, value string) (*Token, error) { + return loadToken(repo, value, false) } // GetGlobalToken loads a token from the global config -func GetGlobalToken(repo repository.RepoConfig, id string) (*Token, error) { - return loadToken(repo, id, true) +func GetGlobalToken(repo repository.RepoConfig, value string) (*Token, error) { + return loadToken(repo, value, true) } func listTokens(repo repository.RepoConfig, global bool) ([]string, error) { @@ -166,19 +155,13 @@ func storeToken(repo repository.RepoConfig, token *Token) error { } var err error - storeValueKey := fmt.Sprintf("git-bug.token.%s.%s", token.Id, tokenKeyValue) - err = store(storeValueKey, token.Value) - if err != nil { - return err - } - - storeTargetKey := fmt.Sprintf("git-bug.token.%s.%s", token.Id, tokenKeyTarget) + storeTargetKey := fmt.Sprintf("git-bug.token.%s.%s", token.Value, tokenKeyTarget) err = store(storeTargetKey, token.Target) if err != nil { return err } - storeScopesKey := fmt.Sprintf("git-bug.token.%s.%s", token.Id, tokenKeyScopes) + storeScopesKey := fmt.Sprintf("git-bug.token.%s.%s", token.Value, tokenKeyScopes) err = store(storeScopesKey, strings.Join(token.Scopes, ",")) if err != nil { return err @@ -198,13 +181,13 @@ func StoreGlobalToken(repo repository.RepoConfig, token *Token) error { } // RemoveToken removes a token from the repo config -func RemoveToken(repo repository.RepoConfig, id string) error { - keyPrefix := fmt.Sprintf("git-bug.token.%s", id) +func RemoveToken(repo repository.RepoConfig, value string) error { + keyPrefix := fmt.Sprintf("git-bug.token.%s", value) return repo.RmConfigs(keyPrefix) } // RemoveGlobalToken removes a token from the repo config -func RemoveGlobalToken(repo repository.RepoConfig, id string) error { - keyPrefix := fmt.Sprintf("git-bug.token.%s", id) +func RemoveGlobalToken(repo repository.RepoConfig, value string) error { + keyPrefix := fmt.Sprintf("git-bug.token.%s", value) return repo.RmGlobalConfigs(keyPrefix) } diff --git a/commands/bridge_token.go b/commands/bridge_token.go index 52dea9a9..cb9754c3 100644 --- a/commands/bridge_token.go +++ b/commands/bridge_token.go @@ -59,14 +59,13 @@ func runTokenBridge(cmd *cobra.Command, args []string) error { for _, token := range tokens { valueFmt := text.LeftPadMaxLine(token.Value, 20, 0) - targetFmt := text.LeftPadMaxLine(token.Target, 10, 0) + targetFmt := text.LeftPadMaxLine(token.Target, 8, 0) scopesFmt := text.LeftPadMaxLine(strings.Join(token.Scopes, ","), 20, 0) - fmt.Printf("%s %s %s %s %s\n", - colors.Cyan(token.Id), + fmt.Printf("%s %s %s %s\n", + valueFmt, colors.Magenta(targetFmt), colors.Yellow(token.Global), - valueFmt, scopesFmt, ) } diff --git a/commands/bridge_token_add.go b/commands/bridge_token_add.go index 8b3fc5ce..1e62a383 100644 --- a/commands/bridge_token_add.go +++ b/commands/bridge_token_add.go @@ -34,11 +34,9 @@ var bridgeTokenAddCmd = &cobra.Command{ func init() { bridgeTokenCmd.AddCommand(bridgeTokenAddCmd) - bridgeTokenAddCmd.Flags().StringVarP(&bridgeToken.Id, "id", "i", "", "") bridgeTokenAddCmd.Flags().BoolVarP(&bridgeToken.Global, "global", "g", false, "") bridgeTokenAddCmd.Flags().StringVarP(&bridgeToken.Value, "value", "v", "", "") bridgeTokenAddCmd.Flags().StringVarP(&bridgeToken.Target, "target", "t", "", "") bridgeTokenAddCmd.Flags().StringArrayVarP(&bridgeToken.Scopes, "scopes", "s", []string{}, "") bridgeTokenAddCmd.Flags().SortFlags = false - } diff --git a/repository/git.go b/repository/git.go index 2b00d1f2..2c72fccd 100644 --- a/repository/git.go +++ b/repository/git.go @@ -15,11 +15,15 @@ import ( "github.com/MichaelMure/git-bug/util/lamport" ) -const createClockFile = "/git-bug/create-clock" -const editClockFile = "/git-bug/edit-clock" +const ( + createClockFile = "/git-bug/create-clock" + editClockFile = "/git-bug/edit-clock" +) -// ErrNotARepo is the error returned when the git repo root wan't be found -var ErrNotARepo = errors.New("not a git repository") +var ( + // ErrNotARepo is the error returned when the git repo root wan't be found + ErrNotARepo = errors.New("not a git repository") +) var _ ClockedRepo = &GitRepo{} -- cgit From 3984919a3df95b8ec203bcb82b66c9c2270579c7 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 12 Oct 2019 18:10:44 +0900 Subject: bridge: various cleanups --- bridge/bridges.go | 12 ++++-- bridge/core/token.go | 75 ++++++++++++++-------------------- bridge/github/github.go | 4 -- bridge/gitlab/gitlab.go | 4 -- bridge/launchpad/launchpad.go | 4 -- commands/bridge_token_add.go | 15 ++++--- doc/man/git-bug-bridge.1 | 2 +- doc/md/git-bug_bridge.md | 1 + misc/bash_completion/git-bug | 84 ++++++++++++++++++++++++++++++++++++++ misc/powershell_completion/git-bug | 28 +++++++++++++ misc/zsh_completion/git-bug | 46 +++++++++++++++++++++ 11 files changed, 207 insertions(+), 68 deletions(-) diff --git a/bridge/bridges.go b/bridge/bridges.go index dcb35af1..9bbf3941 100644 --- a/bridge/bridges.go +++ b/bridge/bridges.go @@ -3,13 +3,19 @@ package bridge import ( "github.com/MichaelMure/git-bug/bridge/core" - _ "github.com/MichaelMure/git-bug/bridge/github" - _ "github.com/MichaelMure/git-bug/bridge/gitlab" - _ "github.com/MichaelMure/git-bug/bridge/launchpad" + "github.com/MichaelMure/git-bug/bridge/github" + "github.com/MichaelMure/git-bug/bridge/gitlab" + "github.com/MichaelMure/git-bug/bridge/launchpad" "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/repository" ) +func init() { + core.Register(&github.Github{}) + core.Register(&gitlab.Gitlab{}) + core.Register(&launchpad.Launchpad{}) +} + // Targets return all known bridge implementation target func Targets() []string { return core.Targets() diff --git a/bridge/core/token.go b/bridge/core/token.go index 0147f747..89c70af2 100644 --- a/bridge/core/token.go +++ b/bridge/core/token.go @@ -14,7 +14,7 @@ const ( tokenKeyScopes = "scopes" ) -// Token represent token related informations +// Token holds an API access token data type Token struct { Value string Target string @@ -35,47 +35,46 @@ func NewToken(value, target string, global bool, scopes []string) *Token { // Validate ensure token important fields are valid func (t *Token) Validate() error { if t.Value == "" { - return fmt.Errorf("missing token value") + return fmt.Errorf("missing value") } if t.Target == "" { - return fmt.Errorf("missing token target") + return fmt.Errorf("missing target") + } + if _, ok := bridgeImpl[t.Target]; !ok { + return fmt.Errorf("unknown target") } return nil } func loadToken(repo repository.RepoConfig, value string, global bool) (*Token, error) { keyPrefix := fmt.Sprintf("git-bug.token.%s.", value) - var pairs map[string]string - var err error - // read token config pairs + readerFn := repo.ReadConfigs if global { - pairs, err = repo.ReadGlobalConfigs(keyPrefix) - if err != nil { - return nil, err - } - } else { - pairs, err = repo.ReadConfigs(keyPrefix) - if err != nil { - return nil, err - } + readerFn = repo.ReadGlobalConfigs + } + + // read token config pairs + configs, err := readerFn(keyPrefix) + if err != nil { + return nil, err } // trim key prefix - result := make(Configuration, len(pairs)) - for key, value := range pairs { - key := strings.TrimPrefix(key, keyPrefix) - result[key] = value + for key, value := range configs { + newKey := strings.TrimPrefix(key, keyPrefix) + configs[newKey] = value + delete(configs, key) } var ok bool token := &Token{Value: value, Global: global} - token.Target, ok = result[tokenKeyTarget] + token.Target, ok = configs[tokenKeyTarget] if !ok { return nil, fmt.Errorf("empty token key") } - scopesString, ok := result[tokenKeyScopes] + scopesString, ok := configs[tokenKeyScopes] if !ok { return nil, fmt.Errorf("missing scopes config") } @@ -95,18 +94,14 @@ func GetGlobalToken(repo repository.RepoConfig, value string) (*Token, error) { } func listTokens(repo repository.RepoConfig, global bool) ([]string, error) { - var configs map[string]string - var err error + readerFn := repo.ReadConfigs if global { - configs, err = repo.ReadGlobalConfigs(tokenConfigKeyPrefix + ".") - if err != nil { - return nil, err - } - } else { - configs, err = repo.ReadConfigs(tokenConfigKeyPrefix + ".") - if err != nil { - return nil, err - } + readerFn = repo.ReadGlobalConfigs + } + + configs, err := readerFn(tokenConfigKeyPrefix + ".") + if err != nil { + return nil, err } re, err := regexp.Compile(tokenConfigKeyPrefix + `.([^.]+)`) @@ -147,27 +142,19 @@ func ListGlobalTokens(repo repository.RepoConfig) ([]string, error) { } func storeToken(repo repository.RepoConfig, token *Token) error { - var store func(key, value string) error + storeFn := repo.StoreConfig if token.Global { - store = repo.StoreGlobalConfig - } else { - store = repo.StoreConfig + storeFn = repo.StoreGlobalConfig } - var err error storeTargetKey := fmt.Sprintf("git-bug.token.%s.%s", token.Value, tokenKeyTarget) - err = store(storeTargetKey, token.Target) + err := storeFn(storeTargetKey, token.Target) if err != nil { return err } storeScopesKey := fmt.Sprintf("git-bug.token.%s.%s", token.Value, tokenKeyScopes) - err = store(storeScopesKey, strings.Join(token.Scopes, ",")) - if err != nil { - return err - } - - return nil + return storeFn(storeScopesKey, strings.Join(token.Scopes, ",")) } // StoreToken stores a token in the repo config diff --git a/bridge/github/github.go b/bridge/github/github.go index 176bdd84..e4fb03dd 100644 --- a/bridge/github/github.go +++ b/bridge/github/github.go @@ -10,10 +10,6 @@ import ( "github.com/MichaelMure/git-bug/bridge/core" ) -func init() { - core.Register(&Github{}) -} - type Github struct{} func (*Github) Target() string { diff --git a/bridge/gitlab/gitlab.go b/bridge/gitlab/gitlab.go index f4b980ac..05721bfe 100644 --- a/bridge/gitlab/gitlab.go +++ b/bridge/gitlab/gitlab.go @@ -23,10 +23,6 @@ const ( defaultTimeout = 60 * time.Second ) -func init() { - core.Register(&Gitlab{}) -} - type Gitlab struct{} func (*Gitlab) Target() string { diff --git a/bridge/launchpad/launchpad.go b/bridge/launchpad/launchpad.go index 1fd9edc2..030d9169 100644 --- a/bridge/launchpad/launchpad.go +++ b/bridge/launchpad/launchpad.go @@ -5,10 +5,6 @@ import ( "github.com/MichaelMure/git-bug/bridge/core" ) -func init() { - core.Register(&Launchpad{}) -} - type Launchpad struct{} func (*Launchpad) Target() string { diff --git a/commands/bridge_token_add.go b/commands/bridge_token_add.go index 1e62a383..76fed237 100644 --- a/commands/bridge_token_add.go +++ b/commands/bridge_token_add.go @@ -1,6 +1,7 @@ package commands import ( + "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/MichaelMure/git-bug/bridge/core" @@ -11,17 +12,15 @@ var ( ) func runBridgeTokenAdd(cmd *cobra.Command, args []string) error { + if err := bridgeToken.Validate(); err != nil { + return errors.Wrap(err, "invalid token") + } + if bridgeToken.Global { - return core.StoreToken( - repo, - &bridgeToken, - ) + return core.StoreToken(repo, &bridgeToken) } - return core.StoreGlobalToken( - repo, - &bridgeToken, - ) + return core.StoreGlobalToken(repo, &bridgeToken) } var bridgeTokenAddCmd = &cobra.Command{ diff --git a/doc/man/git-bug-bridge.1 b/doc/man/git-bug-bridge.1 index dfede4e0..f7e3ff85 100644 --- a/doc/man/git-bug-bridge.1 +++ b/doc/man/git-bug-bridge.1 @@ -26,4 +26,4 @@ Configure and use bridges to other bug trackers. .SH SEE ALSO .PP -\fBgit\-bug(1)\fP, \fBgit\-bug\-bridge\-configure(1)\fP, \fBgit\-bug\-bridge\-pull(1)\fP, \fBgit\-bug\-bridge\-push(1)\fP, \fBgit\-bug\-bridge\-rm(1)\fP +\fBgit\-bug(1)\fP, \fBgit\-bug\-bridge\-configure(1)\fP, \fBgit\-bug\-bridge\-pull(1)\fP, \fBgit\-bug\-bridge\-push(1)\fP, \fBgit\-bug\-bridge\-rm(1)\fP, \fBgit\-bug\-bridge\-token(1)\fP diff --git a/doc/md/git-bug_bridge.md b/doc/md/git-bug_bridge.md index dfd61e29..7731ff4b 100644 --- a/doc/md/git-bug_bridge.md +++ b/doc/md/git-bug_bridge.md @@ -23,4 +23,5 @@ git-bug bridge [flags] * [git-bug bridge pull](git-bug_bridge_pull.md) - Pull updates. * [git-bug bridge push](git-bug_bridge_push.md) - Push updates. * [git-bug bridge rm](git-bug_bridge_rm.md) - Delete a configured bridge. +* [git-bug bridge token](git-bug_bridge_token.md) - Configure and use bridge tokens. diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug index 2088fd4d..9c719949 100644 --- a/misc/bash_completion/git-bug +++ b/misc/bash_completion/git-bug @@ -400,6 +400,89 @@ _git-bug_bridge_rm() noun_aliases=() } +_git-bug_bridge_token_add() +{ + last_command="git-bug_bridge_token_add" + + command_aliases=() + + commands=() + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--global") + flags+=("-g") + local_nonpersistent_flags+=("--global") + flags+=("--value=") + two_word_flags+=("--value") + two_word_flags+=("-v") + local_nonpersistent_flags+=("--value=") + flags+=("--target=") + two_word_flags+=("--target") + two_word_flags+=("-t") + local_nonpersistent_flags+=("--target=") + flags+=("--scopes=") + two_word_flags+=("--scopes") + two_word_flags+=("-s") + local_nonpersistent_flags+=("--scopes=") + + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() +} + +_git-bug_bridge_token_rm() +{ + last_command="git-bug_bridge_token_rm" + + command_aliases=() + + commands=() + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() +} + +_git-bug_bridge_token() +{ + last_command="git-bug_bridge_token" + + command_aliases=() + + commands=() + commands+=("add") + commands+=("rm") + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--local") + flags+=("-l") + local_nonpersistent_flags+=("--local") + flags+=("--global") + flags+=("-g") + local_nonpersistent_flags+=("--global") + + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() +} + _git-bug_bridge() { last_command="git-bug_bridge" @@ -411,6 +494,7 @@ _git-bug_bridge() commands+=("pull") commands+=("push") commands+=("rm") + commands+=("token") flags=() two_word_flags=() diff --git a/misc/powershell_completion/git-bug b/misc/powershell_completion/git-bug index 34037531..e875b8a2 100644 --- a/misc/powershell_completion/git-bug +++ b/misc/powershell_completion/git-bug @@ -22,6 +22,7 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock { [CompletionResult]::new('commands', 'commands', [CompletionResultType]::ParameterValue, 'Display available commands.') [CompletionResult]::new('comment', 'comment', [CompletionResultType]::ParameterValue, 'Display or add comments to a bug.') [CompletionResult]::new('deselect', 'deselect', [CompletionResultType]::ParameterValue, 'Clear the implicitly selected bug.') + [CompletionResult]::new('export', 'export', [CompletionResultType]::ParameterValue, '') [CompletionResult]::new('label', 'label', [CompletionResultType]::ParameterValue, 'Display, add or remove labels to/from a bug.') [CompletionResult]::new('ls', 'ls', [CompletionResultType]::ParameterValue, 'List bugs.') [CompletionResult]::new('ls-id', 'ls-id', [CompletionResultType]::ParameterValue, 'List bug identifiers.') @@ -52,6 +53,7 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock { [CompletionResult]::new('pull', 'pull', [CompletionResultType]::ParameterValue, 'Pull updates.') [CompletionResult]::new('push', 'push', [CompletionResultType]::ParameterValue, 'Push updates.') [CompletionResult]::new('rm', 'rm', [CompletionResultType]::ParameterValue, 'Delete a configured bridge.') + [CompletionResult]::new('token', 'token', [CompletionResultType]::ParameterValue, 'Configure and use bridge tokens.') break } 'git-bug;bridge;configure' { @@ -83,6 +85,29 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock { 'git-bug;bridge;rm' { break } + 'git-bug;bridge;token' { + [CompletionResult]::new('-l', 'l', [CompletionResultType]::ParameterName, '') + [CompletionResult]::new('--local', 'local', [CompletionResultType]::ParameterName, '') + [CompletionResult]::new('-g', 'g', [CompletionResultType]::ParameterName, '') + [CompletionResult]::new('--global', 'global', [CompletionResultType]::ParameterName, '') + [CompletionResult]::new('add', 'add', [CompletionResultType]::ParameterValue, 'Configure and use bridge tokens.') + [CompletionResult]::new('rm', 'rm', [CompletionResultType]::ParameterValue, 'Configure and use bridge tokens.') + break + } + 'git-bug;bridge;token;add' { + [CompletionResult]::new('-g', 'g', [CompletionResultType]::ParameterName, '') + [CompletionResult]::new('--global', 'global', [CompletionResultType]::ParameterName, '') + [CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, '') + [CompletionResult]::new('--value', 'value', [CompletionResultType]::ParameterName, '') + [CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, '') + [CompletionResult]::new('--target', 'target', [CompletionResultType]::ParameterName, '') + [CompletionResult]::new('-s', 's', [CompletionResultType]::ParameterName, '') + [CompletionResult]::new('--scopes', 'scopes', [CompletionResultType]::ParameterName, '') + break + } + 'git-bug;bridge;token;rm' { + break + } 'git-bug;commands' { [CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Output the command description as well as Markdown compatible comment') [CompletionResult]::new('--pretty', 'pretty', [CompletionResultType]::ParameterName, 'Output the command description as well as Markdown compatible comment') @@ -102,6 +127,9 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock { 'git-bug;deselect' { break } + 'git-bug;export' { + break + } 'git-bug;label' { [CompletionResult]::new('add', 'add', [CompletionResultType]::ParameterValue, 'Add a label to a bug.') [CompletionResult]::new('rm', 'rm', [CompletionResultType]::ParameterValue, 'Remove a label from a bug.') diff --git a/misc/zsh_completion/git-bug b/misc/zsh_completion/git-bug index 9951bab9..1f4679ad 100644 --- a/misc/zsh_completion/git-bug +++ b/misc/zsh_completion/git-bug @@ -118,6 +118,7 @@ function _git-bug_bridge { "pull:Pull updates." "push:Push updates." "rm:Delete a configured bridge." + "token:Configure and use bridge tokens." ) _describe "command" commands ;; @@ -136,6 +137,9 @@ function _git-bug_bridge { rm) _git-bug_bridge_rm ;; + token) + _git-bug_bridge_token + ;; esac } @@ -164,6 +168,48 @@ function _git-bug_bridge_rm { _arguments } + +function _git-bug_bridge_token { + local -a commands + + _arguments -C \ + '(-l --local)'{-l,--local}'[]' \ + '(-g --global)'{-g,--global}'[]' \ + "1: :->cmnds" \ + "*::arg:->args" + + case $state in + cmnds) + commands=( + "add:Configure and use bridge tokens." + "rm:Configure and use bridge tokens." + ) + _describe "command" commands + ;; + esac + + case "$words[1]" in + add) + _git-bug_bridge_token_add + ;; + rm) + _git-bug_bridge_token_rm + ;; + esac +} + +function _git-bug_bridge_token_add { + _arguments \ + '(-g --global)'{-g,--global}'[]' \ + '(-v --value)'{-v,--value}'[]:' \ + '(-t --target)'{-t,--target}'[]:' \ + '(*-s *--scopes)'{\*-s,\*--scopes}'[]:' +} + +function _git-bug_bridge_token_rm { + _arguments +} + function _git-bug_commands { _arguments \ '(-p --pretty)'{-p,--pretty}'[Output the command description as well as Markdown compatible comment]' -- cgit From baefa687b582632cd9cc21b945bc074c833f5389 Mon Sep 17 00:00:00 2001 From: amine Date: Thu, 24 Oct 2019 20:16:51 +0200 Subject: tokens: use a hash as token identifier instead of the token it self --- bridge/core/token.go | 129 ++++++++++++++++++++++++++++--------- commands/bridge_token.go | 71 +++++++++----------- commands/bridge_token_add.go | 10 ++- commands/bridge_token_rm.go | 2 +- doc/man/git-bug-bridge-token-add.1 | 41 ++++++++++++ doc/man/git-bug-bridge-token-rm.1 | 29 +++++++++ doc/man/git-bug-bridge-token.1 | 35 ++++++++++ doc/md/git-bug_bridge.md | 2 +- doc/md/git-bug_bridge_token.md | 26 ++++++++ doc/md/git-bug_bridge_token_add.md | 26 ++++++++ doc/md/git-bug_bridge_token_rm.md | 22 +++++++ misc/powershell_completion/git-bug | 10 +-- misc/zsh_completion/git-bug | 6 +- 13 files changed, 319 insertions(+), 90 deletions(-) create mode 100644 doc/man/git-bug-bridge-token-add.1 create mode 100644 doc/man/git-bug-bridge-token-rm.1 create mode 100644 doc/man/git-bug-bridge-token.1 create mode 100644 doc/md/git-bug_bridge_token.md create mode 100644 doc/md/git-bug_bridge_token_add.md create mode 100644 doc/md/git-bug_bridge_token_rm.md diff --git a/bridge/core/token.go b/bridge/core/token.go index 89c70af2..bd97cd18 100644 --- a/bridge/core/token.go +++ b/bridge/core/token.go @@ -1,6 +1,8 @@ package core import ( + "crypto/sha256" + "encoding/json" "fmt" "regexp" "strings" @@ -10,12 +12,14 @@ import ( const ( tokenConfigKeyPrefix = "git-bug.token" - tokenKeyTarget = "target" - tokenKeyScopes = "scopes" + tokenValueKey = "value" + tokenTargetKey = "target" + tokenScopesKey = "scopes" ) // Token holds an API access token data type Token struct { + ID string Value string Target string Global bool @@ -24,16 +28,46 @@ type Token struct { // NewToken instantiate a new token func NewToken(value, target string, global bool, scopes []string) *Token { - return &Token{ + token := &Token{ Value: value, Target: target, Global: global, Scopes: scopes, } + + token.ID = hashToken(token) + return token +} + +// Id return full token identifier. It will compute the Id if it's empty +func (t *Token) Id() string { + if t.ID == "" { + t.ID = hashToken(t) + } + + return t.ID +} + +// HumanId return the truncated token id +func (t *Token) HumanId() string { + return t.Id()[:6] +} + +func hashToken(token *Token) string { + tokenJson, err := json.Marshal(&token) + if err != nil { + panic(err) + } + + sum := sha256.Sum256(tokenJson) + return fmt.Sprintf("%x", sum) } // Validate ensure token important fields are valid func (t *Token) Validate() error { + if t.ID == "" { + return fmt.Errorf("missing id") + } if t.Value == "" { return fmt.Errorf("missing value") } @@ -46,8 +80,17 @@ func (t *Token) Validate() error { return nil } -func loadToken(repo repository.RepoConfig, value string, global bool) (*Token, error) { - keyPrefix := fmt.Sprintf("git-bug.token.%s.", value) +// Kind return the type of the token as string +func (t *Token) Kind() string { + if t.Global { + return "global" + } + + return "local" +} + +func loadToken(repo repository.RepoConfig, id string, global bool) (*Token, error) { + keyPrefix := fmt.Sprintf("git-bug.token.%s.", id) readerFn := repo.ReadConfigs if global { @@ -62,19 +105,25 @@ func loadToken(repo repository.RepoConfig, value string, global bool) (*Token, e // trim key prefix for key, value := range configs { + delete(configs, key) newKey := strings.TrimPrefix(key, keyPrefix) configs[newKey] = value - delete(configs, key) } var ok bool - token := &Token{Value: value, Global: global} - token.Target, ok = configs[tokenKeyTarget] + token := &Token{ID: id, Global: global} + + token.Value, ok = configs[tokenValueKey] + if !ok { + return nil, fmt.Errorf("empty token value") + } + + token.Target, ok = configs[tokenTargetKey] if !ok { return nil, fmt.Errorf("empty token key") } - scopesString, ok := configs[tokenKeyScopes] + scopesString, ok := configs[tokenScopesKey] if !ok { return nil, fmt.Errorf("missing scopes config") } @@ -84,13 +133,13 @@ func loadToken(repo repository.RepoConfig, value string, global bool) (*Token, e } // GetToken loads a token from repo config -func GetToken(repo repository.RepoConfig, value string) (*Token, error) { - return loadToken(repo, value, false) +func GetToken(repo repository.RepoConfig, id string) (*Token, error) { + return loadToken(repo, id, false) } // GetGlobalToken loads a token from the global config -func GetGlobalToken(repo repository.RepoConfig, value string) (*Token, error) { - return loadToken(repo, value, true) +func GetGlobalToken(repo repository.RepoConfig, id string) (*Token, error) { + return loadToken(repo, id, true) } func listTokens(repo repository.RepoConfig, global bool) ([]string, error) { @@ -131,14 +180,29 @@ func listTokens(repo repository.RepoConfig, global bool) ([]string, error) { return result, nil } -// ListTokens return the list of stored tokens in the repo config -func ListTokens(repo repository.RepoConfig) ([]string, error) { - return listTokens(repo, false) -} +// ListTokens return a map representing the stored tokens in the repo config and global config +// along with their type (global: true, local:false) +func ListTokens(repo repository.RepoConfig) (map[string]bool, error) { + localTokens, err := listTokens(repo, false) + if err != nil { + return nil, err + } -// ListGlobalTokens return the list of stored tokens in the global config -func ListGlobalTokens(repo repository.RepoConfig) ([]string, error) { - return listTokens(repo, true) + globalTokens, err := listTokens(repo, true) + if err != nil { + return nil, err + } + + tokens := map[string]bool{} + for _, token := range localTokens { + tokens[token] = false + } + + for _, token := range globalTokens { + tokens[token] = true + } + + return tokens, nil } func storeToken(repo repository.RepoConfig, token *Token) error { @@ -147,13 +211,19 @@ func storeToken(repo repository.RepoConfig, token *Token) error { storeFn = repo.StoreGlobalConfig } - storeTargetKey := fmt.Sprintf("git-bug.token.%s.%s", token.Value, tokenKeyTarget) - err := storeFn(storeTargetKey, token.Target) + storeValueKey := fmt.Sprintf("git-bug.token.%s.%s", token.Id(), tokenValueKey) + err := storeFn(storeValueKey, token.Value) + if err != nil { + return err + } + + storeTargetKey := fmt.Sprintf("git-bug.token.%s.%s", token.Id(), tokenTargetKey) + err = storeFn(storeTargetKey, token.Target) if err != nil { return err } - storeScopesKey := fmt.Sprintf("git-bug.token.%s.%s", token.Value, tokenKeyScopes) + storeScopesKey := fmt.Sprintf("git-bug.token.%s.%s", token.Id(), tokenScopesKey) return storeFn(storeScopesKey, strings.Join(token.Scopes, ",")) } @@ -162,19 +232,14 @@ func StoreToken(repo repository.RepoConfig, token *Token) error { return storeToken(repo, token) } -// StoreGlobalToken stores a token in global config -func StoreGlobalToken(repo repository.RepoConfig, token *Token) error { - return storeToken(repo, token) -} - // RemoveToken removes a token from the repo config -func RemoveToken(repo repository.RepoConfig, value string) error { - keyPrefix := fmt.Sprintf("git-bug.token.%s", value) +func RemoveToken(repo repository.RepoConfig, id string) error { + keyPrefix := fmt.Sprintf("git-bug.token.%s", id) return repo.RmConfigs(keyPrefix) } // RemoveGlobalToken removes a token from the repo config -func RemoveGlobalToken(repo repository.RepoConfig, value string) error { - keyPrefix := fmt.Sprintf("git-bug.token.%s", value) +func RemoveGlobalToken(repo repository.RepoConfig, id string) error { + keyPrefix := fmt.Sprintf("git-bug.token.%s", id) return repo.RmGlobalConfigs(keyPrefix) } diff --git a/commands/bridge_token.go b/commands/bridge_token.go index cb9754c3..f33ee3e3 100644 --- a/commands/bridge_token.go +++ b/commands/bridge_token.go @@ -14,8 +14,8 @@ import ( ) var ( - bridgeTokenLocalOnly bool - bridgeTokenGlobalOnly bool + bridgeTokenLocal bool + bridgeTokenGlobal bool ) func runTokenBridge(cmd *cobra.Command, args []string) error { @@ -26,55 +26,46 @@ func runTokenBridge(cmd *cobra.Command, args []string) error { defer backend.Close() interrupt.RegisterCleaner(backend.Close) - var tokens []*core.Token - if !bridgeTokenGlobalOnly { - localTokens, err := core.ListTokens(backend) - if err != nil { - return err - } + tokens, err := core.ListTokens(backend) + if err != nil { + return err + } - for _, id := range localTokens { - token, err := core.GetToken(repo, id) - if err != nil { - return err - } - tokens = append(tokens, token) + for token, global := range tokens { + // TODO: filter tokens using flags + getTokenFn := core.GetToken + if global { + getTokenFn = core.GetGlobalToken } - } - if !bridgeTokenLocalOnly { - globalTokens, err := core.ListGlobalTokens(backend) + token, err := getTokenFn(repo, token) if err != nil { return err } - - for _, id := range globalTokens { - token, err := core.GetGlobalToken(repo, id) - if err != nil { - return err - } - tokens = append(tokens, token) - } + printToken(token) } - for _, token := range tokens { - valueFmt := text.LeftPadMaxLine(token.Value, 20, 0) - targetFmt := text.LeftPadMaxLine(token.Target, 8, 0) - scopesFmt := text.LeftPadMaxLine(strings.Join(token.Scopes, ","), 20, 0) - - fmt.Printf("%s %s %s %s\n", - valueFmt, - colors.Magenta(targetFmt), - colors.Yellow(token.Global), - scopesFmt, - ) - } return nil } +func printToken(token *core.Token) { + idFmt := text.LeftPadMaxLine(token.HumanId(), 6, 0) + valueFmt := text.LeftPadMaxLine(token.Value, 8, 0) + targetFmt := text.LeftPadMaxLine(token.Target, 8, 0) + scopesFmt := text.LeftPadMaxLine(strings.Join(token.Scopes, ","), 20, 0) + + fmt.Printf("%s %s %s %s %s\n", + idFmt, + valueFmt, + colors.Magenta(targetFmt), + colors.Yellow(token.Kind()), + scopesFmt, + ) +} + var bridgeTokenCmd = &cobra.Command{ Use: "token", - Short: "Configure and use bridge tokens.", + Short: "List all stored tokens.", PreRunE: loadRepo, RunE: runTokenBridge, Args: cobra.NoArgs, @@ -82,7 +73,7 @@ var bridgeTokenCmd = &cobra.Command{ func init() { bridgeCmd.AddCommand(bridgeTokenCmd) - bridgeTokenCmd.Flags().BoolVarP(&bridgeTokenLocalOnly, "local", "l", false, "") - bridgeTokenCmd.Flags().BoolVarP(&bridgeTokenGlobalOnly, "global", "g", false, "") + bridgeTokenCmd.Flags().BoolVarP(&bridgeTokenLocal, "local", "l", false, "") + bridgeTokenCmd.Flags().BoolVarP(&bridgeTokenGlobal, "global", "g", false, "") bridgeTokenCmd.Flags().SortFlags = false } diff --git a/commands/bridge_token_add.go b/commands/bridge_token_add.go index 76fed237..7b7a8964 100644 --- a/commands/bridge_token_add.go +++ b/commands/bridge_token_add.go @@ -12,20 +12,18 @@ var ( ) func runBridgeTokenAdd(cmd *cobra.Command, args []string) error { + _ = bridgeToken.Id() // TODO: a better design to avoid doing this + if err := bridgeToken.Validate(); err != nil { return errors.Wrap(err, "invalid token") } - if bridgeToken.Global { - return core.StoreToken(repo, &bridgeToken) - } - - return core.StoreGlobalToken(repo, &bridgeToken) + return core.StoreToken(repo, &bridgeToken) } var bridgeTokenAddCmd = &cobra.Command{ Use: "add", - Short: "Configure and use bridge tokens.", + Short: "Create and store a new token", PreRunE: loadRepo, RunE: runBridgeTokenAdd, Args: cobra.NoArgs, diff --git a/commands/bridge_token_rm.go b/commands/bridge_token_rm.go index 7fd79126..29fdb4f2 100644 --- a/commands/bridge_token_rm.go +++ b/commands/bridge_token_rm.go @@ -18,7 +18,7 @@ func runBridgeTokenRm(cmd *cobra.Command, args []string) error { var bridgeTokenRmCmd = &cobra.Command{ Use: "rm", - Short: "Configure and use bridge tokens.", + Short: "Remove token by Id.", PreRunE: loadRepo, RunE: runBridgeTokenRm, Args: cobra.ExactArgs(1), diff --git a/doc/man/git-bug-bridge-token-add.1 b/doc/man/git-bug-bridge-token-add.1 new file mode 100644 index 00000000..1eb5bb20 --- /dev/null +++ b/doc/man/git-bug-bridge-token-add.1 @@ -0,0 +1,41 @@ +.TH "GIT-BUG" "1" "Apr 2019" "Generated from git-bug's source code" "" +.nh +.ad l + + +.SH NAME +.PP +git\-bug\-bridge\-token\-add \- Create and store a new token + + +.SH SYNOPSIS +.PP +\fBgit\-bug bridge token add [flags]\fP + + +.SH DESCRIPTION +.PP +Create and store a new token + + +.SH OPTIONS +.PP +\fB\-g\fP, \fB\-\-global\fP[=false] + +.PP +\fB\-v\fP, \fB\-\-value\fP="" + +.PP +\fB\-t\fP, \fB\-\-target\fP="" + +.PP +\fB\-s\fP, \fB\-\-scopes\fP=[] + +.PP +\fB\-h\fP, \fB\-\-help\fP[=false] + help for add + + +.SH SEE ALSO +.PP +\fBgit\-bug\-bridge\-token(1)\fP diff --git a/doc/man/git-bug-bridge-token-rm.1 b/doc/man/git-bug-bridge-token-rm.1 new file mode 100644 index 00000000..5c5a16a6 --- /dev/null +++ b/doc/man/git-bug-bridge-token-rm.1 @@ -0,0 +1,29 @@ +.TH "GIT-BUG" "1" "Apr 2019" "Generated from git-bug's source code" "" +.nh +.ad l + + +.SH NAME +.PP +git\-bug\-bridge\-token\-rm \- Remove token by Id. + + +.SH SYNOPSIS +.PP +\fBgit\-bug bridge token rm [flags]\fP + + +.SH DESCRIPTION +.PP +Remove token by Id. + + +.SH OPTIONS +.PP +\fB\-h\fP, \fB\-\-help\fP[=false] + help for rm + + +.SH SEE ALSO +.PP +\fBgit\-bug\-bridge\-token(1)\fP diff --git a/doc/man/git-bug-bridge-token.1 b/doc/man/git-bug-bridge-token.1 new file mode 100644 index 00000000..d97c8e33 --- /dev/null +++ b/doc/man/git-bug-bridge-token.1 @@ -0,0 +1,35 @@ +.TH "GIT-BUG" "1" "Apr 2019" "Generated from git-bug's source code" "" +.nh +.ad l + + +.SH NAME +.PP +git\-bug\-bridge\-token \- List all stored tokens. + + +.SH SYNOPSIS +.PP +\fBgit\-bug bridge token [flags]\fP + + +.SH DESCRIPTION +.PP +List all stored tokens. + + +.SH OPTIONS +.PP +\fB\-l\fP, \fB\-\-local\fP[=false] + +.PP +\fB\-g\fP, \fB\-\-global\fP[=false] + +.PP +\fB\-h\fP, \fB\-\-help\fP[=false] + help for token + + +.SH SEE ALSO +.PP +\fBgit\-bug\-bridge(1)\fP, \fBgit\-bug\-bridge\-token\-add(1)\fP, \fBgit\-bug\-bridge\-token\-rm(1)\fP diff --git a/doc/md/git-bug_bridge.md b/doc/md/git-bug_bridge.md index 7731ff4b..a965074d 100644 --- a/doc/md/git-bug_bridge.md +++ b/doc/md/git-bug_bridge.md @@ -23,5 +23,5 @@ git-bug bridge [flags] * [git-bug bridge pull](git-bug_bridge_pull.md) - Pull updates. * [git-bug bridge push](git-bug_bridge_push.md) - Push updates. * [git-bug bridge rm](git-bug_bridge_rm.md) - Delete a configured bridge. -* [git-bug bridge token](git-bug_bridge_token.md) - Configure and use bridge tokens. +* [git-bug bridge token](git-bug_bridge_token.md) - List all stored tokens. diff --git a/doc/md/git-bug_bridge_token.md b/doc/md/git-bug_bridge_token.md new file mode 100644 index 00000000..5e6baa26 --- /dev/null +++ b/doc/md/git-bug_bridge_token.md @@ -0,0 +1,26 @@ +## git-bug bridge token + +List all stored tokens. + +### Synopsis + +List all stored tokens. + +``` +git-bug bridge token [flags] +``` + +### Options + +``` + -l, --local + -g, --global + -h, --help help for token +``` + +### SEE ALSO + +* [git-bug bridge](git-bug_bridge.md) - Configure and use bridges to other bug trackers. +* [git-bug bridge token add](git-bug_bridge_token_add.md) - Create and store a new token +* [git-bug bridge token rm](git-bug_bridge_token_rm.md) - Remove token by Id. + diff --git a/doc/md/git-bug_bridge_token_add.md b/doc/md/git-bug_bridge_token_add.md new file mode 100644 index 00000000..6ef705d0 --- /dev/null +++ b/doc/md/git-bug_bridge_token_add.md @@ -0,0 +1,26 @@ +## git-bug bridge token add + +Create and store a new token + +### Synopsis + +Create and store a new token + +``` +git-bug bridge token add [flags] +``` + +### Options + +``` + -g, --global + -v, --value string + -t, --target string + -s, --scopes stringArray + -h, --help help for add +``` + +### SEE ALSO + +* [git-bug bridge token](git-bug_bridge_token.md) - List all stored tokens. + diff --git a/doc/md/git-bug_bridge_token_rm.md b/doc/md/git-bug_bridge_token_rm.md new file mode 100644 index 00000000..52417a9c --- /dev/null +++ b/doc/md/git-bug_bridge_token_rm.md @@ -0,0 +1,22 @@ +## git-bug bridge token rm + +Remove token by Id. + +### Synopsis + +Remove token by Id. + +``` +git-bug bridge token rm [flags] +``` + +### Options + +``` + -h, --help help for rm +``` + +### SEE ALSO + +* [git-bug bridge token](git-bug_bridge_token.md) - List all stored tokens. + diff --git a/misc/powershell_completion/git-bug b/misc/powershell_completion/git-bug index e875b8a2..d92bc04b 100644 --- a/misc/powershell_completion/git-bug +++ b/misc/powershell_completion/git-bug @@ -22,7 +22,6 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock { [CompletionResult]::new('commands', 'commands', [CompletionResultType]::ParameterValue, 'Display available commands.') [CompletionResult]::new('comment', 'comment', [CompletionResultType]::ParameterValue, 'Display or add comments to a bug.') [CompletionResult]::new('deselect', 'deselect', [CompletionResultType]::ParameterValue, 'Clear the implicitly selected bug.') - [CompletionResult]::new('export', 'export', [CompletionResultType]::ParameterValue, '') [CompletionResult]::new('label', 'label', [CompletionResultType]::ParameterValue, 'Display, add or remove labels to/from a bug.') [CompletionResult]::new('ls', 'ls', [CompletionResultType]::ParameterValue, 'List bugs.') [CompletionResult]::new('ls-id', 'ls-id', [CompletionResultType]::ParameterValue, 'List bug identifiers.') @@ -53,7 +52,7 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock { [CompletionResult]::new('pull', 'pull', [CompletionResultType]::ParameterValue, 'Pull updates.') [CompletionResult]::new('push', 'push', [CompletionResultType]::ParameterValue, 'Push updates.') [CompletionResult]::new('rm', 'rm', [CompletionResultType]::ParameterValue, 'Delete a configured bridge.') - [CompletionResult]::new('token', 'token', [CompletionResultType]::ParameterValue, 'Configure and use bridge tokens.') + [CompletionResult]::new('token', 'token', [CompletionResultType]::ParameterValue, 'List all stored tokens.') break } 'git-bug;bridge;configure' { @@ -90,8 +89,8 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock { [CompletionResult]::new('--local', 'local', [CompletionResultType]::ParameterName, '') [CompletionResult]::new('-g', 'g', [CompletionResultType]::ParameterName, '') [CompletionResult]::new('--global', 'global', [CompletionResultType]::ParameterName, '') - [CompletionResult]::new('add', 'add', [CompletionResultType]::ParameterValue, 'Configure and use bridge tokens.') - [CompletionResult]::new('rm', 'rm', [CompletionResultType]::ParameterValue, 'Configure and use bridge tokens.') + [CompletionResult]::new('add', 'add', [CompletionResultType]::ParameterValue, 'Create and store a new token') + [CompletionResult]::new('rm', 'rm', [CompletionResultType]::ParameterValue, 'Remove token by Id.') break } 'git-bug;bridge;token;add' { @@ -127,9 +126,6 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock { 'git-bug;deselect' { break } - 'git-bug;export' { - break - } 'git-bug;label' { [CompletionResult]::new('add', 'add', [CompletionResultType]::ParameterValue, 'Add a label to a bug.') [CompletionResult]::new('rm', 'rm', [CompletionResultType]::ParameterValue, 'Remove a label from a bug.') diff --git a/misc/zsh_completion/git-bug b/misc/zsh_completion/git-bug index 1f4679ad..d9da4ac2 100644 --- a/misc/zsh_completion/git-bug +++ b/misc/zsh_completion/git-bug @@ -118,7 +118,7 @@ function _git-bug_bridge { "pull:Pull updates." "push:Push updates." "rm:Delete a configured bridge." - "token:Configure and use bridge tokens." + "token:List all stored tokens." ) _describe "command" commands ;; @@ -181,8 +181,8 @@ function _git-bug_bridge_token { case $state in cmnds) commands=( - "add:Configure and use bridge tokens." - "rm:Configure and use bridge tokens." + "add:Create and store a new token" + "rm:Remove token by Id." ) _describe "command" commands ;; -- cgit From 4dc7b8b06ed5d48eca077b81a0b8c90777b8fe82 Mon Sep 17 00:00:00 2001 From: amine Date: Thu, 24 Oct 2019 20:39:13 +0200 Subject: tokens: use entity.Id as id type --- bridge/core/token.go | 17 +++++++++-------- commands/bridge_token.go | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/bridge/core/token.go b/bridge/core/token.go index bd97cd18..cd5303d5 100644 --- a/bridge/core/token.go +++ b/bridge/core/token.go @@ -4,6 +4,7 @@ import ( "crypto/sha256" "encoding/json" "fmt" + "github.com/MichaelMure/git-bug/entity" "regexp" "strings" @@ -19,7 +20,7 @@ const ( // Token holds an API access token data type Token struct { - ID string + id entity.Id Value string Target string Global bool @@ -35,22 +36,22 @@ func NewToken(value, target string, global bool, scopes []string) *Token { Scopes: scopes, } - token.ID = hashToken(token) + token.id = entity.Id(hashToken(token)) return token } // Id return full token identifier. It will compute the Id if it's empty func (t *Token) Id() string { - if t.ID == "" { - t.ID = hashToken(t) + if t.id == "" { + t.id = entity.Id(hashToken(t)) } - return t.ID + return t.id.String() } // HumanId return the truncated token id func (t *Token) HumanId() string { - return t.Id()[:6] + return t.id.Human() } func hashToken(token *Token) string { @@ -65,7 +66,7 @@ func hashToken(token *Token) string { // Validate ensure token important fields are valid func (t *Token) Validate() error { - if t.ID == "" { + if t.id == "" { return fmt.Errorf("missing id") } if t.Value == "" { @@ -111,7 +112,7 @@ func loadToken(repo repository.RepoConfig, id string, global bool) (*Token, erro } var ok bool - token := &Token{ID: id, Global: global} + token := &Token{id: entity.Id(id), Global: global} token.Value, ok = configs[tokenValueKey] if !ok { diff --git a/commands/bridge_token.go b/commands/bridge_token.go index f33ee3e3..cdae0664 100644 --- a/commands/bridge_token.go +++ b/commands/bridge_token.go @@ -49,7 +49,7 @@ func runTokenBridge(cmd *cobra.Command, args []string) error { } func printToken(token *core.Token) { - idFmt := text.LeftPadMaxLine(token.HumanId(), 6, 0) + idFmt := text.LeftPadMaxLine(token.HumanId(), 7, 0) valueFmt := text.LeftPadMaxLine(token.Value, 8, 0) targetFmt := text.LeftPadMaxLine(token.Target, 8, 0) scopesFmt := text.LeftPadMaxLine(strings.Join(token.Scopes, ","), 20, 0) -- cgit From bbbf3c6c7f245ea2ddc9d31639e7ebac50eeac2d Mon Sep 17 00:00:00 2001 From: amine Date: Fri, 8 Nov 2019 14:49:24 +0100 Subject: bridge/core: store token in the global config and replace scopes with create date --- bridge/core/token.go | 168 ++++++++++++------------------------------- commands/bridge_token.go | 29 +++----- commands/bridge_token_add.go | 16 ++--- commands/bridge_token_rm.go | 8 +-- 4 files changed, 64 insertions(+), 157 deletions(-) diff --git a/bridge/core/token.go b/bridge/core/token.go index cd5303d5..09294e49 100644 --- a/bridge/core/token.go +++ b/bridge/core/token.go @@ -2,11 +2,14 @@ package core import ( "crypto/sha256" - "encoding/json" "fmt" - "github.com/MichaelMure/git-bug/entity" "regexp" + "strconv" "strings" + "time" + + "github.com/MichaelMure/git-bug/entity" + "github.com/araddon/dateparse" "github.com/MichaelMure/git-bug/repository" ) @@ -15,58 +18,37 @@ const ( tokenConfigKeyPrefix = "git-bug.token" tokenValueKey = "value" tokenTargetKey = "target" - tokenScopesKey = "scopes" + tokenCreateTimeKey = "createtime" ) // Token holds an API access token data type Token struct { - id entity.Id - Value string - Target string - Global bool - Scopes []string + ID entity.Id + Value string + Target string + CreateTime time.Time } // NewToken instantiate a new token -func NewToken(value, target string, global bool, scopes []string) *Token { +func NewToken(value, target string) *Token { token := &Token{ - Value: value, - Target: target, - Global: global, - Scopes: scopes, + Value: value, + Target: target, + CreateTime: time.Now(), } - token.id = entity.Id(hashToken(token)) + token.ID = entity.Id(hashToken(token)) return token } -// Id return full token identifier. It will compute the Id if it's empty -func (t *Token) Id() string { - if t.id == "" { - t.id = entity.Id(hashToken(t)) - } - - return t.id.String() -} - -// HumanId return the truncated token id -func (t *Token) HumanId() string { - return t.id.Human() -} - func hashToken(token *Token) string { - tokenJson, err := json.Marshal(&token) - if err != nil { - panic(err) - } - - sum := sha256.Sum256(tokenJson) + sum := sha256.Sum256([]byte(token.Value)) return fmt.Sprintf("%x", sum) } // Validate ensure token important fields are valid func (t *Token) Validate() error { - if t.id == "" { + if t.ID == "" { return fmt.Errorf("missing id") } if t.Value == "" { @@ -75,31 +57,21 @@ func (t *Token) Validate() error { if t.Target == "" { return fmt.Errorf("missing target") } + if t.CreateTime.Equal(time.Time{}) { + return fmt.Errorf("missing creation time") + } if _, ok := bridgeImpl[t.Target]; !ok { return fmt.Errorf("unknown target") } return nil } -// Kind return the type of the token as string -func (t *Token) Kind() string { - if t.Global { - return "global" - } - - return "local" -} - -func loadToken(repo repository.RepoConfig, id string, global bool) (*Token, error) { +// LoadToken loads a token from repo config +func LoadToken(repo repository.RepoCommon, id string) (*Token, error) { keyPrefix := fmt.Sprintf("git-bug.token.%s.", id) - readerFn := repo.ReadConfigs - if global { - readerFn = repo.ReadGlobalConfigs - } - // read token config pairs - configs, err := readerFn(keyPrefix) + configs, err := repo.GlobalConfig().ReadAll(keyPrefix) if err != nil { return nil, err } @@ -111,9 +83,9 @@ func loadToken(repo repository.RepoConfig, id string, global bool) (*Token, erro configs[newKey] = value } - var ok bool - token := &Token{id: entity.Id(id), Global: global} + token := &Token{ID: entity.Id(id)} + var ok bool token.Value, ok = configs[tokenValueKey] if !ok { return nil, fmt.Errorf("empty token value") @@ -124,32 +96,22 @@ func loadToken(repo repository.RepoConfig, id string, global bool) (*Token, erro return nil, fmt.Errorf("empty token key") } - scopesString, ok := configs[tokenScopesKey] + createTime, ok := configs[tokenCreateTimeKey] if !ok { - return nil, fmt.Errorf("missing scopes config") + return nil, fmt.Errorf("missing createtime key") } - token.Scopes = strings.Split(scopesString, ",") + token.CreateTime, err = dateparse.ParseLocal(createTime) + if err != nil { + return nil, err + } return token, nil } -// GetToken loads a token from repo config -func GetToken(repo repository.RepoConfig, id string) (*Token, error) { - return loadToken(repo, id, false) -} - -// GetGlobalToken loads a token from the global config -func GetGlobalToken(repo repository.RepoConfig, id string) (*Token, error) { - return loadToken(repo, id, true) -} - -func listTokens(repo repository.RepoConfig, global bool) ([]string, error) { - readerFn := repo.ReadConfigs - if global { - readerFn = repo.ReadGlobalConfigs - } - - configs, err := readerFn(tokenConfigKeyPrefix + ".") +// ListTokens return a map representing the stored tokens in the repo config and global config +// along with their type (global: true, local:false) +func ListTokens(repo repository.RepoCommon) ([]string, error) { + configs, err := repo.GlobalConfig().ReadAll(tokenConfigKeyPrefix + ".") if err != nil { return nil, err } @@ -181,66 +143,26 @@ func listTokens(repo repository.RepoConfig, global bool) ([]string, error) { return result, nil } -// ListTokens return a map representing the stored tokens in the repo config and global config -// along with their type (global: true, local:false) -func ListTokens(repo repository.RepoConfig) (map[string]bool, error) { - localTokens, err := listTokens(repo, false) - if err != nil { - return nil, err - } - - globalTokens, err := listTokens(repo, true) - if err != nil { - return nil, err - } - - tokens := map[string]bool{} - for _, token := range localTokens { - tokens[token] = false - } - - for _, token := range globalTokens { - tokens[token] = true - } - - return tokens, nil -} - -func storeToken(repo repository.RepoConfig, token *Token) error { - storeFn := repo.StoreConfig - if token.Global { - storeFn = repo.StoreGlobalConfig - } - - storeValueKey := fmt.Sprintf("git-bug.token.%s.%s", token.Id(), tokenValueKey) - err := storeFn(storeValueKey, token.Value) +// StoreToken stores a token in the repo config +func StoreToken(repo repository.RepoCommon, token *Token) error { + storeValueKey := fmt.Sprintf("git-bug.token.%s.%s", token.ID.String(), tokenValueKey) + err := repo.GlobalConfig().StoreString(storeValueKey, token.Value) if err != nil { return err } - storeTargetKey := fmt.Sprintf("git-bug.token.%s.%s", token.Id(), tokenTargetKey) - err = storeFn(storeTargetKey, token.Target) + storeTargetKey := fmt.Sprintf("git-bug.token.%s.%s", token.ID.String(), tokenTargetKey) + err = repo.GlobalConfig().StoreString(storeTargetKey, token.Target) if err != nil { return err } - storeScopesKey := fmt.Sprintf("git-bug.token.%s.%s", token.Id(), tokenScopesKey) - return storeFn(storeScopesKey, strings.Join(token.Scopes, ",")) -} - -// StoreToken stores a token in the repo config -func StoreToken(repo repository.RepoConfig, token *Token) error { - return storeToken(repo, token) + createTimeKey := fmt.Sprintf("git-bug.token.%s.%s", token.ID.String(), tokenCreateTimeKey) + return repo.GlobalConfig().StoreString(createTimeKey, strconv.Itoa(int(token.CreateTime.Unix()))) } // RemoveToken removes a token from the repo config -func RemoveToken(repo repository.RepoConfig, id string) error { - keyPrefix := fmt.Sprintf("git-bug.token.%s", id) - return repo.RmConfigs(keyPrefix) -} - -// RemoveGlobalToken removes a token from the repo config -func RemoveGlobalToken(repo repository.RepoConfig, id string) error { +func RemoveToken(repo repository.RepoCommon, id string) error { keyPrefix := fmt.Sprintf("git-bug.token.%s", id) - return repo.RmGlobalConfigs(keyPrefix) + return repo.GlobalConfig().RemoveAll(keyPrefix) } diff --git a/commands/bridge_token.go b/commands/bridge_token.go index cdae0664..7467691e 100644 --- a/commands/bridge_token.go +++ b/commands/bridge_token.go @@ -2,7 +2,7 @@ package commands import ( "fmt" - "strings" + "time" "github.com/spf13/cobra" @@ -10,7 +10,7 @@ import ( "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/util/colors" "github.com/MichaelMure/git-bug/util/interrupt" - "github.com/MichaelMure/git-bug/util/text" + text "github.com/MichaelMure/go-term-text" ) var ( @@ -31,14 +31,8 @@ func runTokenBridge(cmd *cobra.Command, args []string) error { return err } - for token, global := range tokens { - // TODO: filter tokens using flags - getTokenFn := core.GetToken - if global { - getTokenFn = core.GetGlobalToken - } - - token, err := getTokenFn(repo, token) + for _, token := range tokens { + token, err := core.LoadToken(repo, token) if err != nil { return err } @@ -49,17 +43,16 @@ func runTokenBridge(cmd *cobra.Command, args []string) error { } func printToken(token *core.Token) { - idFmt := text.LeftPadMaxLine(token.HumanId(), 7, 0) - valueFmt := text.LeftPadMaxLine(token.Value, 8, 0) - targetFmt := text.LeftPadMaxLine(token.Target, 8, 0) - scopesFmt := text.LeftPadMaxLine(strings.Join(token.Scopes, ","), 20, 0) + idFmt := text.LeftPadMaxLine(token.ID.Human(), 7, 0) + valueFmt := text.LeftPadMaxLine(token.Value, 15, 0) + targetFmt := text.LeftPadMaxLine(token.Target, 7, 0) + createTimeFmt := text.LeftPadMaxLine(token.CreateTime.Format(time.RFC822), 20, 0) - fmt.Printf("%s %s %s %s %s\n", + fmt.Printf("%s %s %s %s\n", idFmt, - valueFmt, colors.Magenta(targetFmt), - colors.Yellow(token.Kind()), - scopesFmt, + valueFmt, + createTimeFmt, ) } diff --git a/commands/bridge_token_add.go b/commands/bridge_token_add.go index 7b7a8964..58e9f472 100644 --- a/commands/bridge_token_add.go +++ b/commands/bridge_token_add.go @@ -8,17 +8,17 @@ import ( ) var ( - bridgeToken core.Token + bridgeTokenValue string + bridgeTokenTarget string ) func runBridgeTokenAdd(cmd *cobra.Command, args []string) error { - _ = bridgeToken.Id() // TODO: a better design to avoid doing this - - if err := bridgeToken.Validate(); err != nil { + token := core.NewToken(bridgeTokenValue, bridgeTokenTarget) + if err := token.Validate(); err != nil { return errors.Wrap(err, "invalid token") } - return core.StoreToken(repo, &bridgeToken) + return core.StoreToken(repo, token) } var bridgeTokenAddCmd = &cobra.Command{ @@ -31,9 +31,7 @@ var bridgeTokenAddCmd = &cobra.Command{ func init() { bridgeTokenCmd.AddCommand(bridgeTokenAddCmd) - bridgeTokenAddCmd.Flags().BoolVarP(&bridgeToken.Global, "global", "g", false, "") - bridgeTokenAddCmd.Flags().StringVarP(&bridgeToken.Value, "value", "v", "", "") - bridgeTokenAddCmd.Flags().StringVarP(&bridgeToken.Target, "target", "t", "", "") - bridgeTokenAddCmd.Flags().StringArrayVarP(&bridgeToken.Scopes, "scopes", "s", []string{}, "") + bridgeTokenAddCmd.Flags().StringVarP(&bridgeTokenValue, "value", "v", "", "") + bridgeTokenAddCmd.Flags().StringVarP(&bridgeTokenTarget, "target", "t", "", "") bridgeTokenAddCmd.Flags().SortFlags = false } diff --git a/commands/bridge_token_rm.go b/commands/bridge_token_rm.go index 29fdb4f2..7296f95a 100644 --- a/commands/bridge_token_rm.go +++ b/commands/bridge_token_rm.go @@ -7,13 +7,7 @@ import ( ) func runBridgeTokenRm(cmd *cobra.Command, args []string) error { - err := core.RemoveToken(repo, args[0]) - if err == nil { - return nil - } - - err = core.RemoveGlobalToken(repo, args[0]) - return err + return core.RemoveToken(repo, args[0]) } var bridgeTokenRmCmd = &cobra.Command{ -- cgit From 45653bd31d9ec91123ee42803cd5c46b43d18528 Mon Sep 17 00:00:00 2001 From: amine Date: Fri, 8 Nov 2019 14:55:27 +0100 Subject: token: regenerate documentation and fix imports --- bridge/core/token.go | 2 +- doc/man/git-bug-bridge-token-add.1 | 6 ------ doc/md/git-bug_bridge_token_add.md | 8 +++----- misc/bash_completion/git-bug | 7 ------- misc/powershell_completion/git-bug | 4 ---- misc/zsh_completion/git-bug | 4 +--- 6 files changed, 5 insertions(+), 26 deletions(-) diff --git a/bridge/core/token.go b/bridge/core/token.go index 09294e49..9f06e73c 100644 --- a/bridge/core/token.go +++ b/bridge/core/token.go @@ -8,9 +8,9 @@ import ( "strings" "time" - "github.com/MichaelMure/git-bug/entity" "github.com/araddon/dateparse" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/repository" ) diff --git a/doc/man/git-bug-bridge-token-add.1 b/doc/man/git-bug-bridge-token-add.1 index 1eb5bb20..7ce07b1c 100644 --- a/doc/man/git-bug-bridge-token-add.1 +++ b/doc/man/git-bug-bridge-token-add.1 @@ -19,18 +19,12 @@ Create and store a new token .SH OPTIONS -.PP -\fB\-g\fP, \fB\-\-global\fP[=false] - .PP \fB\-v\fP, \fB\-\-value\fP="" .PP \fB\-t\fP, \fB\-\-target\fP="" -.PP -\fB\-s\fP, \fB\-\-scopes\fP=[] - .PP \fB\-h\fP, \fB\-\-help\fP[=false] help for add diff --git a/doc/md/git-bug_bridge_token_add.md b/doc/md/git-bug_bridge_token_add.md index 6ef705d0..f372a06c 100644 --- a/doc/md/git-bug_bridge_token_add.md +++ b/doc/md/git-bug_bridge_token_add.md @@ -13,11 +13,9 @@ git-bug bridge token add [flags] ### Options ``` - -g, --global - -v, --value string - -t, --target string - -s, --scopes stringArray - -h, --help help for add + -v, --value string + -t, --target string + -h, --help help for add ``` ### SEE ALSO diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug index 9c719949..e6a19626 100644 --- a/misc/bash_completion/git-bug +++ b/misc/bash_completion/git-bug @@ -414,9 +414,6 @@ _git-bug_bridge_token_add() flags_with_completion=() flags_completion=() - flags+=("--global") - flags+=("-g") - local_nonpersistent_flags+=("--global") flags+=("--value=") two_word_flags+=("--value") two_word_flags+=("-v") @@ -425,10 +422,6 @@ _git-bug_bridge_token_add() two_word_flags+=("--target") two_word_flags+=("-t") local_nonpersistent_flags+=("--target=") - flags+=("--scopes=") - two_word_flags+=("--scopes") - two_word_flags+=("-s") - local_nonpersistent_flags+=("--scopes=") must_have_one_flag=() must_have_one_noun=() diff --git a/misc/powershell_completion/git-bug b/misc/powershell_completion/git-bug index d92bc04b..99265bbb 100644 --- a/misc/powershell_completion/git-bug +++ b/misc/powershell_completion/git-bug @@ -94,14 +94,10 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock { break } 'git-bug;bridge;token;add' { - [CompletionResult]::new('-g', 'g', [CompletionResultType]::ParameterName, '') - [CompletionResult]::new('--global', 'global', [CompletionResultType]::ParameterName, '') [CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, '') [CompletionResult]::new('--value', 'value', [CompletionResultType]::ParameterName, '') [CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, '') [CompletionResult]::new('--target', 'target', [CompletionResultType]::ParameterName, '') - [CompletionResult]::new('-s', 's', [CompletionResultType]::ParameterName, '') - [CompletionResult]::new('--scopes', 'scopes', [CompletionResultType]::ParameterName, '') break } 'git-bug;bridge;token;rm' { diff --git a/misc/zsh_completion/git-bug b/misc/zsh_completion/git-bug index d9da4ac2..e8c48cb6 100644 --- a/misc/zsh_completion/git-bug +++ b/misc/zsh_completion/git-bug @@ -200,10 +200,8 @@ function _git-bug_bridge_token { function _git-bug_bridge_token_add { _arguments \ - '(-g --global)'{-g,--global}'[]' \ '(-v --value)'{-v,--value}'[]:' \ - '(-t --target)'{-t,--target}'[]:' \ - '(*-s *--scopes)'{\*-s,\*--scopes}'[]:' + '(-t --target)'{-t,--target}'[]:' } function _git-bug_bridge_token_rm { -- cgit From e2445edcb99ed0aa7fcd40fe7484d71e73367334 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 10 Nov 2019 14:46:55 +0100 Subject: bridge: various improvement on the global token PR --- bridge/core/bridge.go | 6 +++ bridge/core/token.go | 108 +++++++++++++++++++++---------------- commands/bridge_token.go | 26 ++------- commands/bridge_token_add.go | 51 +++++++++++++++--- commands/bridge_token_rm.go | 15 +++++- doc/man/git-bug-bridge-token-add.1 | 8 ++- doc/man/git-bug-bridge-token.1 | 10 +--- doc/md/git-bug_bridge.md | 2 +- doc/md/git-bug_bridge_token.md | 10 ++-- doc/md/git-bug_bridge_token_add.md | 9 ++-- doc/md/git-bug_bridge_token_rm.md | 2 +- entity/id.go | 18 +++++++ misc/bash_completion/git-bug | 10 ---- misc/powershell_completion/git-bug | 14 ++--- misc/zsh_completion/git-bug | 9 ++-- repository/config.go | 2 +- repository/config_git.go | 2 +- 17 files changed, 172 insertions(+), 130 deletions(-) diff --git a/bridge/core/bridge.go b/bridge/core/bridge.go index ddf041f1..e419ed77 100644 --- a/bridge/core/bridge.go +++ b/bridge/core/bridge.go @@ -71,6 +71,12 @@ func Targets() []string { return result } +// TargetExist return true if the given target has a bridge implementation +func TargetExist(target string) bool { + _, ok := bridgeImpl[target] + return ok +} + // Instantiate a new Bridge for a repo, from the given target and name func NewBridge(repo *cache.RepoCache, target string, name string) (*Bridge, error) { implType, ok := bridgeImpl[target] diff --git a/bridge/core/token.go b/bridge/core/token.go index 9f06e73c..b9d68c0b 100644 --- a/bridge/core/token.go +++ b/bridge/core/token.go @@ -2,14 +2,13 @@ package core import ( "crypto/sha256" + "errors" "fmt" "regexp" - "strconv" + "sort" "strings" "time" - "github.com/araddon/dateparse" - "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/repository" ) @@ -21,9 +20,14 @@ const ( tokenCreateTimeKey = "createtime" ) +var ErrTokenNotExist = errors.New("token doesn't exist") + +func NewErrMultipleMatchToken(matching []entity.Id) *entity.ErrMultipleMatch { + return entity.NewErrMultipleMatch("token", matching) +} + // Token holds an API access token data type Token struct { - ID entity.Id Value string Target string CreateTime time.Time @@ -31,86 +35,96 @@ type Token struct { // NewToken instantiate a new token func NewToken(value, target string) *Token { - token := &Token{ + return &Token{ Value: value, Target: target, CreateTime: time.Now(), } - - token.ID = entity.Id(hashToken(token)) - return token } -func hashToken(token *Token) string { - sum := sha256.Sum256([]byte(token.Value)) - return fmt.Sprintf("%x", sum) +func (t *Token) ID() entity.Id { + sum := sha256.Sum256([]byte(t.Value)) + return entity.Id(fmt.Sprintf("%x", sum)) } // Validate ensure token important fields are valid func (t *Token) Validate() error { - if t.ID == "" { - return fmt.Errorf("missing id") - } if t.Value == "" { return fmt.Errorf("missing value") } if t.Target == "" { return fmt.Errorf("missing target") } - if t.CreateTime.Equal(time.Time{}) { + if t.CreateTime.IsZero() { return fmt.Errorf("missing creation time") } - if _, ok := bridgeImpl[t.Target]; !ok { + if !TargetExist(t.Target) { return fmt.Errorf("unknown target") } return nil } -// LoadToken loads a token from repo config -func LoadToken(repo repository.RepoCommon, id string) (*Token, error) { +// LoadToken loads a token from the repo config +func LoadToken(repo repository.RepoCommon, id entity.Id) (*Token, error) { keyPrefix := fmt.Sprintf("git-bug.token.%s.", id) // read token config pairs - configs, err := repo.GlobalConfig().ReadAll(keyPrefix) + rawconfigs, err := repo.GlobalConfig().ReadAll(keyPrefix) if err != nil { - return nil, err + // Not exactly right due to the limitation of ReadAll() + return nil, ErrTokenNotExist } // trim key prefix - for key, value := range configs { - delete(configs, key) + configs := make(map[string]string) + for key, value := range rawconfigs { newKey := strings.TrimPrefix(key, keyPrefix) configs[newKey] = value } - token := &Token{ID: entity.Id(id)} + token := &Token{} + + token.Value = configs[tokenValueKey] + token.Target = configs[tokenTargetKey] + if createTime, ok := configs[tokenCreateTimeKey]; ok { + if t, err := repository.ParseTimestamp(createTime); err == nil { + token.CreateTime = t + } + } + + return token, nil +} - var ok bool - token.Value, ok = configs[tokenValueKey] - if !ok { - return nil, fmt.Errorf("empty token value") +// LoadTokenPrefix load a token from the repo config with a prefix +func LoadTokenPrefix(repo repository.RepoCommon, prefix string) (*Token, error) { + tokens, err := ListTokens(repo) + if err != nil { + return nil, err } - token.Target, ok = configs[tokenTargetKey] - if !ok { - return nil, fmt.Errorf("empty token key") + // preallocate but empty + matching := make([]entity.Id, 0, 5) + + for _, id := range tokens { + if id.HasPrefix(prefix) { + matching = append(matching, id) + } } - createTime, ok := configs[tokenCreateTimeKey] - if !ok { - return nil, fmt.Errorf("missing createtime key") + if len(matching) > 1 { + return nil, NewErrMultipleMatchToken(matching) } - token.CreateTime, err = dateparse.ParseLocal(createTime) - if err != nil { - return nil, err + if len(matching) == 0 { + return nil, ErrTokenNotExist } - return token, nil + + return LoadToken(repo, matching[0]) } // ListTokens return a map representing the stored tokens in the repo config and global config // along with their type (global: true, local:false) -func ListTokens(repo repository.RepoCommon) ([]string, error) { +func ListTokens(repo repository.RepoCommon) ([]entity.Id, error) { configs, err := repo.GlobalConfig().ReadAll(tokenConfigKeyPrefix + ".") if err != nil { return nil, err @@ -133,36 +147,36 @@ func ListTokens(repo repository.RepoCommon) ([]string, error) { set[res[1]] = nil } - result := make([]string, len(set)) - i := 0 + result := make([]entity.Id, 0, len(set)) for key := range set { - result[i] = key - i++ + result = append(result, entity.Id(key)) } + sort.Sort(entity.Alphabetical(result)) + return result, nil } // StoreToken stores a token in the repo config func StoreToken(repo repository.RepoCommon, token *Token) error { - storeValueKey := fmt.Sprintf("git-bug.token.%s.%s", token.ID.String(), tokenValueKey) + storeValueKey := fmt.Sprintf("git-bug.token.%s.%s", token.ID().String(), tokenValueKey) err := repo.GlobalConfig().StoreString(storeValueKey, token.Value) if err != nil { return err } - storeTargetKey := fmt.Sprintf("git-bug.token.%s.%s", token.ID.String(), tokenTargetKey) + storeTargetKey := fmt.Sprintf("git-bug.token.%s.%s", token.ID().String(), tokenTargetKey) err = repo.GlobalConfig().StoreString(storeTargetKey, token.Target) if err != nil { return err } - createTimeKey := fmt.Sprintf("git-bug.token.%s.%s", token.ID.String(), tokenCreateTimeKey) - return repo.GlobalConfig().StoreString(createTimeKey, strconv.Itoa(int(token.CreateTime.Unix()))) + createTimeKey := fmt.Sprintf("git-bug.token.%s.%s", token.ID().String(), tokenCreateTimeKey) + return repo.GlobalConfig().StoreTimestamp(createTimeKey, token.CreateTime) } // RemoveToken removes a token from the repo config -func RemoveToken(repo repository.RepoCommon, id string) error { +func RemoveToken(repo repository.RepoCommon, id entity.Id) error { keyPrefix := fmt.Sprintf("git-bug.token.%s", id) return repo.GlobalConfig().RemoveAll(keyPrefix) } diff --git a/commands/bridge_token.go b/commands/bridge_token.go index 7467691e..b9e2d49f 100644 --- a/commands/bridge_token.go +++ b/commands/bridge_token.go @@ -6,27 +6,14 @@ import ( "github.com/spf13/cobra" - "github.com/MichaelMure/git-bug/bridge/core" - "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/util/colors" - "github.com/MichaelMure/git-bug/util/interrupt" text "github.com/MichaelMure/go-term-text" -) -var ( - bridgeTokenLocal bool - bridgeTokenGlobal bool + "github.com/MichaelMure/git-bug/bridge/core" + "github.com/MichaelMure/git-bug/util/colors" ) func runTokenBridge(cmd *cobra.Command, args []string) error { - backend, err := cache.NewRepoCache(repo) - if err != nil { - return err - } - defer backend.Close() - interrupt.RegisterCleaner(backend.Close) - - tokens, err := core.ListTokens(backend) + tokens, err := core.ListTokens(repo) if err != nil { return err } @@ -43,13 +30,12 @@ func runTokenBridge(cmd *cobra.Command, args []string) error { } func printToken(token *core.Token) { - idFmt := text.LeftPadMaxLine(token.ID.Human(), 7, 0) valueFmt := text.LeftPadMaxLine(token.Value, 15, 0) targetFmt := text.LeftPadMaxLine(token.Target, 7, 0) createTimeFmt := text.LeftPadMaxLine(token.CreateTime.Format(time.RFC822), 20, 0) fmt.Printf("%s %s %s %s\n", - idFmt, + token.ID().Human(), colors.Magenta(targetFmt), valueFmt, createTimeFmt, @@ -58,7 +44,7 @@ func printToken(token *core.Token) { var bridgeTokenCmd = &cobra.Command{ Use: "token", - Short: "List all stored tokens.", + Short: "List all known tokens.", PreRunE: loadRepo, RunE: runTokenBridge, Args: cobra.NoArgs, @@ -66,7 +52,5 @@ var bridgeTokenCmd = &cobra.Command{ func init() { bridgeCmd.AddCommand(bridgeTokenCmd) - bridgeTokenCmd.Flags().BoolVarP(&bridgeTokenLocal, "local", "l", false, "") - bridgeTokenCmd.Flags().BoolVarP(&bridgeTokenGlobal, "global", "g", false, "") bridgeTokenCmd.Flags().SortFlags = false } diff --git a/commands/bridge_token_add.go b/commands/bridge_token_add.go index 58e9f472..d2c697fa 100644 --- a/commands/bridge_token_add.go +++ b/commands/bridge_token_add.go @@ -1,37 +1,74 @@ package commands import ( + "bufio" + "fmt" + "os" + "strings" + + "github.com/mattn/go-isatty" "github.com/pkg/errors" "github.com/spf13/cobra" + "github.com/MichaelMure/git-bug/bridge" "github.com/MichaelMure/git-bug/bridge/core" ) var ( - bridgeTokenValue string bridgeTokenTarget string ) func runBridgeTokenAdd(cmd *cobra.Command, args []string) error { - token := core.NewToken(bridgeTokenValue, bridgeTokenTarget) + var value string + + if bridgeTokenTarget == "" { + return fmt.Errorf("token target is required") + } + + if !core.TargetExist(bridgeTokenTarget) { + return fmt.Errorf("unknown target") + } + + if len(args) == 1 { + value = args[0] + } else { + // Read from Stdin + if isatty.IsTerminal(os.Stdin.Fd()) { + fmt.Println("Enter the token:") + } + reader := bufio.NewReader(os.Stdin) + raw, err := reader.ReadString('\n') + if err != nil { + return fmt.Errorf("reading from stdin: %v", err) + } + value = strings.TrimSuffix(raw, "\n") + } + + token := core.NewToken(value, bridgeTokenTarget) if err := token.Validate(); err != nil { return errors.Wrap(err, "invalid token") } - return core.StoreToken(repo, token) + err := core.StoreToken(repo, token) + if err != nil { + return err + } + + fmt.Printf("token %s added\n", token.ID()) + return nil } var bridgeTokenAddCmd = &cobra.Command{ Use: "add", - Short: "Create and store a new token", + Short: "Store a new token", PreRunE: loadRepo, RunE: runBridgeTokenAdd, - Args: cobra.NoArgs, + Args: cobra.MaximumNArgs(1), } func init() { bridgeTokenCmd.AddCommand(bridgeTokenAddCmd) - bridgeTokenAddCmd.Flags().StringVarP(&bridgeTokenValue, "value", "v", "", "") - bridgeTokenAddCmd.Flags().StringVarP(&bridgeTokenTarget, "target", "t", "", "") + bridgeTokenAddCmd.Flags().StringVarP(&bridgeTokenTarget, "target", "t", "", + fmt.Sprintf("The target of the bridge. Valid values are [%s]", strings.Join(bridge.Targets(), ","))) bridgeTokenAddCmd.Flags().SortFlags = false } diff --git a/commands/bridge_token_rm.go b/commands/bridge_token_rm.go index 7296f95a..1f4ca4e8 100644 --- a/commands/bridge_token_rm.go +++ b/commands/bridge_token_rm.go @@ -1,13 +1,26 @@ package commands import ( + "fmt" + "github.com/spf13/cobra" "github.com/MichaelMure/git-bug/bridge/core" ) func runBridgeTokenRm(cmd *cobra.Command, args []string) error { - return core.RemoveToken(repo, args[0]) + token, err := core.LoadTokenPrefix(repo, args[0]) + if err != nil { + return err + } + + err = core.RemoveToken(repo, token.ID()) + if err != nil { + return err + } + + fmt.Printf("token %s removed\n", token.ID()) + return nil } var bridgeTokenRmCmd = &cobra.Command{ diff --git a/doc/man/git-bug-bridge-token-add.1 b/doc/man/git-bug-bridge-token-add.1 index 7ce07b1c..9b8a0db8 100644 --- a/doc/man/git-bug-bridge-token-add.1 +++ b/doc/man/git-bug-bridge-token-add.1 @@ -5,7 +5,7 @@ .SH NAME .PP -git\-bug\-bridge\-token\-add \- Create and store a new token +git\-bug\-bridge\-token\-add \- Store a new token .SH SYNOPSIS @@ -15,15 +15,13 @@ git\-bug\-bridge\-token\-add \- Create and store a new token .SH DESCRIPTION .PP -Create and store a new token +Store a new token .SH OPTIONS -.PP -\fB\-v\fP, \fB\-\-value\fP="" - .PP \fB\-t\fP, \fB\-\-target\fP="" + The target of the bridge. Valid values are [github,gitlab,launchpad\-preview] .PP \fB\-h\fP, \fB\-\-help\fP[=false] diff --git a/doc/man/git-bug-bridge-token.1 b/doc/man/git-bug-bridge-token.1 index d97c8e33..d377556f 100644 --- a/doc/man/git-bug-bridge-token.1 +++ b/doc/man/git-bug-bridge-token.1 @@ -5,7 +5,7 @@ .SH NAME .PP -git\-bug\-bridge\-token \- List all stored tokens. +git\-bug\-bridge\-token \- List all known tokens. .SH SYNOPSIS @@ -15,16 +15,10 @@ git\-bug\-bridge\-token \- List all stored tokens. .SH DESCRIPTION .PP -List all stored tokens. +List all known tokens. .SH OPTIONS -.PP -\fB\-l\fP, \fB\-\-local\fP[=false] - -.PP -\fB\-g\fP, \fB\-\-global\fP[=false] - .PP \fB\-h\fP, \fB\-\-help\fP[=false] help for token diff --git a/doc/md/git-bug_bridge.md b/doc/md/git-bug_bridge.md index a965074d..073d23ff 100644 --- a/doc/md/git-bug_bridge.md +++ b/doc/md/git-bug_bridge.md @@ -23,5 +23,5 @@ git-bug bridge [flags] * [git-bug bridge pull](git-bug_bridge_pull.md) - Pull updates. * [git-bug bridge push](git-bug_bridge_push.md) - Push updates. * [git-bug bridge rm](git-bug_bridge_rm.md) - Delete a configured bridge. -* [git-bug bridge token](git-bug_bridge_token.md) - List all stored tokens. +* [git-bug bridge token](git-bug_bridge_token.md) - List all known tokens. diff --git a/doc/md/git-bug_bridge_token.md b/doc/md/git-bug_bridge_token.md index 5e6baa26..e263e291 100644 --- a/doc/md/git-bug_bridge_token.md +++ b/doc/md/git-bug_bridge_token.md @@ -1,10 +1,10 @@ ## git-bug bridge token -List all stored tokens. +List all known tokens. ### Synopsis -List all stored tokens. +List all known tokens. ``` git-bug bridge token [flags] @@ -13,14 +13,12 @@ git-bug bridge token [flags] ### Options ``` - -l, --local - -g, --global - -h, --help help for token + -h, --help help for token ``` ### SEE ALSO * [git-bug bridge](git-bug_bridge.md) - Configure and use bridges to other bug trackers. -* [git-bug bridge token add](git-bug_bridge_token_add.md) - Create and store a new token +* [git-bug bridge token add](git-bug_bridge_token_add.md) - Store a new token * [git-bug bridge token rm](git-bug_bridge_token_rm.md) - Remove token by Id. diff --git a/doc/md/git-bug_bridge_token_add.md b/doc/md/git-bug_bridge_token_add.md index f372a06c..1c0e5bbc 100644 --- a/doc/md/git-bug_bridge_token_add.md +++ b/doc/md/git-bug_bridge_token_add.md @@ -1,10 +1,10 @@ ## git-bug bridge token add -Create and store a new token +Store a new token ### Synopsis -Create and store a new token +Store a new token ``` git-bug bridge token add [flags] @@ -13,12 +13,11 @@ git-bug bridge token add [flags] ### Options ``` - -v, --value string - -t, --target string + -t, --target string The target of the bridge. Valid values are [github,gitlab,launchpad-preview] -h, --help help for add ``` ### SEE ALSO -* [git-bug bridge token](git-bug_bridge_token.md) - List all stored tokens. +* [git-bug bridge token](git-bug_bridge_token.md) - List all known tokens. diff --git a/doc/md/git-bug_bridge_token_rm.md b/doc/md/git-bug_bridge_token_rm.md index 52417a9c..f8c5fcc2 100644 --- a/doc/md/git-bug_bridge_token_rm.md +++ b/doc/md/git-bug_bridge_token_rm.md @@ -18,5 +18,5 @@ git-bug bridge token rm [flags] ### SEE ALSO -* [git-bug bridge token](git-bug_bridge_token.md) - List all stored tokens. +* [git-bug bridge token](git-bug_bridge_token.md) - List all known tokens. diff --git a/entity/id.go b/entity/id.go index 7ff6b223..1b78aacd 100644 --- a/entity/id.go +++ b/entity/id.go @@ -65,3 +65,21 @@ func (i Id) Validate() error { } return nil } + +/* + * Sorting + */ + +type Alphabetical []Id + +func (a Alphabetical) Len() int { + return len(a) +} + +func (a Alphabetical) Less(i, j int) bool { + return a[i] < a[j] +} + +func (a Alphabetical) Swap(i, j int) { + a[i], a[j] = a[j], a[i] +} diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug index e6a19626..28924d1c 100644 --- a/misc/bash_completion/git-bug +++ b/misc/bash_completion/git-bug @@ -414,10 +414,6 @@ _git-bug_bridge_token_add() flags_with_completion=() flags_completion=() - flags+=("--value=") - two_word_flags+=("--value") - two_word_flags+=("-v") - local_nonpersistent_flags+=("--value=") flags+=("--target=") two_word_flags+=("--target") two_word_flags+=("-t") @@ -464,12 +460,6 @@ _git-bug_bridge_token() flags_with_completion=() flags_completion=() - flags+=("--local") - flags+=("-l") - local_nonpersistent_flags+=("--local") - flags+=("--global") - flags+=("-g") - local_nonpersistent_flags+=("--global") must_have_one_flag=() must_have_one_noun=() diff --git a/misc/powershell_completion/git-bug b/misc/powershell_completion/git-bug index 99265bbb..094fa254 100644 --- a/misc/powershell_completion/git-bug +++ b/misc/powershell_completion/git-bug @@ -52,7 +52,7 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock { [CompletionResult]::new('pull', 'pull', [CompletionResultType]::ParameterValue, 'Pull updates.') [CompletionResult]::new('push', 'push', [CompletionResultType]::ParameterValue, 'Push updates.') [CompletionResult]::new('rm', 'rm', [CompletionResultType]::ParameterValue, 'Delete a configured bridge.') - [CompletionResult]::new('token', 'token', [CompletionResultType]::ParameterValue, 'List all stored tokens.') + [CompletionResult]::new('token', 'token', [CompletionResultType]::ParameterValue, 'List all known tokens.') break } 'git-bug;bridge;configure' { @@ -85,19 +85,13 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock { break } 'git-bug;bridge;token' { - [CompletionResult]::new('-l', 'l', [CompletionResultType]::ParameterName, '') - [CompletionResult]::new('--local', 'local', [CompletionResultType]::ParameterName, '') - [CompletionResult]::new('-g', 'g', [CompletionResultType]::ParameterName, '') - [CompletionResult]::new('--global', 'global', [CompletionResultType]::ParameterName, '') - [CompletionResult]::new('add', 'add', [CompletionResultType]::ParameterValue, 'Create and store a new token') + [CompletionResult]::new('add', 'add', [CompletionResultType]::ParameterValue, 'Store a new token') [CompletionResult]::new('rm', 'rm', [CompletionResultType]::ParameterValue, 'Remove token by Id.') break } 'git-bug;bridge;token;add' { - [CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, '') - [CompletionResult]::new('--value', 'value', [CompletionResultType]::ParameterName, '') - [CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, '') - [CompletionResult]::new('--target', 'target', [CompletionResultType]::ParameterName, '') + [CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, 'The target of the bridge. Valid values are [github,gitlab,launchpad-preview]') + [CompletionResult]::new('--target', 'target', [CompletionResultType]::ParameterName, 'The target of the bridge. Valid values are [github,gitlab,launchpad-preview]') break } 'git-bug;bridge;token;rm' { diff --git a/misc/zsh_completion/git-bug b/misc/zsh_completion/git-bug index e8c48cb6..7f5f6231 100644 --- a/misc/zsh_completion/git-bug +++ b/misc/zsh_completion/git-bug @@ -118,7 +118,7 @@ function _git-bug_bridge { "pull:Pull updates." "push:Push updates." "rm:Delete a configured bridge." - "token:List all stored tokens." + "token:List all known tokens." ) _describe "command" commands ;; @@ -173,15 +173,13 @@ function _git-bug_bridge_token { local -a commands _arguments -C \ - '(-l --local)'{-l,--local}'[]' \ - '(-g --global)'{-g,--global}'[]' \ "1: :->cmnds" \ "*::arg:->args" case $state in cmnds) commands=( - "add:Create and store a new token" + "add:Store a new token" "rm:Remove token by Id." ) _describe "command" commands @@ -200,8 +198,7 @@ function _git-bug_bridge_token { function _git-bug_bridge_token_add { _arguments \ - '(-v --value)'{-v,--value}'[]:' \ - '(-t --target)'{-t,--target}'[]:' + '(-t --target)'{-t,--target}'[The target of the bridge. Valid values are [github,gitlab,launchpad-preview]]:' } function _git-bug_bridge_token_rm { diff --git a/repository/config.go b/repository/config.go index d72e7b4e..4fa5c69b 100644 --- a/repository/config.go +++ b/repository/config.go @@ -38,7 +38,7 @@ type Config interface { RemoveAll(keyPrefix string) error } -func parseTimestamp(s string) (time.Time, error) { +func ParseTimestamp(s string) (time.Time, error) { timestamp, err := strconv.Atoi(s) if err != nil { return time.Time{}, err diff --git a/repository/config_git.go b/repository/config_git.go index 63ca2457..cff82afb 100644 --- a/repository/config_git.go +++ b/repository/config_git.go @@ -116,7 +116,7 @@ func (gc *gitConfig) ReadTimestamp(key string) (time.Time, error) { if err != nil { return time.Time{}, err } - return parseTimestamp(value) + return ParseTimestamp(value) } func (gc *gitConfig) rmSection(keyPrefix string) error { -- cgit From f8cf3fea035d7f0ad0287166c3a5016777acf5ad Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 10 Nov 2019 15:50:56 +0100 Subject: cli: add bridge token show --- bridge/core/token.go | 2 +- commands/bridge_token_rm.go | 4 ++-- commands/bridge_token_show.go | 36 ++++++++++++++++++++++++++++++++++++ doc/man/git-bug-bridge-token-rm.1 | 6 +++--- doc/man/git-bug-bridge-token-show.1 | 29 +++++++++++++++++++++++++++++ doc/man/git-bug-bridge-token.1 | 2 +- doc/md/git-bug_bridge_token.md | 3 ++- doc/md/git-bug_bridge_token_rm.md | 6 +++--- doc/md/git-bug_bridge_token_show.md | 22 ++++++++++++++++++++++ misc/bash_completion/git-bug | 21 +++++++++++++++++++++ misc/powershell_completion/git-bug | 6 +++++- misc/zsh_completion/git-bug | 10 +++++++++- 12 files changed, 134 insertions(+), 13 deletions(-) create mode 100644 commands/bridge_token_show.go create mode 100644 doc/man/git-bug-bridge-token-show.1 create mode 100644 doc/md/git-bug_bridge_token_show.md diff --git a/bridge/core/token.go b/bridge/core/token.go index b9d68c0b..2ceabca2 100644 --- a/bridge/core/token.go +++ b/bridge/core/token.go @@ -55,7 +55,7 @@ func (t *Token) Validate() error { if t.Target == "" { return fmt.Errorf("missing target") } - if t.CreateTime.IsZero() { + if t.CreateTime.IsZero() || t.CreateTime.Equal(time.Time{}) { return fmt.Errorf("missing creation time") } if !TargetExist(t.Target) { diff --git a/commands/bridge_token_rm.go b/commands/bridge_token_rm.go index 1f4ca4e8..a73fbb91 100644 --- a/commands/bridge_token_rm.go +++ b/commands/bridge_token_rm.go @@ -24,8 +24,8 @@ func runBridgeTokenRm(cmd *cobra.Command, args []string) error { } var bridgeTokenRmCmd = &cobra.Command{ - Use: "rm", - Short: "Remove token by Id.", + Use: "rm ", + Short: "Remove a token.", PreRunE: loadRepo, RunE: runBridgeTokenRm, Args: cobra.ExactArgs(1), diff --git a/commands/bridge_token_show.go b/commands/bridge_token_show.go new file mode 100644 index 00000000..2d2e824d --- /dev/null +++ b/commands/bridge_token_show.go @@ -0,0 +1,36 @@ +package commands + +import ( + "fmt" + "time" + + "github.com/spf13/cobra" + + "github.com/MichaelMure/git-bug/bridge/core" +) + +func runBridgeTokenShow(cmd *cobra.Command, args []string) error { + token, err := core.LoadTokenPrefix(repo, args[0]) + if err != nil { + return err + } + + fmt.Printf("Id: %s\n", token.ID()) + fmt.Printf("Value: %s\n", token.Value) + fmt.Printf("Target: %s\n", token.Target) + fmt.Printf("Creation: %s\n", token.CreateTime.Format(time.RFC822)) + + return nil +} + +var bridgeTokenShowCmd = &cobra.Command{ + Use: "show", + Short: "Display a token.", + PreRunE: loadRepo, + RunE: runBridgeTokenShow, + Args: cobra.ExactArgs(1), +} + +func init() { + bridgeTokenCmd.AddCommand(bridgeTokenShowCmd) +} diff --git a/doc/man/git-bug-bridge-token-rm.1 b/doc/man/git-bug-bridge-token-rm.1 index 5c5a16a6..217d938d 100644 --- a/doc/man/git-bug-bridge-token-rm.1 +++ b/doc/man/git-bug-bridge-token-rm.1 @@ -5,17 +5,17 @@ .SH NAME .PP -git\-bug\-bridge\-token\-rm \- Remove token by Id. +git\-bug\-bridge\-token\-rm \- Remove a token. .SH SYNOPSIS .PP -\fBgit\-bug bridge token rm [flags]\fP +\fBgit\-bug bridge token rm [flags]\fP .SH DESCRIPTION .PP -Remove token by Id. +Remove a token. .SH OPTIONS diff --git a/doc/man/git-bug-bridge-token-show.1 b/doc/man/git-bug-bridge-token-show.1 new file mode 100644 index 00000000..f40b5024 --- /dev/null +++ b/doc/man/git-bug-bridge-token-show.1 @@ -0,0 +1,29 @@ +.TH "GIT-BUG" "1" "Apr 2019" "Generated from git-bug's source code" "" +.nh +.ad l + + +.SH NAME +.PP +git\-bug\-bridge\-token\-show \- Display a token. + + +.SH SYNOPSIS +.PP +\fBgit\-bug bridge token show [flags]\fP + + +.SH DESCRIPTION +.PP +Display a token. + + +.SH OPTIONS +.PP +\fB\-h\fP, \fB\-\-help\fP[=false] + help for show + + +.SH SEE ALSO +.PP +\fBgit\-bug\-bridge\-token(1)\fP diff --git a/doc/man/git-bug-bridge-token.1 b/doc/man/git-bug-bridge-token.1 index d377556f..f229bf76 100644 --- a/doc/man/git-bug-bridge-token.1 +++ b/doc/man/git-bug-bridge-token.1 @@ -26,4 +26,4 @@ List all known tokens. .SH SEE ALSO .PP -\fBgit\-bug\-bridge(1)\fP, \fBgit\-bug\-bridge\-token\-add(1)\fP, \fBgit\-bug\-bridge\-token\-rm(1)\fP +\fBgit\-bug\-bridge(1)\fP, \fBgit\-bug\-bridge\-token\-add(1)\fP, \fBgit\-bug\-bridge\-token\-rm(1)\fP, \fBgit\-bug\-bridge\-token\-show(1)\fP diff --git a/doc/md/git-bug_bridge_token.md b/doc/md/git-bug_bridge_token.md index e263e291..14663784 100644 --- a/doc/md/git-bug_bridge_token.md +++ b/doc/md/git-bug_bridge_token.md @@ -20,5 +20,6 @@ git-bug bridge token [flags] * [git-bug bridge](git-bug_bridge.md) - Configure and use bridges to other bug trackers. * [git-bug bridge token add](git-bug_bridge_token_add.md) - Store a new token -* [git-bug bridge token rm](git-bug_bridge_token_rm.md) - Remove token by Id. +* [git-bug bridge token rm](git-bug_bridge_token_rm.md) - Remove a token. +* [git-bug bridge token show](git-bug_bridge_token_show.md) - Display a token. diff --git a/doc/md/git-bug_bridge_token_rm.md b/doc/md/git-bug_bridge_token_rm.md index f8c5fcc2..534406f4 100644 --- a/doc/md/git-bug_bridge_token_rm.md +++ b/doc/md/git-bug_bridge_token_rm.md @@ -1,13 +1,13 @@ ## git-bug bridge token rm -Remove token by Id. +Remove a token. ### Synopsis -Remove token by Id. +Remove a token. ``` -git-bug bridge token rm [flags] +git-bug bridge token rm [flags] ``` ### Options diff --git a/doc/md/git-bug_bridge_token_show.md b/doc/md/git-bug_bridge_token_show.md new file mode 100644 index 00000000..80439617 --- /dev/null +++ b/doc/md/git-bug_bridge_token_show.md @@ -0,0 +1,22 @@ +## git-bug bridge token show + +Display a token. + +### Synopsis + +Display a token. + +``` +git-bug bridge token show [flags] +``` + +### Options + +``` + -h, --help help for show +``` + +### SEE ALSO + +* [git-bug bridge token](git-bug_bridge_token.md) - List all known tokens. + diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug index 28924d1c..e8126b8f 100644 --- a/misc/bash_completion/git-bug +++ b/misc/bash_completion/git-bug @@ -444,6 +444,26 @@ _git-bug_bridge_token_rm() noun_aliases=() } +_git-bug_bridge_token_show() +{ + last_command="git-bug_bridge_token_show" + + command_aliases=() + + commands=() + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() +} + _git-bug_bridge_token() { last_command="git-bug_bridge_token" @@ -453,6 +473,7 @@ _git-bug_bridge_token() commands=() commands+=("add") commands+=("rm") + commands+=("show") flags=() two_word_flags=() diff --git a/misc/powershell_completion/git-bug b/misc/powershell_completion/git-bug index 094fa254..6a7bf0c3 100644 --- a/misc/powershell_completion/git-bug +++ b/misc/powershell_completion/git-bug @@ -86,7 +86,8 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock { } 'git-bug;bridge;token' { [CompletionResult]::new('add', 'add', [CompletionResultType]::ParameterValue, 'Store a new token') - [CompletionResult]::new('rm', 'rm', [CompletionResultType]::ParameterValue, 'Remove token by Id.') + [CompletionResult]::new('rm', 'rm', [CompletionResultType]::ParameterValue, 'Remove a token.') + [CompletionResult]::new('show', 'show', [CompletionResultType]::ParameterValue, 'Display a token.') break } 'git-bug;bridge;token;add' { @@ -97,6 +98,9 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock { 'git-bug;bridge;token;rm' { break } + 'git-bug;bridge;token;show' { + break + } 'git-bug;commands' { [CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Output the command description as well as Markdown compatible comment') [CompletionResult]::new('--pretty', 'pretty', [CompletionResultType]::ParameterName, 'Output the command description as well as Markdown compatible comment') diff --git a/misc/zsh_completion/git-bug b/misc/zsh_completion/git-bug index 7f5f6231..f0ff7edf 100644 --- a/misc/zsh_completion/git-bug +++ b/misc/zsh_completion/git-bug @@ -180,7 +180,8 @@ function _git-bug_bridge_token { cmnds) commands=( "add:Store a new token" - "rm:Remove token by Id." + "rm:Remove a token." + "show:Display a token." ) _describe "command" commands ;; @@ -193,6 +194,9 @@ function _git-bug_bridge_token { rm) _git-bug_bridge_token_rm ;; + show) + _git-bug_bridge_token_show + ;; esac } @@ -205,6 +209,10 @@ function _git-bug_bridge_token_rm { _arguments } +function _git-bug_bridge_token_show { + _arguments +} + function _git-bug_commands { _arguments \ '(-p --pretty)'{-p,--pretty}'[Output the command description as well as Markdown compatible comment]' -- cgit From e0b15ee7644c20533156850e0be5a07597967450 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 10 Nov 2019 17:32:14 +0100 Subject: cli: rename "token" into "auth" --- commands/bridge_auth.go | 53 ++++++++++++++++++ commands/bridge_auth_add.go | 74 +++++++++++++++++++++++++ commands/bridge_auth_rm.go | 36 ++++++++++++ commands/bridge_auth_show.go | 37 +++++++++++++ commands/bridge_token.go | 56 ------------------- commands/bridge_token_add.go | 74 ------------------------- commands/bridge_token_rm.go | 36 ------------ commands/bridge_token_show.go | 36 ------------ doc/man/git-bug-bridge-auth-add-token.1 | 33 +++++++++++ doc/man/git-bug-bridge-auth-rm.1 | 29 ++++++++++ doc/man/git-bug-bridge-auth-show.1 | 29 ++++++++++ doc/man/git-bug-bridge-auth.1 | 29 ++++++++++ doc/man/git-bug-bridge-token-add.1 | 33 ----------- doc/man/git-bug-bridge-token-rm.1 | 29 ---------- doc/man/git-bug-bridge-token-show.1 | 29 ---------- doc/man/git-bug-bridge-token.1 | 29 ---------- doc/man/git-bug-bridge.1 | 2 +- doc/md/git-bug_bridge.md | 2 +- doc/md/git-bug_bridge_auth.md | 25 +++++++++ doc/md/git-bug_bridge_auth_add-token.md | 23 ++++++++ doc/md/git-bug_bridge_auth_rm.md | 22 ++++++++ doc/md/git-bug_bridge_auth_show.md | 22 ++++++++ doc/md/git-bug_bridge_token.md | 25 --------- doc/md/git-bug_bridge_token_add.md | 23 -------- doc/md/git-bug_bridge_token_rm.md | 22 -------- doc/md/git-bug_bridge_token_show.md | 22 -------- misc/bash_completion/git-bug | 98 ++++++++++++++++----------------- misc/powershell_completion/git-bug | 36 ++++++------ misc/zsh_completion/git-bug | 80 +++++++++++++-------------- 29 files changed, 521 insertions(+), 523 deletions(-) create mode 100644 commands/bridge_auth.go create mode 100644 commands/bridge_auth_add.go create mode 100644 commands/bridge_auth_rm.go create mode 100644 commands/bridge_auth_show.go delete mode 100644 commands/bridge_token.go delete mode 100644 commands/bridge_token_add.go delete mode 100644 commands/bridge_token_rm.go delete mode 100644 commands/bridge_token_show.go create mode 100644 doc/man/git-bug-bridge-auth-add-token.1 create mode 100644 doc/man/git-bug-bridge-auth-rm.1 create mode 100644 doc/man/git-bug-bridge-auth-show.1 create mode 100644 doc/man/git-bug-bridge-auth.1 delete mode 100644 doc/man/git-bug-bridge-token-add.1 delete mode 100644 doc/man/git-bug-bridge-token-rm.1 delete mode 100644 doc/man/git-bug-bridge-token-show.1 delete mode 100644 doc/man/git-bug-bridge-token.1 create mode 100644 doc/md/git-bug_bridge_auth.md create mode 100644 doc/md/git-bug_bridge_auth_add-token.md create mode 100644 doc/md/git-bug_bridge_auth_rm.md create mode 100644 doc/md/git-bug_bridge_auth_show.md delete mode 100644 doc/md/git-bug_bridge_token.md delete mode 100644 doc/md/git-bug_bridge_token_add.md delete mode 100644 doc/md/git-bug_bridge_token_rm.md delete mode 100644 doc/md/git-bug_bridge_token_show.md diff --git a/commands/bridge_auth.go b/commands/bridge_auth.go new file mode 100644 index 00000000..e7fce1bd --- /dev/null +++ b/commands/bridge_auth.go @@ -0,0 +1,53 @@ +package commands + +import ( + "fmt" + + "github.com/spf13/cobra" + + text "github.com/MichaelMure/go-term-text" + + "github.com/MichaelMure/git-bug/bridge/core" + "github.com/MichaelMure/git-bug/util/colors" +) + +func runBridgeAuth(cmd *cobra.Command, args []string) error { + tokens, err := core.ListTokens(repo) + if err != nil { + return err + } + + for _, token := range tokens { + token, err := core.LoadToken(repo, token) + if err != nil { + return err + } + printToken(token) + } + + return nil +} + +func printToken(token *core.Token) { + targetFmt := text.LeftPadMaxLine(token.Target, 10, 0) + + fmt.Printf("%s %s %s %s\n", + colors.Cyan(token.ID().Human()), + colors.Yellow(targetFmt), + colors.Magenta("token"), + token.Value, + ) +} + +var bridgeAuthCmd = &cobra.Command{ + Use: "auth", + Short: "List all known bridge authentication credentials.", + PreRunE: loadRepo, + RunE: runBridgeAuth, + Args: cobra.NoArgs, +} + +func init() { + bridgeCmd.AddCommand(bridgeAuthCmd) + bridgeAuthCmd.Flags().SortFlags = false +} diff --git a/commands/bridge_auth_add.go b/commands/bridge_auth_add.go new file mode 100644 index 00000000..ae2c4dbc --- /dev/null +++ b/commands/bridge_auth_add.go @@ -0,0 +1,74 @@ +package commands + +import ( + "bufio" + "fmt" + "os" + "strings" + + "github.com/mattn/go-isatty" + "github.com/pkg/errors" + "github.com/spf13/cobra" + + "github.com/MichaelMure/git-bug/bridge" + "github.com/MichaelMure/git-bug/bridge/core" +) + +var ( + bridgeAuthAddTokenTarget string +) + +func runBridgeTokenAdd(cmd *cobra.Command, args []string) error { + var value string + + if bridgeAuthAddTokenTarget == "" { + return fmt.Errorf("auth target is required") + } + + if !core.TargetExist(bridgeAuthAddTokenTarget) { + return fmt.Errorf("unknown target") + } + + if len(args) == 1 { + value = args[0] + } else { + // Read from Stdin + if isatty.IsTerminal(os.Stdin.Fd()) { + fmt.Println("Enter the token:") + } + reader := bufio.NewReader(os.Stdin) + raw, err := reader.ReadString('\n') + if err != nil { + return fmt.Errorf("reading from stdin: %v", err) + } + value = strings.TrimSuffix(raw, "\n") + } + + token := core.NewToken(value, bridgeAuthAddTokenTarget) + if err := token.Validate(); err != nil { + return errors.Wrap(err, "invalid token") + } + + err := core.StoreToken(repo, token) + if err != nil { + return err + } + + fmt.Printf("token %s added\n", token.ID()) + return nil +} + +var bridgeAuthAddTokenCmd = &cobra.Command{ + Use: "add-token []", + Short: "Store a new token", + PreRunE: loadRepo, + RunE: runBridgeTokenAdd, + Args: cobra.MaximumNArgs(1), +} + +func init() { + bridgeAuthCmd.AddCommand(bridgeAuthAddTokenCmd) + bridgeAuthAddTokenCmd.Flags().StringVarP(&bridgeAuthAddTokenTarget, "target", "t", "", + fmt.Sprintf("The target of the bridge. Valid values are [%s]", strings.Join(bridge.Targets(), ","))) + bridgeAuthAddTokenCmd.Flags().SortFlags = false +} diff --git a/commands/bridge_auth_rm.go b/commands/bridge_auth_rm.go new file mode 100644 index 00000000..b0b4d437 --- /dev/null +++ b/commands/bridge_auth_rm.go @@ -0,0 +1,36 @@ +package commands + +import ( + "fmt" + + "github.com/spf13/cobra" + + "github.com/MichaelMure/git-bug/bridge/core" +) + +func runBridgeAuthRm(cmd *cobra.Command, args []string) error { + token, err := core.LoadTokenPrefix(repo, args[0]) + if err != nil { + return err + } + + err = core.RemoveToken(repo, token.ID()) + if err != nil { + return err + } + + fmt.Printf("token %s removed\n", token.ID()) + return nil +} + +var bridgeAuthRmCmd = &cobra.Command{ + Use: "rm ", + Short: "Remove a credential.", + PreRunE: loadRepo, + RunE: runBridgeAuthRm, + Args: cobra.ExactArgs(1), +} + +func init() { + bridgeAuthCmd.AddCommand(bridgeAuthRmCmd) +} diff --git a/commands/bridge_auth_show.go b/commands/bridge_auth_show.go new file mode 100644 index 00000000..94141b93 --- /dev/null +++ b/commands/bridge_auth_show.go @@ -0,0 +1,37 @@ +package commands + +import ( + "fmt" + "time" + + "github.com/spf13/cobra" + + "github.com/MichaelMure/git-bug/bridge/core" +) + +func runBridgeAuthShow(cmd *cobra.Command, args []string) error { + token, err := core.LoadTokenPrefix(repo, args[0]) + if err != nil { + return err + } + + fmt.Printf("Id: %s\n", token.ID()) + fmt.Printf("Target: %s\n", token.Target) + fmt.Printf("Type: token\n") + fmt.Printf("Value: %s\n", token.Value) + fmt.Printf("Creation: %s\n", token.CreateTime.Format(time.RFC822)) + + return nil +} + +var bridgeAuthShowCmd = &cobra.Command{ + Use: "show", + Short: "Display an authentication credential.", + PreRunE: loadRepo, + RunE: runBridgeAuthShow, + Args: cobra.ExactArgs(1), +} + +func init() { + bridgeAuthCmd.AddCommand(bridgeAuthShowCmd) +} diff --git a/commands/bridge_token.go b/commands/bridge_token.go deleted file mode 100644 index b9e2d49f..00000000 --- a/commands/bridge_token.go +++ /dev/null @@ -1,56 +0,0 @@ -package commands - -import ( - "fmt" - "time" - - "github.com/spf13/cobra" - - text "github.com/MichaelMure/go-term-text" - - "github.com/MichaelMure/git-bug/bridge/core" - "github.com/MichaelMure/git-bug/util/colors" -) - -func runTokenBridge(cmd *cobra.Command, args []string) error { - tokens, err := core.ListTokens(repo) - if err != nil { - return err - } - - for _, token := range tokens { - token, err := core.LoadToken(repo, token) - if err != nil { - return err - } - printToken(token) - } - - return nil -} - -func printToken(token *core.Token) { - valueFmt := text.LeftPadMaxLine(token.Value, 15, 0) - targetFmt := text.LeftPadMaxLine(token.Target, 7, 0) - createTimeFmt := text.LeftPadMaxLine(token.CreateTime.Format(time.RFC822), 20, 0) - - fmt.Printf("%s %s %s %s\n", - token.ID().Human(), - colors.Magenta(targetFmt), - valueFmt, - createTimeFmt, - ) -} - -var bridgeTokenCmd = &cobra.Command{ - Use: "token", - Short: "List all known tokens.", - PreRunE: loadRepo, - RunE: runTokenBridge, - Args: cobra.NoArgs, -} - -func init() { - bridgeCmd.AddCommand(bridgeTokenCmd) - bridgeTokenCmd.Flags().SortFlags = false -} diff --git a/commands/bridge_token_add.go b/commands/bridge_token_add.go deleted file mode 100644 index d2c697fa..00000000 --- a/commands/bridge_token_add.go +++ /dev/null @@ -1,74 +0,0 @@ -package commands - -import ( - "bufio" - "fmt" - "os" - "strings" - - "github.com/mattn/go-isatty" - "github.com/pkg/errors" - "github.com/spf13/cobra" - - "github.com/MichaelMure/git-bug/bridge" - "github.com/MichaelMure/git-bug/bridge/core" -) - -var ( - bridgeTokenTarget string -) - -func runBridgeTokenAdd(cmd *cobra.Command, args []string) error { - var value string - - if bridgeTokenTarget == "" { - return fmt.Errorf("token target is required") - } - - if !core.TargetExist(bridgeTokenTarget) { - return fmt.Errorf("unknown target") - } - - if len(args) == 1 { - value = args[0] - } else { - // Read from Stdin - if isatty.IsTerminal(os.Stdin.Fd()) { - fmt.Println("Enter the token:") - } - reader := bufio.NewReader(os.Stdin) - raw, err := reader.ReadString('\n') - if err != nil { - return fmt.Errorf("reading from stdin: %v", err) - } - value = strings.TrimSuffix(raw, "\n") - } - - token := core.NewToken(value, bridgeTokenTarget) - if err := token.Validate(); err != nil { - return errors.Wrap(err, "invalid token") - } - - err := core.StoreToken(repo, token) - if err != nil { - return err - } - - fmt.Printf("token %s added\n", token.ID()) - return nil -} - -var bridgeTokenAddCmd = &cobra.Command{ - Use: "add", - Short: "Store a new token", - PreRunE: loadRepo, - RunE: runBridgeTokenAdd, - Args: cobra.MaximumNArgs(1), -} - -func init() { - bridgeTokenCmd.AddCommand(bridgeTokenAddCmd) - bridgeTokenAddCmd.Flags().StringVarP(&bridgeTokenTarget, "target", "t", "", - fmt.Sprintf("The target of the bridge. Valid values are [%s]", strings.Join(bridge.Targets(), ","))) - bridgeTokenAddCmd.Flags().SortFlags = false -} diff --git a/commands/bridge_token_rm.go b/commands/bridge_token_rm.go deleted file mode 100644 index a73fbb91..00000000 --- a/commands/bridge_token_rm.go +++ /dev/null @@ -1,36 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/spf13/cobra" - - "github.com/MichaelMure/git-bug/bridge/core" -) - -func runBridgeTokenRm(cmd *cobra.Command, args []string) error { - token, err := core.LoadTokenPrefix(repo, args[0]) - if err != nil { - return err - } - - err = core.RemoveToken(repo, token.ID()) - if err != nil { - return err - } - - fmt.Printf("token %s removed\n", token.ID()) - return nil -} - -var bridgeTokenRmCmd = &cobra.Command{ - Use: "rm ", - Short: "Remove a token.", - PreRunE: loadRepo, - RunE: runBridgeTokenRm, - Args: cobra.ExactArgs(1), -} - -func init() { - bridgeTokenCmd.AddCommand(bridgeTokenRmCmd) -} diff --git a/commands/bridge_token_show.go b/commands/bridge_token_show.go deleted file mode 100644 index 2d2e824d..00000000 --- a/commands/bridge_token_show.go +++ /dev/null @@ -1,36 +0,0 @@ -package commands - -import ( - "fmt" - "time" - - "github.com/spf13/cobra" - - "github.com/MichaelMure/git-bug/bridge/core" -) - -func runBridgeTokenShow(cmd *cobra.Command, args []string) error { - token, err := core.LoadTokenPrefix(repo, args[0]) - if err != nil { - return err - } - - fmt.Printf("Id: %s\n", token.ID()) - fmt.Printf("Value: %s\n", token.Value) - fmt.Printf("Target: %s\n", token.Target) - fmt.Printf("Creation: %s\n", token.CreateTime.Format(time.RFC822)) - - return nil -} - -var bridgeTokenShowCmd = &cobra.Command{ - Use: "show", - Short: "Display a token.", - PreRunE: loadRepo, - RunE: runBridgeTokenShow, - Args: cobra.ExactArgs(1), -} - -func init() { - bridgeTokenCmd.AddCommand(bridgeTokenShowCmd) -} diff --git a/doc/man/git-bug-bridge-auth-add-token.1 b/doc/man/git-bug-bridge-auth-add-token.1 new file mode 100644 index 00000000..a76ed793 --- /dev/null +++ b/doc/man/git-bug-bridge-auth-add-token.1 @@ -0,0 +1,33 @@ +.TH "GIT-BUG" "1" "Apr 2019" "Generated from git-bug's source code" "" +.nh +.ad l + + +.SH NAME +.PP +git\-bug\-bridge\-auth\-add\-token \- Store a new token + + +.SH SYNOPSIS +.PP +\fBgit\-bug bridge auth add\-token [] [flags]\fP + + +.SH DESCRIPTION +.PP +Store a new token + + +.SH OPTIONS +.PP +\fB\-t\fP, \fB\-\-target\fP="" + The target of the bridge. Valid values are [github,gitlab,launchpad\-preview] + +.PP +\fB\-h\fP, \fB\-\-help\fP[=false] + help for add\-token + + +.SH SEE ALSO +.PP +\fBgit\-bug\-bridge\-auth(1)\fP diff --git a/doc/man/git-bug-bridge-auth-rm.1 b/doc/man/git-bug-bridge-auth-rm.1 new file mode 100644 index 00000000..b0222b72 --- /dev/null +++ b/doc/man/git-bug-bridge-auth-rm.1 @@ -0,0 +1,29 @@ +.TH "GIT-BUG" "1" "Apr 2019" "Generated from git-bug's source code" "" +.nh +.ad l + + +.SH NAME +.PP +git\-bug\-bridge\-auth\-rm \- Remove a credential. + + +.SH SYNOPSIS +.PP +\fBgit\-bug bridge auth rm [flags]\fP + + +.SH DESCRIPTION +.PP +Remove a credential. + + +.SH OPTIONS +.PP +\fB\-h\fP, \fB\-\-help\fP[=false] + help for rm + + +.SH SEE ALSO +.PP +\fBgit\-bug\-bridge\-auth(1)\fP diff --git a/doc/man/git-bug-bridge-auth-show.1 b/doc/man/git-bug-bridge-auth-show.1 new file mode 100644 index 00000000..6e0d345c --- /dev/null +++ b/doc/man/git-bug-bridge-auth-show.1 @@ -0,0 +1,29 @@ +.TH "GIT-BUG" "1" "Apr 2019" "Generated from git-bug's source code" "" +.nh +.ad l + + +.SH NAME +.PP +git\-bug\-bridge\-auth\-show \- Display an authentication credential. + + +.SH SYNOPSIS +.PP +\fBgit\-bug bridge auth show [flags]\fP + + +.SH DESCRIPTION +.PP +Display an authentication credential. + + +.SH OPTIONS +.PP +\fB\-h\fP, \fB\-\-help\fP[=false] + help for show + + +.SH SEE ALSO +.PP +\fBgit\-bug\-bridge\-auth(1)\fP diff --git a/doc/man/git-bug-bridge-auth.1 b/doc/man/git-bug-bridge-auth.1 new file mode 100644 index 00000000..0e400c41 --- /dev/null +++ b/doc/man/git-bug-bridge-auth.1 @@ -0,0 +1,29 @@ +.TH "GIT-BUG" "1" "Apr 2019" "Generated from git-bug's source code" "" +.nh +.ad l + + +.SH NAME +.PP +git\-bug\-bridge\-auth \- List all known bridge authentication credentials. + + +.SH SYNOPSIS +.PP +\fBgit\-bug bridge auth [flags]\fP + + +.SH DESCRIPTION +.PP +List all known bridge authentication credentials. + + +.SH OPTIONS +.PP +\fB\-h\fP, \fB\-\-help\fP[=false] + help for auth + + +.SH SEE ALSO +.PP +\fBgit\-bug\-bridge(1)\fP, \fBgit\-bug\-bridge\-auth\-add\-token(1)\fP, \fBgit\-bug\-bridge\-auth\-rm(1)\fP, \fBgit\-bug\-bridge\-auth\-show(1)\fP diff --git a/doc/man/git-bug-bridge-token-add.1 b/doc/man/git-bug-bridge-token-add.1 deleted file mode 100644 index 9b8a0db8..00000000 --- a/doc/man/git-bug-bridge-token-add.1 +++ /dev/null @@ -1,33 +0,0 @@ -.TH "GIT-BUG" "1" "Apr 2019" "Generated from git-bug's source code" "" -.nh -.ad l - - -.SH NAME -.PP -git\-bug\-bridge\-token\-add \- Store a new token - - -.SH SYNOPSIS -.PP -\fBgit\-bug bridge token add [flags]\fP - - -.SH DESCRIPTION -.PP -Store a new token - - -.SH OPTIONS -.PP -\fB\-t\fP, \fB\-\-target\fP="" - The target of the bridge. Valid values are [github,gitlab,launchpad\-preview] - -.PP -\fB\-h\fP, \fB\-\-help\fP[=false] - help for add - - -.SH SEE ALSO -.PP -\fBgit\-bug\-bridge\-token(1)\fP diff --git a/doc/man/git-bug-bridge-token-rm.1 b/doc/man/git-bug-bridge-token-rm.1 deleted file mode 100644 index 217d938d..00000000 --- a/doc/man/git-bug-bridge-token-rm.1 +++ /dev/null @@ -1,29 +0,0 @@ -.TH "GIT-BUG" "1" "Apr 2019" "Generated from git-bug's source code" "" -.nh -.ad l - - -.SH NAME -.PP -git\-bug\-bridge\-token\-rm \- Remove a token. - - -.SH SYNOPSIS -.PP -\fBgit\-bug bridge token rm [flags]\fP - - -.SH DESCRIPTION -.PP -Remove a token. - - -.SH OPTIONS -.PP -\fB\-h\fP, \fB\-\-help\fP[=false] - help for rm - - -.SH SEE ALSO -.PP -\fBgit\-bug\-bridge\-token(1)\fP diff --git a/doc/man/git-bug-bridge-token-show.1 b/doc/man/git-bug-bridge-token-show.1 deleted file mode 100644 index f40b5024..00000000 --- a/doc/man/git-bug-bridge-token-show.1 +++ /dev/null @@ -1,29 +0,0 @@ -.TH "GIT-BUG" "1" "Apr 2019" "Generated from git-bug's source code" "" -.nh -.ad l - - -.SH NAME -.PP -git\-bug\-bridge\-token\-show \- Display a token. - - -.SH SYNOPSIS -.PP -\fBgit\-bug bridge token show [flags]\fP - - -.SH DESCRIPTION -.PP -Display a token. - - -.SH OPTIONS -.PP -\fB\-h\fP, \fB\-\-help\fP[=false] - help for show - - -.SH SEE ALSO -.PP -\fBgit\-bug\-bridge\-token(1)\fP diff --git a/doc/man/git-bug-bridge-token.1 b/doc/man/git-bug-bridge-token.1 deleted file mode 100644 index f229bf76..00000000 --- a/doc/man/git-bug-bridge-token.1 +++ /dev/null @@ -1,29 +0,0 @@ -.TH "GIT-BUG" "1" "Apr 2019" "Generated from git-bug's source code" "" -.nh -.ad l - - -.SH NAME -.PP -git\-bug\-bridge\-token \- List all known tokens. - - -.SH SYNOPSIS -.PP -\fBgit\-bug bridge token [flags]\fP - - -.SH DESCRIPTION -.PP -List all known tokens. - - -.SH OPTIONS -.PP -\fB\-h\fP, \fB\-\-help\fP[=false] - help for token - - -.SH SEE ALSO -.PP -\fBgit\-bug\-bridge(1)\fP, \fBgit\-bug\-bridge\-token\-add(1)\fP, \fBgit\-bug\-bridge\-token\-rm(1)\fP, \fBgit\-bug\-bridge\-token\-show(1)\fP diff --git a/doc/man/git-bug-bridge.1 b/doc/man/git-bug-bridge.1 index f7e3ff85..8e885f10 100644 --- a/doc/man/git-bug-bridge.1 +++ b/doc/man/git-bug-bridge.1 @@ -26,4 +26,4 @@ Configure and use bridges to other bug trackers. .SH SEE ALSO .PP -\fBgit\-bug(1)\fP, \fBgit\-bug\-bridge\-configure(1)\fP, \fBgit\-bug\-bridge\-pull(1)\fP, \fBgit\-bug\-bridge\-push(1)\fP, \fBgit\-bug\-bridge\-rm(1)\fP, \fBgit\-bug\-bridge\-token(1)\fP +\fBgit\-bug(1)\fP, \fBgit\-bug\-bridge\-auth(1)\fP, \fBgit\-bug\-bridge\-configure(1)\fP, \fBgit\-bug\-bridge\-pull(1)\fP, \fBgit\-bug\-bridge\-push(1)\fP, \fBgit\-bug\-bridge\-rm(1)\fP diff --git a/doc/md/git-bug_bridge.md b/doc/md/git-bug_bridge.md index 073d23ff..3ddb9892 100644 --- a/doc/md/git-bug_bridge.md +++ b/doc/md/git-bug_bridge.md @@ -19,9 +19,9 @@ git-bug bridge [flags] ### SEE ALSO * [git-bug](git-bug.md) - A bug tracker embedded in Git. +* [git-bug bridge auth](git-bug_bridge_auth.md) - List all known bridge authentication credentials. * [git-bug bridge configure](git-bug_bridge_configure.md) - Configure a new bridge. * [git-bug bridge pull](git-bug_bridge_pull.md) - Pull updates. * [git-bug bridge push](git-bug_bridge_push.md) - Push updates. * [git-bug bridge rm](git-bug_bridge_rm.md) - Delete a configured bridge. -* [git-bug bridge token](git-bug_bridge_token.md) - List all known tokens. diff --git a/doc/md/git-bug_bridge_auth.md b/doc/md/git-bug_bridge_auth.md new file mode 100644 index 00000000..e953f0ec --- /dev/null +++ b/doc/md/git-bug_bridge_auth.md @@ -0,0 +1,25 @@ +## git-bug bridge auth + +List all known bridge authentication credentials. + +### Synopsis + +List all known bridge authentication credentials. + +``` +git-bug bridge auth [flags] +``` + +### Options + +``` + -h, --help help for auth +``` + +### SEE ALSO + +* [git-bug bridge](git-bug_bridge.md) - Configure and use bridges to other bug trackers. +* [git-bug bridge auth add-token](git-bug_bridge_auth_add-token.md) - Store a new token +* [git-bug bridge auth rm](git-bug_bridge_auth_rm.md) - Remove a credential. +* [git-bug bridge auth show](git-bug_bridge_auth_show.md) - Display an authentication credential. + diff --git a/doc/md/git-bug_bridge_auth_add-token.md b/doc/md/git-bug_bridge_auth_add-token.md new file mode 100644 index 00000000..7067c3ca --- /dev/null +++ b/doc/md/git-bug_bridge_auth_add-token.md @@ -0,0 +1,23 @@ +## git-bug bridge auth add-token + +Store a new token + +### Synopsis + +Store a new token + +``` +git-bug bridge auth add-token [] [flags] +``` + +### Options + +``` + -t, --target string The target of the bridge. Valid values are [github,gitlab,launchpad-preview] + -h, --help help for add-token +``` + +### SEE ALSO + +* [git-bug bridge auth](git-bug_bridge_auth.md) - List all known bridge authentication credentials. + diff --git a/doc/md/git-bug_bridge_auth_rm.md b/doc/md/git-bug_bridge_auth_rm.md new file mode 100644 index 00000000..059aa43d --- /dev/null +++ b/doc/md/git-bug_bridge_auth_rm.md @@ -0,0 +1,22 @@ +## git-bug bridge auth rm + +Remove a credential. + +### Synopsis + +Remove a credential. + +``` +git-bug bridge auth rm [flags] +``` + +### Options + +``` + -h, --help help for rm +``` + +### SEE ALSO + +* [git-bug bridge auth](git-bug_bridge_auth.md) - List all known bridge authentication credentials. + diff --git a/doc/md/git-bug_bridge_auth_show.md b/doc/md/git-bug_bridge_auth_show.md new file mode 100644 index 00000000..5da3820f --- /dev/null +++ b/doc/md/git-bug_bridge_auth_show.md @@ -0,0 +1,22 @@ +## git-bug bridge auth show + +Display an authentication credential. + +### Synopsis + +Display an authentication credential. + +``` +git-bug bridge auth show [flags] +``` + +### Options + +``` + -h, --help help for show +``` + +### SEE ALSO + +* [git-bug bridge auth](git-bug_bridge_auth.md) - List all known bridge authentication credentials. + diff --git a/doc/md/git-bug_bridge_token.md b/doc/md/git-bug_bridge_token.md deleted file mode 100644 index 14663784..00000000 --- a/doc/md/git-bug_bridge_token.md +++ /dev/null @@ -1,25 +0,0 @@ -## git-bug bridge token - -List all known tokens. - -### Synopsis - -List all known tokens. - -``` -git-bug bridge token [flags] -``` - -### Options - -``` - -h, --help help for token -``` - -### SEE ALSO - -* [git-bug bridge](git-bug_bridge.md) - Configure and use bridges to other bug trackers. -* [git-bug bridge token add](git-bug_bridge_token_add.md) - Store a new token -* [git-bug bridge token rm](git-bug_bridge_token_rm.md) - Remove a token. -* [git-bug bridge token show](git-bug_bridge_token_show.md) - Display a token. - diff --git a/doc/md/git-bug_bridge_token_add.md b/doc/md/git-bug_bridge_token_add.md deleted file mode 100644 index 1c0e5bbc..00000000 --- a/doc/md/git-bug_bridge_token_add.md +++ /dev/null @@ -1,23 +0,0 @@ -## git-bug bridge token add - -Store a new token - -### Synopsis - -Store a new token - -``` -git-bug bridge token add [flags] -``` - -### Options - -``` - -t, --target string The target of the bridge. Valid values are [github,gitlab,launchpad-preview] - -h, --help help for add -``` - -### SEE ALSO - -* [git-bug bridge token](git-bug_bridge_token.md) - List all known tokens. - diff --git a/doc/md/git-bug_bridge_token_rm.md b/doc/md/git-bug_bridge_token_rm.md deleted file mode 100644 index 534406f4..00000000 --- a/doc/md/git-bug_bridge_token_rm.md +++ /dev/null @@ -1,22 +0,0 @@ -## git-bug bridge token rm - -Remove a token. - -### Synopsis - -Remove a token. - -``` -git-bug bridge token rm [flags] -``` - -### Options - -``` - -h, --help help for rm -``` - -### SEE ALSO - -* [git-bug bridge token](git-bug_bridge_token.md) - List all known tokens. - diff --git a/doc/md/git-bug_bridge_token_show.md b/doc/md/git-bug_bridge_token_show.md deleted file mode 100644 index 80439617..00000000 --- a/doc/md/git-bug_bridge_token_show.md +++ /dev/null @@ -1,22 +0,0 @@ -## git-bug bridge token show - -Display a token. - -### Synopsis - -Display a token. - -``` -git-bug bridge token show [flags] -``` - -### Options - -``` - -h, --help help for show -``` - -### SEE ALSO - -* [git-bug bridge token](git-bug_bridge_token.md) - List all known tokens. - diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug index e8126b8f..9dc3ac87 100644 --- a/misc/bash_completion/git-bug +++ b/misc/bash_completion/git-bug @@ -287,9 +287,9 @@ _git-bug_add() noun_aliases=() } -_git-bug_bridge_configure() +_git-bug_bridge_auth_add-token() { - last_command="git-bug_bridge_configure" + last_command="git-bug_bridge_auth_add-token" command_aliases=() @@ -301,41 +301,19 @@ _git-bug_bridge_configure() flags_with_completion=() flags_completion=() - flags+=("--name=") - two_word_flags+=("--name") - two_word_flags+=("-n") - local_nonpersistent_flags+=("--name=") flags+=("--target=") two_word_flags+=("--target") two_word_flags+=("-t") local_nonpersistent_flags+=("--target=") - flags+=("--url=") - two_word_flags+=("--url") - two_word_flags+=("-u") - local_nonpersistent_flags+=("--url=") - flags+=("--owner=") - two_word_flags+=("--owner") - two_word_flags+=("-o") - local_nonpersistent_flags+=("--owner=") - flags+=("--token=") - two_word_flags+=("--token") - two_word_flags+=("-T") - local_nonpersistent_flags+=("--token=") - flags+=("--token-stdin") - local_nonpersistent_flags+=("--token-stdin") - flags+=("--project=") - two_word_flags+=("--project") - two_word_flags+=("-p") - local_nonpersistent_flags+=("--project=") must_have_one_flag=() must_have_one_noun=() noun_aliases=() } -_git-bug_bridge_pull() +_git-bug_bridge_auth_rm() { - last_command="git-bug_bridge_pull" + last_command="git-bug_bridge_auth_rm" command_aliases=() @@ -347,22 +325,15 @@ _git-bug_bridge_pull() flags_with_completion=() flags_completion=() - flags+=("--no-resume") - flags+=("-n") - local_nonpersistent_flags+=("--no-resume") - flags+=("--since=") - two_word_flags+=("--since") - two_word_flags+=("-s") - local_nonpersistent_flags+=("--since=") must_have_one_flag=() must_have_one_noun=() noun_aliases=() } -_git-bug_bridge_push() +_git-bug_bridge_auth_show() { - last_command="git-bug_bridge_push" + last_command="git-bug_bridge_auth_show" command_aliases=() @@ -380,13 +351,16 @@ _git-bug_bridge_push() noun_aliases=() } -_git-bug_bridge_rm() +_git-bug_bridge_auth() { - last_command="git-bug_bridge_rm" + last_command="git-bug_bridge_auth" command_aliases=() commands=() + commands+=("add-token") + commands+=("rm") + commands+=("show") flags=() two_word_flags=() @@ -400,9 +374,9 @@ _git-bug_bridge_rm() noun_aliases=() } -_git-bug_bridge_token_add() +_git-bug_bridge_configure() { - last_command="git-bug_bridge_token_add" + last_command="git-bug_bridge_configure" command_aliases=() @@ -414,19 +388,41 @@ _git-bug_bridge_token_add() flags_with_completion=() flags_completion=() + flags+=("--name=") + two_word_flags+=("--name") + two_word_flags+=("-n") + local_nonpersistent_flags+=("--name=") flags+=("--target=") two_word_flags+=("--target") two_word_flags+=("-t") local_nonpersistent_flags+=("--target=") + flags+=("--url=") + two_word_flags+=("--url") + two_word_flags+=("-u") + local_nonpersistent_flags+=("--url=") + flags+=("--owner=") + two_word_flags+=("--owner") + two_word_flags+=("-o") + local_nonpersistent_flags+=("--owner=") + flags+=("--token=") + two_word_flags+=("--token") + two_word_flags+=("-T") + local_nonpersistent_flags+=("--token=") + flags+=("--token-stdin") + local_nonpersistent_flags+=("--token-stdin") + flags+=("--project=") + two_word_flags+=("--project") + two_word_flags+=("-p") + local_nonpersistent_flags+=("--project=") must_have_one_flag=() must_have_one_noun=() noun_aliases=() } -_git-bug_bridge_token_rm() +_git-bug_bridge_pull() { - last_command="git-bug_bridge_token_rm" + last_command="git-bug_bridge_pull" command_aliases=() @@ -438,15 +434,22 @@ _git-bug_bridge_token_rm() flags_with_completion=() flags_completion=() + flags+=("--no-resume") + flags+=("-n") + local_nonpersistent_flags+=("--no-resume") + flags+=("--since=") + two_word_flags+=("--since") + two_word_flags+=("-s") + local_nonpersistent_flags+=("--since=") must_have_one_flag=() must_have_one_noun=() noun_aliases=() } -_git-bug_bridge_token_show() +_git-bug_bridge_push() { - last_command="git-bug_bridge_token_show" + last_command="git-bug_bridge_push" command_aliases=() @@ -464,16 +467,13 @@ _git-bug_bridge_token_show() noun_aliases=() } -_git-bug_bridge_token() +_git-bug_bridge_rm() { - last_command="git-bug_bridge_token" + last_command="git-bug_bridge_rm" command_aliases=() commands=() - commands+=("add") - commands+=("rm") - commands+=("show") flags=() two_word_flags=() @@ -494,11 +494,11 @@ _git-bug_bridge() command_aliases=() commands=() + commands+=("auth") commands+=("configure") commands+=("pull") commands+=("push") commands+=("rm") - commands+=("token") flags=() two_word_flags=() diff --git a/misc/powershell_completion/git-bug b/misc/powershell_completion/git-bug index 6a7bf0c3..5f043932 100644 --- a/misc/powershell_completion/git-bug +++ b/misc/powershell_completion/git-bug @@ -48,11 +48,28 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock { break } 'git-bug;bridge' { + [CompletionResult]::new('auth', 'auth', [CompletionResultType]::ParameterValue, 'List all known bridge authentication credentials.') [CompletionResult]::new('configure', 'configure', [CompletionResultType]::ParameterValue, 'Configure a new bridge.') [CompletionResult]::new('pull', 'pull', [CompletionResultType]::ParameterValue, 'Pull updates.') [CompletionResult]::new('push', 'push', [CompletionResultType]::ParameterValue, 'Push updates.') [CompletionResult]::new('rm', 'rm', [CompletionResultType]::ParameterValue, 'Delete a configured bridge.') - [CompletionResult]::new('token', 'token', [CompletionResultType]::ParameterValue, 'List all known tokens.') + break + } + 'git-bug;bridge;auth' { + [CompletionResult]::new('add-token', 'add-token', [CompletionResultType]::ParameterValue, 'Store a new token') + [CompletionResult]::new('rm', 'rm', [CompletionResultType]::ParameterValue, 'Remove a credential.') + [CompletionResult]::new('show', 'show', [CompletionResultType]::ParameterValue, 'Display an authentication credential.') + break + } + 'git-bug;bridge;auth;add-token' { + [CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, 'The target of the bridge. Valid values are [github,gitlab,launchpad-preview]') + [CompletionResult]::new('--target', 'target', [CompletionResultType]::ParameterName, 'The target of the bridge. Valid values are [github,gitlab,launchpad-preview]') + break + } + 'git-bug;bridge;auth;rm' { + break + } + 'git-bug;bridge;auth;show' { break } 'git-bug;bridge;configure' { @@ -84,23 +101,6 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock { 'git-bug;bridge;rm' { break } - 'git-bug;bridge;token' { - [CompletionResult]::new('add', 'add', [CompletionResultType]::ParameterValue, 'Store a new token') - [CompletionResult]::new('rm', 'rm', [CompletionResultType]::ParameterValue, 'Remove a token.') - [CompletionResult]::new('show', 'show', [CompletionResultType]::ParameterValue, 'Display a token.') - break - } - 'git-bug;bridge;token;add' { - [CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, 'The target of the bridge. Valid values are [github,gitlab,launchpad-preview]') - [CompletionResult]::new('--target', 'target', [CompletionResultType]::ParameterName, 'The target of the bridge. Valid values are [github,gitlab,launchpad-preview]') - break - } - 'git-bug;bridge;token;rm' { - break - } - 'git-bug;bridge;token;show' { - break - } 'git-bug;commands' { [CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Output the command description as well as Markdown compatible comment') [CompletionResult]::new('--pretty', 'pretty', [CompletionResultType]::ParameterName, 'Output the command description as well as Markdown compatible comment') diff --git a/misc/zsh_completion/git-bug b/misc/zsh_completion/git-bug index f0ff7edf..230061dd 100644 --- a/misc/zsh_completion/git-bug +++ b/misc/zsh_completion/git-bug @@ -114,17 +114,20 @@ function _git-bug_bridge { case $state in cmnds) commands=( + "auth:List all known bridge authentication credentials." "configure:Configure a new bridge." "pull:Pull updates." "push:Push updates." "rm:Delete a configured bridge." - "token:List all known tokens." ) _describe "command" commands ;; esac case "$words[1]" in + auth) + _git-bug_bridge_auth + ;; configure) _git-bug_bridge_configure ;; @@ -137,39 +140,11 @@ function _git-bug_bridge { rm) _git-bug_bridge_rm ;; - token) - _git-bug_bridge_token - ;; esac } -function _git-bug_bridge_configure { - _arguments \ - '(-n --name)'{-n,--name}'[A distinctive name to identify the bridge]:' \ - '(-t --target)'{-t,--target}'[The target of the bridge. Valid values are [github,gitlab,launchpad-preview]]:' \ - '(-u --url)'{-u,--url}'[The URL of the target repository]:' \ - '(-o --owner)'{-o,--owner}'[The owner of the target repository]:' \ - '(-T --token)'{-T,--token}'[The authentication token for the API]:' \ - '--token-stdin[Will read the token from stdin and ignore --token]' \ - '(-p --project)'{-p,--project}'[The name of the target repository]:' -} - -function _git-bug_bridge_pull { - _arguments \ - '(-n --no-resume)'{-n,--no-resume}'[force importing all bugs]' \ - '(-s --since)'{-s,--since}'[import only bugs updated after the given date (ex: "200h" or "june 2 2019")]:' -} - -function _git-bug_bridge_push { - _arguments -} - -function _git-bug_bridge_rm { - _arguments -} - -function _git-bug_bridge_token { +function _git-bug_bridge_auth { local -a commands _arguments -C \ @@ -179,37 +154,62 @@ function _git-bug_bridge_token { case $state in cmnds) commands=( - "add:Store a new token" - "rm:Remove a token." - "show:Display a token." + "add-token:Store a new token" + "rm:Remove a credential." + "show:Display an authentication credential." ) _describe "command" commands ;; esac case "$words[1]" in - add) - _git-bug_bridge_token_add + add-token) + _git-bug_bridge_auth_add-token ;; rm) - _git-bug_bridge_token_rm + _git-bug_bridge_auth_rm ;; show) - _git-bug_bridge_token_show + _git-bug_bridge_auth_show ;; esac } -function _git-bug_bridge_token_add { +function _git-bug_bridge_auth_add-token { _arguments \ '(-t --target)'{-t,--target}'[The target of the bridge. Valid values are [github,gitlab,launchpad-preview]]:' } -function _git-bug_bridge_token_rm { +function _git-bug_bridge_auth_rm { + _arguments +} + +function _git-bug_bridge_auth_show { + _arguments +} + +function _git-bug_bridge_configure { + _arguments \ + '(-n --name)'{-n,--name}'[A distinctive name to identify the bridge]:' \ + '(-t --target)'{-t,--target}'[The target of the bridge. Valid values are [github,gitlab,launchpad-preview]]:' \ + '(-u --url)'{-u,--url}'[The URL of the target repository]:' \ + '(-o --owner)'{-o,--owner}'[The owner of the target repository]:' \ + '(-T --token)'{-T,--token}'[The authentication token for the API]:' \ + '--token-stdin[Will read the token from stdin and ignore --token]' \ + '(-p --project)'{-p,--project}'[The name of the target repository]:' +} + +function _git-bug_bridge_pull { + _arguments \ + '(-n --no-resume)'{-n,--no-resume}'[force importing all bugs]' \ + '(-s --since)'{-s,--since}'[import only bugs updated after the given date (ex: "200h" or "june 2 2019")]:' +} + +function _git-bug_bridge_push { _arguments } -function _git-bug_bridge_token_show { +function _git-bug_bridge_rm { _arguments } -- cgit