From a5a58dfd3208690d3640275878efb311681cbe86 Mon Sep 17 00:00:00 2001 From: CronyAkatsuki Date: Sat, 11 Nov 2023 20:14:44 +0100 Subject: [PATCH] Print out help message. Print our help message when run with no argument's or --help|-h. --- main.go | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 2f4e98a..5d71e49 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,21 @@ import ( miniflux "miniflux.app/client" ) +// Help message +const HELP = `examples: + mfeed create {category_id} {feed_url} + +usage: mfeed [-h] {feeds,categories,create} ... + feeds list all the feeds you have + categories list all the categories you have + create create a new feed + +positional arguments: + {feeds, categories, create} + +options: + -h, --help shows this help page` + // Crreate the config struct type Configuration struct { Instance string @@ -18,6 +33,18 @@ type Configuration struct { } func main() { + // print help message based on first argument + if len(os.Args) < 2 { + fmt.Println(HELP) + return + } else if os.Args[1] == "-h" { + fmt.Println(HELP) + return + } else if os.Args[1] == "--help" { + fmt.Println(HELP) + return + } + // get config folder locaation config_dir, _ := os.UserConfigDir() @@ -51,12 +78,6 @@ func main() { string(pass), ) - // check if atleast one option is provided - if len(os.Args) < 2 { - fmt.Println("No option provided!") - return - } - // Run fuction based on first argument switch os.Args[1] { case "feeds":