From 19dc9d7bbc398a40b8dbc17fde0d1fa0fe68a0f7 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Sun, 17 Sep 2017 22:11:26 -0400 Subject: [PATCH] Fix options and make usage text much more readable Now micro -h will just show you the important information and if you want to see each individual option's help text use micro -options. --- cmd/micro/micro.go | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index 46f9f7cf..d2fc5227 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -250,23 +250,31 @@ func LoadAll() { var flagVersion = flag.Bool("version", false, "Show the version number and information") var flagStartPos = flag.String("startpos", "", "LINE,COL to start the cursor at when opening a buffer.") var flagConfigDir = flag.String("config-dir", "", "Specify a custom location for the configuration directory") -var optionFlagSet = flag.NewFlagSet("option", flag.ExitOnError) +var flagOptions = flag.Bool("options", false, "Show all option help") func main() { flag.Usage = func() { fmt.Println("Usage: micro [OPTIONS] [FILE]...") - flag.CommandLine.SetOutput(os.Stdout) - flag.PrintDefaults() - optionFlagSet.SetOutput(os.Stdout) - fmt.Print("\n------------------------------------------------------------------\n") - fmt.Print("Micro's options can also be set via command line arguments for quick\nadjustments. For real configuration, please use the bindings.json\nfile (see 'help options').\n\n") - optionFlagSet.PrintDefaults() + fmt.Println("-config-dir dir") + fmt.Println(" \tSpecify a custom location for the configuration directory") + fmt.Println("-startpos LINE,COL") + fmt.Println(" \tSpecify a line and column to start the cursor at when opening a buffer") + fmt.Println("-options") + fmt.Println(" \tShow all option help") + fmt.Println("-version") + fmt.Println(" \tShow the version number and information") + + fmt.Print("\nMicro's options can also be set via command line arguments for quick\nadjustments. For real configuration, please use the bindings.json\nfile (see 'help options').\n\n") + fmt.Println("-option value") + fmt.Println(" \tSet `option` to `value` for this session") + fmt.Println(" \tFor example: `micro -syntax off file.c`") + fmt.Println("\nUse `micro -options` to see the full list of configuration options") } optionFlags := make(map[string]*string) for k, v := range DefaultGlobalSettings() { - optionFlags[k] = optionFlagSet.String(k, "", fmt.Sprintf("The %s option. Default value: '%v'", k, v)) + optionFlags[k] = flag.String(k, "", fmt.Sprintf("The %s option. Default value: '%v'", k, v)) } flag.Parse() @@ -279,6 +287,15 @@ func main() { os.Exit(0) } + if *flagOptions { + // If -options was passed + for k, v := range DefaultGlobalSettings() { + fmt.Printf("-%s value\n", k) + fmt.Printf(" \tThe %s option. Default value: '%v'\n", k, v) + } + os.Exit(0) + } + // Start the Lua VM for running plugins L = lua.NewState() defer L.Close()