From 67042ffa5049cbdf21c14d2247db1d24458c81de Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Mon, 11 Mar 2024 10:02:46 +0100 Subject: [PATCH] fix(cli): use correct exit codes --- src/cli/config_export.go | 8 +++++++- src/cli/root.go | 3 ++- src/engine/config.go | 2 +- src/font/cli.go | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/cli/config_export.go b/src/cli/config_export.go index 4b1aacf5..67af7573 100644 --- a/src/cli/config_export.go +++ b/src/cli/config_export.go @@ -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) diff --git a/src/cli/root.go b/src/cli/root.go index 16715c64..5660c3e6 100644 --- a/src/cli/root.go +++ b/src/cli/root.go @@ -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) } } diff --git a/src/engine/config.go b/src/engine/config.go index 4c9f1a2a..909550fc 100644 --- a/src/engine/config.go +++ b/src/engine/config.go @@ -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 } diff --git a/src/font/cli.go b/src/font/cli.go index 72e84722..421bd197 100644 --- a/src/font/cli.go +++ b/src/font/cli.go @@ -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) } }