2019-09-18 22:00:07 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2019-10-12 12:10:44 +03:00
|
|
|
"github.com/pkg/errors"
|
2019-09-18 22:00:07 +03:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
"github.com/MichaelMure/git-bug/bridge/core"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
bridgeToken core.Token
|
|
|
|
)
|
|
|
|
|
|
|
|
func runBridgeTokenAdd(cmd *cobra.Command, args []string) error {
|
2019-10-12 12:10:44 +03:00
|
|
|
if err := bridgeToken.Validate(); err != nil {
|
|
|
|
return errors.Wrap(err, "invalid token")
|
|
|
|
}
|
|
|
|
|
2019-09-18 22:00:07 +03:00
|
|
|
if bridgeToken.Global {
|
2019-10-12 12:10:44 +03:00
|
|
|
return core.StoreToken(repo, &bridgeToken)
|
2019-09-18 22:00:07 +03:00
|
|
|
}
|
|
|
|
|
2019-10-12 12:10:44 +03:00
|
|
|
return core.StoreGlobalToken(repo, &bridgeToken)
|
2019-09-18 22:00:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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().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
|
|
|
|
}
|