mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
fix(config): print only the value of config get and add display preferences
tea config get printed "key<TAB>value", so $(tea config get editor) was not usable; it now prints the value alone, and --show-source appends the source (D18). config get reads the instance's user, and instance settings come from the selected instance (--host, TEA_HOST, default_host or the sole instance). Unknown keys list the valid ones, and keys that need --host or --user say so. config path no longer loads the settings, so it works when hosts.yml is broken. config list is a table on a terminal. config set confirms the change on a terminal and warns when default_host has no account. config.yml stores the hyperlinks (auto, always, never) and markdown (auto, raw) preferences that tables and views now read, instead of the TEA_HYPERLINKS and TEA_MARKDOWN variables. The environment table moves out of tea config --help into tea help environment. alias set refuses to replace an alias without --clobber, drops a leading "tea", and explains how to quote an expansion with spaces or flags. alias delete takes several names or --all, alias list is a table, and an empty list says so on a terminal. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
9 files changed
+687
-271
No files matched your search
@@ -52,6 +52,8 @@ type Preferences struct {
|
||||
Pager string `yaml:"pager,omitempty" json:"pager"`
|
||||
Browser string `yaml:"browser,omitempty" json:"browser"`
|
||||
Color string `yaml:"color,omitempty" json:"color"`
|
||||
Hyperlinks string `yaml:"hyperlinks,omitempty" json:"hyperlinks"`
|
||||
Markdown string `yaml:"markdown,omitempty" json:"markdown"`
|
||||
Remote string `yaml:"remote,omitempty" json:"remote"`
|
||||
Aliases map[string]string `yaml:"aliases,omitempty" json:"aliases"`
|
||||
}
|
||||
@@ -114,7 +116,7 @@ func New(dir string) *Store {
|
||||
|
||||
// Defaults returns a fresh preferences value with built-in settings.
|
||||
func Defaults() Preferences {
|
||||
return Preferences{Version: Version, GitProtocol: "https", Prompt: "enabled", Color: "auto", Aliases: map[string]string{}}
|
||||
return Preferences{Version: Version, GitProtocol: "https", Prompt: "enabled", Color: "auto", Hyperlinks: "auto", Markdown: "auto", Aliases: map[string]string{}}
|
||||
}
|
||||
|
||||
// stored omits built-in defaults so that only explicit settings are persisted.
|
||||
@@ -129,6 +131,12 @@ func (p Preferences) stored() Preferences {
|
||||
if p.Color == defaults.Color {
|
||||
p.Color = ""
|
||||
}
|
||||
if p.Hyperlinks == defaults.Hyperlinks {
|
||||
p.Hyperlinks = ""
|
||||
}
|
||||
if p.Markdown == defaults.Markdown {
|
||||
p.Markdown = ""
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
@@ -247,6 +255,12 @@ func (s Snapshot) Validate() error {
|
||||
if p.Color != "auto" && p.Color != "always" && p.Color != "never" {
|
||||
return errors.New("color must be auto, always, or never")
|
||||
}
|
||||
if p.Hyperlinks != "auto" && p.Hyperlinks != "always" && p.Hyperlinks != "never" {
|
||||
return errors.New("hyperlinks must be auto, always, or never")
|
||||
}
|
||||
if p.Markdown != "auto" && p.Markdown != "raw" {
|
||||
return errors.New("markdown must be auto or raw")
|
||||
}
|
||||
if p.DefaultHost != "" {
|
||||
normalized, err := NormalizeHost(p.DefaultHost)
|
||||
if err != nil || normalized != p.DefaultHost {
|
||||
|
||||
@@ -120,7 +120,7 @@ func TestUpdatePersistsOnlyExplicitPreferences(t *testing.T) {
|
||||
snapshot, err := s.Load()
|
||||
require.NoError(t, err)
|
||||
require.True(t, snapshot.Configured["editor"])
|
||||
for _, key := range []string{"git_protocol", "prompt", "color", "aliases"} {
|
||||
for _, key := range []string{"git_protocol", "prompt", "color", "hyperlinks", "markdown", "aliases"} {
|
||||
require.False(t, snapshot.Configured[key], key)
|
||||
}
|
||||
require.Equal(t, Defaults().GitProtocol, snapshot.Preferences.GitProtocol)
|
||||
@@ -130,6 +130,25 @@ func TestUpdatePersistsOnlyExplicitPreferences(t *testing.T) {
|
||||
require.Equal(t, "version: \"1\"\neditor: vi\ncolor: never\n", string(data))
|
||||
}
|
||||
|
||||
func TestDisplayPreferencesAcceptOnlyTheirValues(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
config string
|
||||
valid bool
|
||||
}{
|
||||
{"hyperlinks: never\n", true},
|
||||
{"hyperlinks: always\nmarkdown: raw\n", true},
|
||||
{"hyperlinks: off\n", false},
|
||||
{"markdown: never\n", false},
|
||||
} {
|
||||
t.Run(tc.config, func(t *testing.T) {
|
||||
s := New(t.TempDir())
|
||||
require.NoError(t, os.WriteFile(filepath.Join(s.Dir, "config.yml"), []byte("version: '1'\n"+tc.config), 0o600))
|
||||
_, err := s.Load()
|
||||
require.Equal(t, tc.valid, err == nil, "%v", err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTokenlessAccounts(t *testing.T) {
|
||||
for method, want := range map[string]bool{AuthToken: false, AuthOAuth: false, AuthSSH: true, AuthHTTPSign: true} {
|
||||
require.Equal(t, want, Account{AuthMethod: method}.Tokenless(), method)
|
||||
|
||||
Reference in new issue
Block a user