diff --git a/cmd/entries.go b/cmd/entries.go index 3514d45..806a7fc 100644 --- a/cmd/entries.go +++ b/cmd/entries.go @@ -96,8 +96,16 @@ var entriesCreateCommand = &cobra.Command{ Use: "create", Short: "create time entries", Run: func(cmd *cobra.Command, args []string) { + if createProjectId == "" { + createProjectId = deps.conf.Get("projectId") + } + + if createServiceId == "" { + createServiceId = deps.conf.Get("serviceId") + } + if createProjectId == "" || createServiceId == "" { - _, _ = fmt.Fprintln(os.Stderr, "please set both the project AND service id") + _, _ = fmt.Fprintln(os.Stderr, "please set both the project AND service id (either via arguments or config)") return } diff --git a/config/config.go b/config/config.go index 000adbf..da12e3c 100644 --- a/config/config.go +++ b/config/config.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/spf13/viper" "os" - "path/filepath" ) type Config interface { @@ -16,16 +15,18 @@ type Config interface { } type config struct { - fileName string - filePath string - fileType string + fileName string + filePath string + fileType string + fileFullPath string } func NewConfig(fileName, filePath, fileType string) Config { viper.AddConfigPath("$HOME") viper.SetConfigName(fileName) viper.SetConfigType(fileType) - return &config{fileName: fileName, filePath: filePath, fileType: fileType} + ffp := fmt.Sprintf("%s/%s.%s", filePath, fileName, fileType) + return &config{fileName: fileName, filePath: filePath, fileType: fileType, fileFullPath: ffp} } func (c *config) GetApiUrl() string { @@ -55,7 +56,7 @@ func (c *config) Set(key string, value string) { if err != nil { _, _ = fmt.Fprintln(os.Stderr, err) } - err = viper.WriteConfigAs(filepath.Join(c.filePath, c.fileName)) + err = viper.WriteConfigAs(c.fileFullPath) if err != nil { _, _ = fmt.Fprintln(os.Stderr, err) }