fix(cli): use correct exit codes

This commit is contained in:
Jan De Dobbeleer 2024-03-11 10:02:46 +01:00 committed by Jan De Dobbeleer
parent 17dd5c8b58
commit 67042ffa50
4 changed files with 11 additions and 4 deletions

View file

@ -44,6 +44,11 @@ Exports the ~/myconfig.omp.json config file to toml and prints the result to std
defer env.Close()
cfg := engine.LoadConfig(env)
if len(output) == 0 && len(format) == 0 {
// usage error
os.Exit(2)
}
if len(output) == 0 {
fmt.Print(cfg.Export(format))
return
@ -63,7 +68,8 @@ Exports the ~/myconfig.omp.json config file to toml and prints the result to std
case "yaml", "yml":
format = engine.YAML
default:
os.Exit(1)
// data error
os.Exit(65)
}
cfg.Write(format)

View file

@ -36,7 +36,8 @@ on getting started, have a look at the docs at https://ohmyposh.dev`,
func Execute() {
if err := RootCmd.Execute(); err != nil {
os.Exit(1)
// software error
os.Exit(70)
}
}

View file

@ -220,7 +220,7 @@ func (cfg *Config) Write(format string) {
content := cfg.Export(format)
if len(content) == 0 {
// we are unable to perform the export
os.Exit(1)
os.Exit(65)
return
}

View file

@ -272,6 +272,6 @@ func Run(font string, system bool) {
program = tea.NewProgram(main)
if _, err := program.Run(); err != nil {
print("Error running program: %v", err)
os.Exit(1)
os.Exit(70)
}
}