2020-02-29 00:02:56 +01:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2020-02-29 00:34:17 +01:00
|
|
|
"git.ctrlz.es/mgdelacroix/campaigner/config"
|
|
|
|
|
2020-02-29 00:02:56 +01:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TokenSetJiraCmd() *cobra.Command {
|
|
|
|
return &cobra.Command{
|
2020-02-29 00:23:26 +01:00
|
|
|
Use: "jira",
|
2020-02-29 00:02:56 +01:00
|
|
|
Short: "Sets the value of the jira token",
|
2020-02-29 00:34:17 +01:00
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
RunE: tokenSetJiraCmdF,
|
2020-02-29 00:02:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TokenSetGithubCmd() *cobra.Command {
|
|
|
|
return &cobra.Command{
|
2020-02-29 00:23:26 +01:00
|
|
|
Use: "github",
|
2020-02-29 00:02:56 +01:00
|
|
|
Short: "Sets the value of the github token",
|
2020-02-29 00:34:17 +01:00
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
RunE: tokenSetGithubCmdF,
|
2020-02-29 00:02:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TokenSetCmd() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
2020-02-29 00:23:26 +01:00
|
|
|
Use: "set",
|
2020-02-29 00:02:56 +01:00
|
|
|
Short: "Sets the value of the platform tokens",
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.AddCommand(
|
|
|
|
TokenSetJiraCmd(),
|
|
|
|
TokenSetGithubCmd(),
|
|
|
|
)
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func TokenCmd() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
2020-02-29 00:23:26 +01:00
|
|
|
Use: "token",
|
2020-02-29 00:02:56 +01:00
|
|
|
Short: "Subcommands related to tokens",
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.AddCommand(
|
|
|
|
TokenSetCmd(),
|
|
|
|
)
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
2020-02-29 00:34:17 +01:00
|
|
|
|
|
|
|
func tokenSetJiraCmdF(cmd *cobra.Command, args []string) error {
|
|
|
|
cfg, err := config.ReadConfig()
|
|
|
|
if err != nil {
|
|
|
|
ErrorAndExit(cmd, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg.JiraToken = args[0]
|
|
|
|
if err := config.SaveConfig(cfg); err != nil {
|
|
|
|
ErrorAndExit(cmd, err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func tokenSetGithubCmdF(cmd *cobra.Command, args []string) error {
|
|
|
|
cfg, err := config.ReadConfig()
|
|
|
|
if err != nil {
|
|
|
|
ErrorAndExit(cmd, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg.GithubToken = args[0]
|
|
|
|
if err := config.SaveConfig(cfg); err != nil {
|
|
|
|
ErrorAndExit(cmd, err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|