From 49afd7c16b4b083ba7b16313b8a6d8981af65298 Mon Sep 17 00:00:00 2001 From: Chris Lane Date: Thu, 25 Jun 2020 18:38:03 -0400 Subject: [PATCH] feat: modify return codes Modify exit codes. `cheat` now returns an exit code value `2` on errors pertaining to a cheatsheet not being found. BREAKING CHANGE --- cmd/cheat/cmd_list.go | 4 ++-- cmd/cheat/cmd_remove.go | 4 ++-- cmd/cheat/cmd_search.go | 2 +- cmd/cheat/cmd_view.go | 2 +- doc/cheat.1 | 7 +++++++ doc/cheat.1.md | 9 +++++++++ 6 files changed, 22 insertions(+), 6 deletions(-) diff --git a/cmd/cheat/cmd_list.go b/cmd/cheat/cmd_list.go index 2e41a25..502fa80 100644 --- a/cmd/cheat/cmd_list.go +++ b/cmd/cheat/cmd_list.go @@ -81,9 +81,9 @@ func cmdList(opts map[string]interface{}, conf config.Config) { flattened = filtered } - // exit early if no cheatsheets are available + // return exit code 2 if no cheatsheets are available if len(flattened) == 0 { - os.Exit(0) + os.Exit(2) } // initialize a tabwriter to produce cleanly columnized output diff --git a/cmd/cheat/cmd_remove.go b/cmd/cheat/cmd_remove.go index caaa09a..072e525 100644 --- a/cmd/cheat/cmd_remove.go +++ b/cmd/cheat/cmd_remove.go @@ -37,8 +37,8 @@ func cmdRemove(opts map[string]interface{}, conf config.Config) { // fail early if the requested cheatsheet does not exist sheet, ok := consolidated[cheatsheet] if !ok { - fmt.Fprintln(os.Stderr, fmt.Sprintf("no cheatsheet found for '%s'.\n", cheatsheet)) - os.Exit(1) + fmt.Fprintln(os.Stderr, fmt.Sprintf("No cheatsheet found for '%s'.\n", cheatsheet)) + os.Exit(2) } // fail early if the sheet is read-only diff --git a/cmd/cheat/cmd_search.go b/cmd/cheat/cmd_search.go index f497831..3606b88 100644 --- a/cmd/cheat/cmd_search.go +++ b/cmd/cheat/cmd_search.go @@ -46,7 +46,7 @@ func cmdSearch(opts map[string]interface{}, conf config.Config) { s, ok := consolidated[cheatsheet] if !ok { fmt.Printf("No cheatsheet found for '%s'.\n", cheatsheet) - os.Exit(0) + os.Exit(2) } consolidated = map[string]sheet.Sheet{ diff --git a/cmd/cheat/cmd_view.go b/cmd/cheat/cmd_view.go index 3e0aade..2f4c550 100644 --- a/cmd/cheat/cmd_view.go +++ b/cmd/cheat/cmd_view.go @@ -39,7 +39,7 @@ func cmdView(opts map[string]interface{}, conf config.Config) { sheet, ok := consolidated[cheatsheet] if !ok { fmt.Printf("No cheatsheet found for '%s'.\n", cheatsheet) - os.Exit(0) + os.Exit(2) } // apply colorization if requested diff --git a/doc/cheat.1 b/doc/cheat.1 index 5b2c932..cc19064 100644 --- a/doc/cheat.1 +++ b/doc/cheat.1 @@ -203,6 +203,13 @@ If set, autocompletion scripts will attempt to integrate with \f[B]fzf\f[]. .RS .RE +.SH RETURN VALUES +.IP "0." 3 +Successful termination +.IP "1." 3 +Application error +.IP "2." 3 +Cheatsheet(s) not found .SH BUGS .PP See GitHub issues: diff --git a/doc/cheat.1.md b/doc/cheat.1.md index f587195..eb9c1ae 100644 --- a/doc/cheat.1.md +++ b/doc/cheat.1.md @@ -163,6 +163,15 @@ set, all other config paths will be ignored. : If set, autocompletion scripts will attempt to integrate with **fzf**. +RETURN VALUES +============= + +0. Successful termination + +1. Application error + +2. Cheatsheet(s) not found + BUGS ====