From c6ab669edffb32ee09809a9cea18d79fd0651937 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Fri, 28 Jun 2019 21:35:08 -0700 Subject: [PATCH] Improve the documentation in /flags --- flags/flags.go | 11 ++++++++++- main.go | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/flags/flags.go b/flags/flags.go index 1c3db2f1..992c343a 100644 --- a/flags/flags.go +++ b/flags/flags.go @@ -11,6 +11,7 @@ import ( "github.com/wtfutil/wtf/utils" ) +// Flags is the container for command line flag data type Flags struct { Config string `short:"c" long:"config" optional:"yes" description:"Path to config file"` Module string `short:"m" long:"module" optional:"yes" description:"Display info about a specific module, i.e.: 'wtf -m=todo'"` @@ -18,6 +19,7 @@ type Flags struct { Version bool `short:"v" long:"version" description:"Show version info"` } +// NewFlags creates an instance of Flags func NewFlags() *Flags { flags := Flags{} return &flags @@ -25,11 +27,14 @@ func NewFlags() *Flags { /* -------------------- Exported Functions -------------------- */ +// ConfigFilePath returns the path to the currently-loaded config file func (flags *Flags) ConfigFilePath() string { return flags.Config } -func (flags *Flags) Display(version string, config *config.Config) { +// RenderIf displays special-case information based on the flags passed +// in, if any flags were passed in +func (flags *Flags) RenderIf(version string, config *config.Config) { if flags.HasModule() { help.Display(flags.Module, config) os.Exit(0) @@ -41,18 +46,22 @@ func (flags *Flags) Display(version string, config *config.Config) { } } +// HasConfig returns TRUE if a config path was passed in, FALSE if one was not func (flags *Flags) HasConfig() bool { return len(flags.Config) > 0 } +// HasModule returns TRUE if a module name was passed in, FALSE if one was not func (flags *Flags) HasModule() bool { return len(flags.Module) > 0 } +// HasVersion returns TRUE if the version flag was passed in, FALSE if it was not func (flags *Flags) HasVersion() bool { return flags.Version == true } +// Parse parses the incoming flags func (flags *Flags) Parse() { parser := goFlags.NewParser(flags, goFlags.Default) if _, err := parser.Parse(); err != nil { diff --git a/main.go b/main.go index f45f5706..6f132563 100644 --- a/main.go +++ b/main.go @@ -127,10 +127,11 @@ func watchForConfigChanges(app *tview.Application, configFilePath string, grid * func main() { log.SetFlags(log.LstdFlags | log.Lshortfile) + // Parse and handle flags flags := flags.NewFlags() flags.Parse() config := cfg.LoadConfigFile(flags.ConfigFilePath()) - flags.Display(version, config) + flags.RenderIf(version, config) cfg.MigrateOldConfig() cfg.CreateConfigDir()