mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
now flags support both short and long names.
This commit is contained in:
parent
55fe6fe9e1
commit
128347e513
26
wtf.go
26
wtf.go
@ -1,13 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
|
flags "github.com/jessevdk/go-flags"
|
||||||
"github.com/olebedev/config"
|
"github.com/olebedev/config"
|
||||||
"github.com/radovskyb/watcher"
|
"github.com/radovskyb/watcher"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
@ -214,17 +214,19 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
flagConf := flag.String("config", filepath.Join(homeDir, ".wtf", "config.yml"), "Path to config file")
|
var cmdFlags struct {
|
||||||
flagHelp := flag.Bool("help", false, "Show help")
|
Version bool `short:"v" long:"version" description:"Show Version Info"`
|
||||||
flagVers := flag.Bool("version", false, "Show version info")
|
Config string `short:"c" long:"config" optional:"yes" description:"Path to config file"`
|
||||||
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
if *flagHelp {
|
|
||||||
help.DisplayHelpInfo(flag.Args())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if *flagVers {
|
var parser = flags.NewParser(&cmdFlags, flags.Default)
|
||||||
|
parser.Parse()
|
||||||
|
|
||||||
|
if len(cmdFlags.Config) == 0 {
|
||||||
|
cmdFlags.Config = filepath.Join(homeDir, ".wtf", "config.yml")
|
||||||
|
}
|
||||||
|
|
||||||
|
if cmdFlags.Version {
|
||||||
help.DisplayVersionInfo(version)
|
help.DisplayVersionInfo(version)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +237,7 @@ func main() {
|
|||||||
wtf.CreateConfigDir()
|
wtf.CreateConfigDir()
|
||||||
wtf.WriteConfigFile()
|
wtf.WriteConfigFile()
|
||||||
|
|
||||||
loadConfig(flagConf)
|
loadConfig(&cmdFlags.Config)
|
||||||
|
|
||||||
app := tview.NewApplication()
|
app := tview.NewApplication()
|
||||||
pages := tview.NewPages()
|
pages := tview.NewPages()
|
||||||
@ -248,7 +250,7 @@ func main() {
|
|||||||
|
|
||||||
// Loop in a routine to redraw the screen
|
// Loop in a routine to redraw the screen
|
||||||
go redrawApp(app)
|
go redrawApp(app)
|
||||||
go watchForConfigChanges(app, flagConf, grid, pages)
|
go watchForConfigChanges(app, &cmdFlags.Config, grid, pages)
|
||||||
|
|
||||||
if err := app.SetRoot(pages, true).Run(); err != nil {
|
if err := app.SetRoot(pages, true).Run(); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user