From 573ea9e136328c5237586ea9eb6b0d4fc9629499 Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Sat, 29 Feb 2020 00:49:55 +0100 Subject: [PATCH] Add init command --- cmd/init.go | 21 +++++++++++++++++++++ cmd/root.go | 1 + config/config.go | 15 ++++++--------- model/campaign.go | 5 +++++ model/config.go | 6 ++++++ 5 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 cmd/init.go create mode 100644 model/campaign.go create mode 100644 model/config.go diff --git a/cmd/init.go b/cmd/init.go new file mode 100644 index 0000000..a2eebf1 --- /dev/null +++ b/cmd/init.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +func InitCmd() *cobra.Command { + return &cobra.Command{ + Use: "init", + Short: "Creates a new campaign in the current directory", + Args: cobra.NoArgs, + RunE: initCmdF, + } + + // add mandatory flags for epic, tags, etc +} + +func initCmdF(_ *cobra.Command, _ []string) error { + // creates the campaign.json file + return nil +} diff --git a/cmd/root.go b/cmd/root.go index 22f1801..d5a4219 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -14,6 +14,7 @@ func RootCmd() *cobra.Command { } cmd.AddCommand( + InitCmd(), TokenCmd(), ) diff --git a/config/config.go b/config/config.go index 38cc2e3..50abc14 100644 --- a/config/config.go +++ b/config/config.go @@ -6,12 +6,9 @@ import ( "io/ioutil" "os" "os/user" -) -type Config struct { - GithubToken string `json:"github_token"` - JiraToken string `json:"jira_token"` -} + "git.ctrlz.es/mgdelacroix/campaigner/model" +) func getConfigPath() (string, error) { user, err := user.Current() @@ -21,14 +18,14 @@ func getConfigPath() (string, error) { return user.HomeDir + "/.campaigner", nil } -func ReadConfig() (*Config, error) { +func ReadConfig() (*model.Config, error) { configPath, err := getConfigPath() if err != nil { return nil, err } if _, err := os.Stat(configPath); err != nil { - return &Config{}, nil + return &model.Config{}, nil } fileContents, err := ioutil.ReadFile(configPath) @@ -36,7 +33,7 @@ func ReadConfig() (*Config, error) { return nil, fmt.Errorf("there was a problem reading the config file: %w", err) } - var config Config + var config model.Config if err := json.Unmarshal(fileContents, &config); err != nil { return nil, fmt.Errorf("there was a problem parsing the config file: %w", err) } @@ -44,7 +41,7 @@ func ReadConfig() (*Config, error) { return &config, nil } -func SaveConfig(config *Config) error { +func SaveConfig(config *model.Config) error { configPath, err := getConfigPath() if err != nil { return err diff --git a/model/campaign.go b/model/campaign.go new file mode 100644 index 0000000..024281f --- /dev/null +++ b/model/campaign.go @@ -0,0 +1,5 @@ +package model + +type Campaign struct { + Epic string `json:"epic"` +} diff --git a/model/config.go b/model/config.go new file mode 100644 index 0000000..6938f8e --- /dev/null +++ b/model/config.go @@ -0,0 +1,6 @@ +package model + +type Config struct { + GithubToken string `json:"github_token"` + JiraToken string `json:"jira_token"` +}