argv autocomplete is fun!
This commit is contained in:
parent
ad2c2ff2ec
commit
a991a4c187
30
argv.go
30
argv.go
|
@ -36,8 +36,6 @@ type args struct {
|
||||||
BuildForge bool `arg:"--forge-rebuild" help:"download and rebuild forge"`
|
BuildForge bool `arg:"--forge-rebuild" help:"download and rebuild forge"`
|
||||||
Force bool `arg:"--force" help:"try to strong arm things"`
|
Force bool `arg:"--force" help:"try to strong arm things"`
|
||||||
Verbose bool `arg:"--verbose" help:"show more output"`
|
Verbose bool `arg:"--verbose" help:"show more output"`
|
||||||
Bash bool `arg:"--bash" help:"generate bash completion"`
|
|
||||||
BashAuto []string `arg:"--auto-complete" help:"todo: move this to go-arg"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmptyCmd struct {
|
type EmptyCmd struct {
|
||||||
|
@ -148,6 +146,7 @@ forge -- a tool to manage lots of git repos. forge includes a GUI and TUI.
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func (args) doBashHelpDebug() {
|
func (args) doBashHelpDebug() {
|
||||||
fmt.Fprintln(os.Stderr, "")
|
fmt.Fprintln(os.Stderr, "")
|
||||||
fmt.Fprintln(os.Stderr, "hello world")
|
fmt.Fprintln(os.Stderr, "hello world")
|
||||||
|
@ -164,6 +163,7 @@ func (args) doBashHelpDebug() {
|
||||||
fmt.Fprintln(os.Stderr, "pull something else", argv.BashAuto, len(argv.BashAuto), p0, p1, p2, p1a, "end", more)
|
fmt.Fprintln(os.Stderr, "pull something else", argv.BashAuto, len(argv.BashAuto), p0, p1, p2, p1a, "end", more)
|
||||||
fmt.Fprintln(os.Stderr, "")
|
fmt.Fprintln(os.Stderr, "")
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
handles shell autocomplete
|
handles shell autocomplete
|
||||||
|
@ -177,14 +177,15 @@ func deleteMatch() {
|
||||||
fmt.Println("go.wit.com/lib/gui/repostatus todo: need to do this")
|
fmt.Println("go.wit.com/lib/gui/repostatus todo: need to do this")
|
||||||
}
|
}
|
||||||
|
|
||||||
func ifBlank() bool {
|
func ifBlank(arg string) bool {
|
||||||
if argv.BashAuto[1] == "''" {
|
if arg == "''" {
|
||||||
// if empty, the user has not typed something
|
// if empty, the user has not typed something
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
// prints help to STDERR // TODO: move everything below this to go-args
|
// prints help to STDERR // TODO: move everything below this to go-args
|
||||||
func (args) doBashHelp() {
|
func (args) doBashHelp() {
|
||||||
if argv.BashAuto[1] != "''" {
|
if argv.BashAuto[1] != "''" {
|
||||||
|
@ -204,9 +205,20 @@ func (args) doBashHelp() {
|
||||||
fmt.Fprintln(os.Stderr, "")
|
fmt.Fprintln(os.Stderr, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (args) doBashAuto() {
|
func (a args) doBashAuto() {
|
||||||
// argv.doBashHelp()
|
DoAutoComplete(argv.BashAuto)
|
||||||
switch argv.BashAuto[0] {
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
func (a args) DoAutoComplete(argv []string) {
|
||||||
|
DoAutoComplete(argv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func DoAutoComplete(argv []string) {
|
||||||
|
// fmt.Fprintln(os.Stderr, "") // these are for debugging
|
||||||
|
// fmt.Fprintln(os.Stderr, "in autocomplete:", argv) // these are for debugging
|
||||||
|
switch argv[0] {
|
||||||
case "checkout":
|
case "checkout":
|
||||||
fmt.Println("devel master user")
|
fmt.Println("devel master user")
|
||||||
case "clean":
|
case "clean":
|
||||||
|
@ -224,7 +236,7 @@ func (args) doBashAuto() {
|
||||||
case "dirty":
|
case "dirty":
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
case "gui":
|
case "gui":
|
||||||
if ifBlank() {
|
if ifBlank(argv[1]) {
|
||||||
fmt.Fprintln(os.Stderr, "")
|
fmt.Fprintln(os.Stderr, "")
|
||||||
fmt.Fprintln(os.Stderr, "CUI: terminal interface using 'gocui'")
|
fmt.Fprintln(os.Stderr, "CUI: terminal interface using 'gocui'")
|
||||||
fmt.Fprintln(os.Stderr, "GUI: linux and macos GUI using GTK")
|
fmt.Fprintln(os.Stderr, "GUI: linux and macos GUI using GTK")
|
||||||
|
@ -250,7 +262,7 @@ func (args) doBashAuto() {
|
||||||
case "verify":
|
case "verify":
|
||||||
fmt.Println("user devel master")
|
fmt.Println("user devel master")
|
||||||
default:
|
default:
|
||||||
if argv.BashAuto[0] == ARGNAME {
|
if argv[0] == ARGNAME {
|
||||||
// list the subcommands here
|
// list the subcommands here
|
||||||
fmt.Println("help list checkout clean commit dirty debug fetch gui normal merge patch pull")
|
fmt.Println("help list checkout clean commit dirty debug fetch gui normal merge patch pull")
|
||||||
}
|
}
|
||||||
|
|
10
main.go
10
main.go
|
@ -14,7 +14,7 @@ import (
|
||||||
|
|
||||||
"go.wit.com/dev/alexflint/arg"
|
"go.wit.com/dev/alexflint/arg"
|
||||||
"go.wit.com/gui"
|
"go.wit.com/gui"
|
||||||
"go.wit.com/lib/fhelp"
|
"go.wit.com/lib/gui/prep"
|
||||||
"go.wit.com/lib/gui/shell"
|
"go.wit.com/lib/gui/shell"
|
||||||
"go.wit.com/lib/protobuf/forgepb"
|
"go.wit.com/lib/protobuf/forgepb"
|
||||||
"go.wit.com/lib/protobuf/gitpb"
|
"go.wit.com/lib/protobuf/gitpb"
|
||||||
|
@ -47,9 +47,11 @@ func getVersion(repo *gitpb.Repo, name string) string {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
me = new(mainType)
|
me = new(mainType)
|
||||||
gui.InitArg()
|
prep.Bash(ARGNAME, argv.DoAutoComplete) // this line should be: prep.Bash(argv)
|
||||||
|
me.myGui = prep.Gui() // prepares the GUI package for go-args
|
||||||
me.pp = arg.MustParse(&argv)
|
me.pp = arg.MustParse(&argv)
|
||||||
|
|
||||||
|
/*
|
||||||
if argv.Bash {
|
if argv.Bash {
|
||||||
fhelp.DoBash(ARGNAME)
|
fhelp.DoBash(ARGNAME)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
@ -58,6 +60,7 @@ func main() {
|
||||||
argv.doBashAuto()
|
argv.doBashAuto()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
me.urlbase = argv.URL
|
me.urlbase = argv.URL
|
||||||
if me.urlbase == "" {
|
if me.urlbase == "" {
|
||||||
me.urlbase = "https://go.wit.com/"
|
me.urlbase = "https://go.wit.com/"
|
||||||
|
@ -185,7 +188,6 @@ func main() {
|
||||||
okExit("")
|
okExit("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// if you are in "normal" mode, always run normal every time to catch accidental errors
|
// if you are in "normal" mode, always run normal every time to catch accidental errors
|
||||||
// for example, if you accidentally changed branches from your user branch
|
// for example, if you accidentally changed branches from your user branch
|
||||||
if me.forge.Config.Mode == forgepb.ForgeMode_NORMAL {
|
if me.forge.Config.Mode == forgepb.ForgeMode_NORMAL {
|
||||||
|
@ -194,7 +196,6 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if argv.Merge != nil {
|
if argv.Merge != nil {
|
||||||
if argv.Merge.Devel != nil {
|
if argv.Merge.Devel != nil {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
@ -243,7 +244,6 @@ func main() {
|
||||||
okExit("")
|
okExit("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// if the user doesn't want to open the GUI and
|
// if the user doesn't want to open the GUI and
|
||||||
// nothing else was specified to be done,
|
// nothing else was specified to be done,
|
||||||
// then just list the table to stdout
|
// then just list the table to stdout
|
||||||
|
|
Loading…
Reference in New Issue