diff options
author | amine <hilalyamine@gmail.com> | 2019-11-08 14:49:24 +0100 |
---|---|---|
committer | amine <hilalyamine@gmail.com> | 2019-11-09 14:52:20 +0100 |
commit | bbbf3c6c7f245ea2ddc9d31639e7ebac50eeac2d (patch) | |
tree | 17883d25b5d1f2f1b1fe2f2bf33b44d1259b938e /commands | |
parent | 4dc7b8b06ed5d48eca077b81a0b8c90777b8fe82 (diff) | |
download | git-bug-bbbf3c6c7f245ea2ddc9d31639e7ebac50eeac2d.tar.gz |
bridge/core: store token in the global config and replace scopes with create date
Diffstat (limited to 'commands')
-rw-r--r-- | commands/bridge_token.go | 29 | ||||
-rw-r--r-- | commands/bridge_token_add.go | 16 | ||||
-rw-r--r-- | commands/bridge_token_rm.go | 8 |
3 files changed, 19 insertions, 34 deletions
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{ |