mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Improve the documentation in /flags
This commit is contained in:
parent
9a9f3804e8
commit
c6ab669edf
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/wtfutil/wtf/utils"
|
"github.com/wtfutil/wtf/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Flags is the container for command line flag data
|
||||||
type Flags struct {
|
type Flags struct {
|
||||||
Config string `short:"c" long:"config" optional:"yes" description:"Path to config file"`
|
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'"`
|
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"`
|
Version bool `short:"v" long:"version" description:"Show version info"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewFlags creates an instance of Flags
|
||||||
func NewFlags() *Flags {
|
func NewFlags() *Flags {
|
||||||
flags := Flags{}
|
flags := Flags{}
|
||||||
return &flags
|
return &flags
|
||||||
@ -25,11 +27,14 @@ func NewFlags() *Flags {
|
|||||||
|
|
||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
|
// ConfigFilePath returns the path to the currently-loaded config file
|
||||||
func (flags *Flags) ConfigFilePath() string {
|
func (flags *Flags) ConfigFilePath() string {
|
||||||
return flags.Config
|
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() {
|
if flags.HasModule() {
|
||||||
help.Display(flags.Module, config)
|
help.Display(flags.Module, config)
|
||||||
os.Exit(0)
|
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 {
|
func (flags *Flags) HasConfig() bool {
|
||||||
return len(flags.Config) > 0
|
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 {
|
func (flags *Flags) HasModule() bool {
|
||||||
return len(flags.Module) > 0
|
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 {
|
func (flags *Flags) HasVersion() bool {
|
||||||
return flags.Version == true
|
return flags.Version == true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse parses the incoming flags
|
||||||
func (flags *Flags) Parse() {
|
func (flags *Flags) Parse() {
|
||||||
parser := goFlags.NewParser(flags, goFlags.Default)
|
parser := goFlags.NewParser(flags, goFlags.Default)
|
||||||
if _, err := parser.Parse(); err != nil {
|
if _, err := parser.Parse(); err != nil {
|
||||||
|
3
main.go
3
main.go
@ -127,10 +127,11 @@ func watchForConfigChanges(app *tview.Application, configFilePath string, grid *
|
|||||||
func main() {
|
func main() {
|
||||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||||
|
|
||||||
|
// Parse and handle flags
|
||||||
flags := flags.NewFlags()
|
flags := flags.NewFlags()
|
||||||
flags.Parse()
|
flags.Parse()
|
||||||
config := cfg.LoadConfigFile(flags.ConfigFilePath())
|
config := cfg.LoadConfigFile(flags.ConfigFilePath())
|
||||||
flags.Display(version, config)
|
flags.RenderIf(version, config)
|
||||||
|
|
||||||
cfg.MigrateOldConfig()
|
cfg.MigrateOldConfig()
|
||||||
cfg.CreateConfigDir()
|
cfg.CreateConfigDir()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user