diff --git a/cmd/init.go b/cmd/init.go index ee86c64..cb50fc4 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -50,6 +50,15 @@ func InitCmd() *cobra.Command { } func initCmdF(cmd *cobra.Command, _ []string) { + campaignPath, _ := cmd.Flags().GetString("campaign") + + _, err := os.Stat(campaignPath) + if err == nil { + ErrorAndExit(cmd, fmt.Errorf("cannot use %s as campaign file: file already exists", campaignPath)) + } else if !os.IsNotExist(err) { + ErrorAndExit(cmd, fmt.Errorf("cannot use %s as campaign file: %w", campaignPath, err)) + } + getStringFlagOrAskIfEmpty := func(name string, question string) string { val, _ := cmd.Flags().GetString(name) if val == "" { @@ -96,7 +105,7 @@ func initCmdF(cmd *cobra.Command, _ []string) { IssueTemplate: issueTemplate, FooterTemplate: footerTemplate, } - if err := app.SaveCampaign(campaign, "./campaign.json"); err != nil { + if err := app.SaveCampaign(campaign, campaignPath); err != nil { ErrorAndExit(cmd, err) } } diff --git a/cmd/root.go b/cmd/root.go index 26e9af2..78f211f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -25,7 +25,9 @@ func withApp(f func(*app.App, *cobra.Command, []string)) func(*cobra.Command, [] func withAppE(f func(*app.App, *cobra.Command, []string) error) func(*cobra.Command, []string) error { return func(cmd *cobra.Command, args []string) error { - a, err := app.NewApp("./campaign.json") + campaignPath, _ := cmd.Flags().GetString("campaign") + + a, err := app.NewApp(campaignPath) if err != nil { fmt.Fprintln(os.Stderr, "ERROR: "+err.Error()) os.Exit(1)