1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Move responsibility for version display out of flags

This commit is contained in:
Chris Cummer 2018-06-16 08:37:55 -07:00
parent 4a00c114ce
commit dd42080ed8
3 changed files with 13 additions and 10 deletions

View File

@ -12,7 +12,7 @@ import (
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'"`
Version bool `short:"v" long:"version" description:"Show Version Info"` Version bool `short:"v" long:"version" description:"Show version info"`
} }
func NewFlags() *Flags { func NewFlags() *Flags {
@ -30,6 +30,10 @@ func (flags *Flags) HasModule() bool {
return len(flags.Module) > 0 return len(flags.Module) > 0
} }
func (flags *Flags) HasVersion() bool {
return flags.Version == true
}
func (flags *Flags) Parse(version string) { func (flags *Flags) Parse(version string) {
parser := goFlags.NewParser(flags, goFlags.Default) parser := goFlags.NewParser(flags, goFlags.Default)
if _, err := parser.Parse(); err != nil { if _, err := parser.Parse(); err != nil {
@ -41,14 +45,10 @@ func (flags *Flags) Parse(version string) {
if !flags.HasConfig() { if !flags.HasConfig() {
homeDir, err := wtf.Home() homeDir, err := wtf.Home()
if err != nil { if err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1) os.Exit(1)
} }
flags.Config = filepath.Join(homeDir, ".wtf", "config.yml") flags.Config = filepath.Join(homeDir, ".wtf", "config.yml")
} }
if flags.Version {
fmt.Printf("Version: %s\n", version)
os.Exit(0)
}
} }

View File

@ -2,7 +2,6 @@ package help
import ( import (
"fmt" "fmt"
"os"
"github.com/senorprogrammer/wtf/git" "github.com/senorprogrammer/wtf/git"
"github.com/senorprogrammer/wtf/github" "github.com/senorprogrammer/wtf/github"
@ -17,8 +16,6 @@ func Display(moduleName string) {
} else { } else {
fmt.Printf("%s\n", helpFor(moduleName)) fmt.Printf("%s\n", helpFor(moduleName))
} }
os.Exit(0)
} }
func helpFor(moduleName string) string { func helpFor(moduleName string) string {

8
wtf.go
View File

@ -266,6 +266,12 @@ func main() {
if flags.HasModule() { if flags.HasModule() {
help.Display(flags.Module) help.Display(flags.Module)
os.Exit(0)
}
if flags.HasVersion() {
fmt.Println(version)
os.Exit(0)
} }
cfg.CreateConfigDir() cfg.CreateConfigDir()
@ -289,7 +295,7 @@ func main() {
go watchForConfigChanges(app, flags.Config, display.Grid, pages) go watchForConfigChanges(app, flags.Config, display.Grid, pages)
if err := app.SetRoot(pages, true).Run(); err != nil { if err := app.SetRoot(pages, true).Run(); err != nil {
fmt.Printf("An error occurred: %v\n", err) fmt.Printf("Error: %v\n", err)
os.Exit(1) os.Exit(1)
} }