fix(config): handle defaults when using default config
This commit is contained in:
parent
5217df9d97
commit
4fe62a8b1d
3 changed files with 21 additions and 20 deletions
|
|
@ -21,7 +21,6 @@ type (
|
|||
}
|
||||
|
||||
Identify struct {
|
||||
Status discord.Status `toml:"status"`
|
||||
}
|
||||
|
||||
Notifications struct {
|
||||
|
|
@ -39,6 +38,8 @@ type (
|
|||
Mouse bool `toml:"mouse"`
|
||||
Editor string `toml:"editor"`
|
||||
|
||||
Status discord.Status `toml:"status"`
|
||||
|
||||
Markdown bool `toml:"markdown"`
|
||||
HideBlockedUsers bool `toml:"hide_blocked_users"`
|
||||
ShowAttachmentLinks bool `toml:"show_attachment_links"`
|
||||
|
|
@ -87,21 +88,25 @@ func Load(path string) (*Config, error) {
|
|||
"err",
|
||||
err,
|
||||
)
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open config file: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
if _, err := toml.NewDecoder(file).Decode(&cfg); err != nil {
|
||||
return nil, fmt.Errorf("failed to decode config: %w", err)
|
||||
} else {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open config file: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
if _, err := toml.NewDecoder(file).Decode(&cfg); err != nil {
|
||||
return nil, fmt.Errorf("failed to decode config: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// set defaults
|
||||
if cfg.Editor == "default" {
|
||||
cfg.Editor = os.Getenv("EDITOR")
|
||||
}
|
||||
|
||||
if cfg.Status == "default" {
|
||||
cfg.Status = ""
|
||||
}
|
||||
|
||||
return &cfg, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ mouse = true
|
|||
# The program to open when the `keys.message_input.editor` keymap is pressed. Set the value to `"default"` to use `$EDITOR`.
|
||||
editor = "default"
|
||||
|
||||
# "default" (unknown), "online", "dnd", "idle", "invisible", "offline"
|
||||
status = "default"
|
||||
|
||||
# Whether to parse and render markdown in messages or not.
|
||||
markdown = true
|
||||
hide_blocked_users = true
|
||||
|
|
@ -28,15 +31,6 @@ duration = 0
|
|||
enabled = true
|
||||
only_on_ping = true
|
||||
|
||||
# How Discord sees us.
|
||||
# status: "online", "idle", "dnd" (Do Not Disturb), "" (invisible),
|
||||
# note: does not seem to work
|
||||
[identify]
|
||||
status = "online"
|
||||
browser = "default"
|
||||
browser_version = "default"
|
||||
user_agent = "default"
|
||||
|
||||
# Global shortcuts
|
||||
# Esc: Reset message selection or close the channel selection popup.
|
||||
[keys]
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ type (
|
|||
SelectCurrent string `toml:"select_current"`
|
||||
YankID string `toml:"yank_id"`
|
||||
|
||||
CollapseAll string `toml:"collapse_all"`
|
||||
ExpandAll string `toml:"expand_all"`
|
||||
CollapseParentNode string `toml:"collapse_parent_node"`
|
||||
MoveToParentNode string `toml:"move_to_parent_node"`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue