Need help troubleshooting #922
-
Hi there, I'm new to go-toml and I'm trying to set up a config parser for a CLI tool that I'm working on. I can't seem to understand why go-toml isn't behaving as I expect. Here is the .toml file that I am reading in: [session.name]
prepend_parent_dir = true
default_startup_script = "~/git_repos/dotfiles/bin/sesh/scripts/default.sh"
[[startup_scripts]]
session_path = "~/git_repos/sesh"
script_path = "~/git_repos/dotfiles/bin/sesh/scripts/sesh.sh" and here is the accompanying Go code: type (
SessionName struct {
PrependParentDir bool `toml:"prepend_parent_dir"`
}
Session struct {
Name SessionName
}
Script struct {
SessionPath string `toml:"session_path"`
ScriptPath string `toml:"script_path"`
}
Config struct {
Session Session
StartupScripts []Script `toml:"startup_scripts"`
DefaultStartupScript string `toml:"default_startup_script"`
}
)
func ParseConfigFile() Config {
configDir, err := os.UserConfigDir()
config := Config{}
if err != nil {
fmt.Printf(
"Error determining the user config directory: %s\nUsing default config instead",
err,
)
return config
}
configPath := filepath.Join(configDir, "sesh", "sesh.toml")
data, err := os.ReadFile(configPath)
if err != nil {
return config
}
err = toml.Unmarshal(data, &config)
if err != nil {
fmt.Printf(
"Error parsing config file: %s\nUsing default config instead",
err,
)
return config
}
return config
} When I toss a And I would expect to instead get: If anyone happens to see something wrong with what I'm doing, I would greatly appreciate if you could point it out to me. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Of course I figured it out after posting! I was expecting |
Beta Was this translation helpful? Give feedback.
Of course I figured it out after posting!
I was expecting
os.UserConfigDir()
to return ~/.config on MacOS, but that was not the case.