Skip to content

Commit

Permalink
Allow configuring log directory separately from config directory (#8)
Browse files Browse the repository at this point in the history
* feat: Add XDG-compliant log dir

Signed-off-by: Felicitas Pojtinger <[email protected]>

* fix: Correct casing and use Viper conventions for flag default formatting

Signed-off-by: Felicitas Pojtinger <[email protected]>

---------

Signed-off-by: Felicitas Pojtinger <[email protected]>
  • Loading branch information
pojntfx authored Jul 25, 2024
1 parent 5e2ba7b commit dde74cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,16 @@ func (c *Command[T]) runCmd(ctx context.Context, format *printer.Format, debug *
return err
}

logDir, err := c.config.DefaultLogDir()
if err != nil {
return err
}

configPath := path.Join(configDir, c.config.DefaultConfigFile())
logPath := path.Join(configDir, c.config.DefaultLogFile())
logPath := path.Join(logDir, c.config.DefaultLogFile())

c.command.PersistentFlags().StringVar(&cfgFile, "config", "", fmt.Sprintf("Config file (default is %s)", configPath))
c.command.PersistentFlags().StringVar(&logFile, "log", logPath, "Log File")
c.command.PersistentFlags().StringVar(&cfgFile, "config", "", fmt.Sprintf(`Config file (default "%s")`, configPath))
c.command.PersistentFlags().StringVar(&logFile, "log", logPath, "Log file")

cobra.OnInitialize(func() {
err := c.initConfig()
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Config interface {
Validate() error
DefaultConfigDir() (string, error)
DefaultConfigFile() string
DefaultLogDir() (string, error)
DefaultLogFile() string
SetConfigFile(configFile string)
GetConfigFile() string
Expand Down

0 comments on commit dde74cb

Please sign in to comment.