forked from jesseduffield/lazygit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add StatusPanelView config (jesseduffield#3309)
Adds a new config `statusPanelView ` which allows you to select the default view of the main window: `dashboard` (default), `allBranchesLog`.
- Loading branch information
Showing
7 changed files
with
128 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"slices" | ||
"strings" | ||
) | ||
|
||
func (config *UserConfig) Validate() error { | ||
if err := validateEnum("gui.statusPanelView", config.Gui.StatusPanelView, []string{"dashboard", "allBranchesLog"}); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func validateEnum(name string, value string, allowedValues []string) error { | ||
if slices.Contains(allowedValues, value) { | ||
return nil | ||
} | ||
allowedValuesStr := strings.Join(allowedValues, ", ") | ||
return fmt.Errorf("Unexpected value '%s' for '%s'. Allowed values: %s", value, name, allowedValuesStr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestUserConfigValidate_enums(t *testing.T) { | ||
type testCase struct { | ||
value string | ||
valid bool | ||
} | ||
|
||
scenarios := []struct { | ||
name string | ||
setup func(config *UserConfig, value string) | ||
testCases []testCase | ||
}{ | ||
{ | ||
name: "Gui.StatusPanelView", | ||
setup: func(config *UserConfig, value string) { | ||
config.Gui.StatusPanelView = value | ||
}, | ||
testCases: []testCase{ | ||
{value: "dashboard", valid: true}, | ||
{value: "allBranchesLog", valid: true}, | ||
{value: "", valid: false}, | ||
{value: "invalid_value", valid: false}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, s := range scenarios { | ||
t.Run(s.name, func(t *testing.T) { | ||
for _, testCase := range s.testCases { | ||
config := GetDefaultConfig() | ||
s.setup(config, testCase.value) | ||
err := config.Validate() | ||
|
||
if testCase.valid { | ||
assert.NoError(t, err) | ||
} else { | ||
assert.Error(t, err) | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters