diff options
Diffstat (limited to 'commands')
-rw-r--r-- | commands/bridge_auth.go (renamed from commands/bridge_token.go) | 27 | ||||
-rw-r--r-- | commands/bridge_auth_add.go (renamed from commands/bridge_token_add.go) | 20 | ||||
-rw-r--r-- | commands/bridge_auth_rm.go (renamed from commands/bridge_token_rm.go) | 10 | ||||
-rw-r--r-- | commands/bridge_auth_show.go (renamed from commands/bridge_token_show.go) | 13 |
4 files changed, 34 insertions, 36 deletions
diff --git a/commands/bridge_token.go b/commands/bridge_auth.go index b9e2d49f..e7fce1bd 100644 --- a/commands/bridge_token.go +++ b/commands/bridge_auth.go @@ -2,7 +2,6 @@ package commands import ( "fmt" - "time" "github.com/spf13/cobra" @@ -12,7 +11,7 @@ import ( "github.com/MichaelMure/git-bug/util/colors" ) -func runTokenBridge(cmd *cobra.Command, args []string) error { +func runBridgeAuth(cmd *cobra.Command, args []string) error { tokens, err := core.ListTokens(repo) if err != nil { return err @@ -30,27 +29,25 @@ func runTokenBridge(cmd *cobra.Command, args []string) error { } 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) + targetFmt := text.LeftPadMaxLine(token.Target, 10, 0) fmt.Printf("%s %s %s %s\n", - token.ID().Human(), - colors.Magenta(targetFmt), - valueFmt, - createTimeFmt, + colors.Cyan(token.ID().Human()), + colors.Yellow(targetFmt), + colors.Magenta("token"), + token.Value, ) } -var bridgeTokenCmd = &cobra.Command{ - Use: "token", - Short: "List all known tokens.", +var bridgeAuthCmd = &cobra.Command{ + Use: "auth", + Short: "List all known bridge authentication credentials.", PreRunE: loadRepo, - RunE: runTokenBridge, + RunE: runBridgeAuth, Args: cobra.NoArgs, } func init() { - bridgeCmd.AddCommand(bridgeTokenCmd) - bridgeTokenCmd.Flags().SortFlags = false + bridgeCmd.AddCommand(bridgeAuthCmd) + bridgeAuthCmd.Flags().SortFlags = false } diff --git a/commands/bridge_token_add.go b/commands/bridge_auth_add.go index d2c697fa..ae2c4dbc 100644 --- a/commands/bridge_token_add.go +++ b/commands/bridge_auth_add.go @@ -15,17 +15,17 @@ import ( ) var ( - bridgeTokenTarget string + bridgeAuthAddTokenTarget string ) func runBridgeTokenAdd(cmd *cobra.Command, args []string) error { var value string - if bridgeTokenTarget == "" { - return fmt.Errorf("token target is required") + if bridgeAuthAddTokenTarget == "" { + return fmt.Errorf("auth target is required") } - if !core.TargetExist(bridgeTokenTarget) { + if !core.TargetExist(bridgeAuthAddTokenTarget) { return fmt.Errorf("unknown target") } @@ -44,7 +44,7 @@ func runBridgeTokenAdd(cmd *cobra.Command, args []string) error { value = strings.TrimSuffix(raw, "\n") } - token := core.NewToken(value, bridgeTokenTarget) + token := core.NewToken(value, bridgeAuthAddTokenTarget) if err := token.Validate(); err != nil { return errors.Wrap(err, "invalid token") } @@ -58,8 +58,8 @@ func runBridgeTokenAdd(cmd *cobra.Command, args []string) error { return nil } -var bridgeTokenAddCmd = &cobra.Command{ - Use: "add", +var bridgeAuthAddTokenCmd = &cobra.Command{ + Use: "add-token [<token>]", Short: "Store a new token", PreRunE: loadRepo, RunE: runBridgeTokenAdd, @@ -67,8 +67,8 @@ var bridgeTokenAddCmd = &cobra.Command{ } func init() { - bridgeTokenCmd.AddCommand(bridgeTokenAddCmd) - bridgeTokenAddCmd.Flags().StringVarP(&bridgeTokenTarget, "target", "t", "", + bridgeAuthCmd.AddCommand(bridgeAuthAddTokenCmd) + bridgeAuthAddTokenCmd.Flags().StringVarP(&bridgeAuthAddTokenTarget, "target", "t", "", fmt.Sprintf("The target of the bridge. Valid values are [%s]", strings.Join(bridge.Targets(), ","))) - bridgeTokenAddCmd.Flags().SortFlags = false + bridgeAuthAddTokenCmd.Flags().SortFlags = false } diff --git a/commands/bridge_token_rm.go b/commands/bridge_auth_rm.go index a73fbb91..b0b4d437 100644 --- a/commands/bridge_token_rm.go +++ b/commands/bridge_auth_rm.go @@ -8,7 +8,7 @@ import ( "github.com/MichaelMure/git-bug/bridge/core" ) -func runBridgeTokenRm(cmd *cobra.Command, args []string) error { +func runBridgeAuthRm(cmd *cobra.Command, args []string) error { token, err := core.LoadTokenPrefix(repo, args[0]) if err != nil { return err @@ -23,14 +23,14 @@ func runBridgeTokenRm(cmd *cobra.Command, args []string) error { return nil } -var bridgeTokenRmCmd = &cobra.Command{ +var bridgeAuthRmCmd = &cobra.Command{ Use: "rm <id>", - Short: "Remove a token.", + Short: "Remove a credential.", PreRunE: loadRepo, - RunE: runBridgeTokenRm, + RunE: runBridgeAuthRm, Args: cobra.ExactArgs(1), } func init() { - bridgeTokenCmd.AddCommand(bridgeTokenRmCmd) + bridgeAuthCmd.AddCommand(bridgeAuthRmCmd) } diff --git a/commands/bridge_token_show.go b/commands/bridge_auth_show.go index 2d2e824d..94141b93 100644 --- a/commands/bridge_token_show.go +++ b/commands/bridge_auth_show.go @@ -9,28 +9,29 @@ import ( "github.com/MichaelMure/git-bug/bridge/core" ) -func runBridgeTokenShow(cmd *cobra.Command, args []string) error { +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("Value: %s\n", token.Value) 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 bridgeTokenShowCmd = &cobra.Command{ +var bridgeAuthShowCmd = &cobra.Command{ Use: "show", - Short: "Display a token.", + Short: "Display an authentication credential.", PreRunE: loadRepo, - RunE: runBridgeTokenShow, + RunE: runBridgeAuthShow, Args: cobra.ExactArgs(1), } func init() { - bridgeTokenCmd.AddCommand(bridgeTokenShowCmd) + bridgeAuthCmd.AddCommand(bridgeAuthShowCmd) } |