Skip to content

Commit 6591fd6

Browse files
authored
fix(tui): create config directory if does not exist (#65)
## What does this PR do? Create dir structure for a default config. ## Why is this change important? Fixes #64. ## How to test this PR locally? `go build main.go && ./main tui --config whatever/config.toml` ## Related issues Closes #64 .
2 parents 09b6922 + 602778d commit 6591fd6

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

cmd/tui.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var tuiCmd = &cobra.Command{
3333
defer f.Close()
3434
} else {
3535
// disable logging completely for tui unless run in the debug mode
36-
logrus.SetLevel(logrus.PanicLevel)
36+
logrus.SetLevel(logrus.ErrorLevel)
3737
}
3838

3939
if runningUnderTest {

internal/app/tui.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ func NewTUI(ctx context.Context, configPath, mockedHyprMonitors string,
3131
) (*TUI, error) {
3232
cfg, err := config.NewConfig(configPath)
3333
if err != nil {
34-
logrus.WithError(err).Error("cant read config, ignoring")
34+
logrus.WithError(err).Error("cant create/read config")
35+
return nil, fmt.Errorf("cant create/read config: %w", err)
3536
}
3637

3738
var monitors hypr.MonitorSpecs

internal/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ func Cond(cond, a *string, b string) string {
291291
}
292292

293293
func CreateDefaultConfig(path string) error {
294+
if err := os.MkdirAll(filepath.Dir(path), 0o750); err != nil {
295+
return fmt.Errorf("cant create directory: %w", err)
296+
}
297+
294298
objectPath, err := utils.GetPowerLine()
295299
if err != nil {
296300
logrus.Warning("No power line available, will use a default")

internal/config/default_config_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func TestCreateDefaultConfig(t *testing.T) {
8383
func TestCreateDefaultConfigTemplate(t *testing.T) {
8484
t.Run("template renders correctly", func(t *testing.T) {
8585
tmpDir := t.TempDir()
86+
tmpDir = filepath.Join(tmpDir, "nonexistentdir")
8687
configPath := filepath.Join(tmpDir, "config.toml")
8788

8889
origRunCmd := utils.GetRunCmd()

0 commit comments

Comments
 (0)