more argv cleanups
This commit is contained in:
parent
362ea63b97
commit
ec8a3688eb
2
Makefile
2
Makefile
|
@ -11,7 +11,7 @@ info: install
|
|||
@echo "make dirty # CheckDirty()"
|
||||
@echo "make user # git checkout user"
|
||||
@echo "make master # git checkout master"
|
||||
forge
|
||||
# forge
|
||||
|
||||
vet:
|
||||
@GO111MODULE=off go vet
|
||||
|
|
64
argv.go
64
argv.go
|
@ -35,13 +35,13 @@ type FindCmd struct {
|
|||
}
|
||||
|
||||
type args struct {
|
||||
List *FindCmd `arg:"subcommand:list" help:"just show a table of the current state"`
|
||||
Dirty *EmptyCmd `arg:"subcommand:dirty" help:"check if your git repos are dirty"`
|
||||
User *FindCmd `arg:"subcommand:user" help:"git checkout user"`
|
||||
Devel *FindCmd `arg:"subcommand:devel" help:"git checkout devel"`
|
||||
Master *FindCmd `arg:"subcommand:master" help:"git checkout master"`
|
||||
List *FindCmd `arg:"subcommand:list" help:"just show a table of the current state"`
|
||||
Dirty *EmptyCmd `arg:"subcommand:dirty" help:"check if your git repos are dirty"`
|
||||
// User *FindCmd `arg:"subcommand:user" help:"git checkout user"`
|
||||
// Devel *FindCmd `arg:"subcommand:devel" help:"git checkout devel"`
|
||||
// Master *FindCmd `arg:"subcommand:master" help:"git checkout master"`
|
||||
Checkout *CheckoutCmd `arg:"subcommand:checkout" help:"switch git branches"`
|
||||
Pathc *PatchCmd `arg:"subcommand:patch" help:"examine and make patch sets"`
|
||||
Patch *PatchCmd `arg:"subcommand:patch" help:"examine and make patch sets"`
|
||||
GitPull *FindCmd `arg:"subcommand:pull" help:"run 'git pull'"`
|
||||
Config *FindCmd `arg:"subcommand:config" help:"show your .config/forge/ settings"`
|
||||
ListPatchSet bool `arg:"--list-patchset" help:"list patch sets"`
|
||||
|
@ -90,6 +90,16 @@ func (args) doBashHelp() {
|
|||
// if this is not the name of the command, the user already started doing something
|
||||
return
|
||||
}
|
||||
if argv.BashAuto[0] == name {
|
||||
me.pp.WriteHelp(os.Stderr)
|
||||
return
|
||||
}
|
||||
fmt.Fprintln(os.Stderr, "")
|
||||
fmt.Fprintln(os.Stderr, "hello world")
|
||||
fmt.Fprintln(os.Stderr, "")
|
||||
}
|
||||
|
||||
func (args) doBashHelpDebug() {
|
||||
fmt.Fprintln(os.Stderr, "")
|
||||
fmt.Fprintln(os.Stderr, "hello world")
|
||||
var more string
|
||||
|
@ -110,54 +120,26 @@ func (args) doBashAuto() {
|
|||
name := "forge"
|
||||
argv.doBashHelp()
|
||||
switch argv.BashAuto[0] {
|
||||
case "dirty":
|
||||
fmt.Println("")
|
||||
case "list":
|
||||
fmt.Println("--all --mine --favorites --private")
|
||||
case "user":
|
||||
case "devel":
|
||||
fmt.Println("reset --mine")
|
||||
case "checkout":
|
||||
fmt.Println("user devel master")
|
||||
case "patches":
|
||||
case "patch":
|
||||
fmt.Println("--list --submit --show")
|
||||
case "pull":
|
||||
case "dirty":
|
||||
case "user":
|
||||
case "devel":
|
||||
case "master":
|
||||
default:
|
||||
if argv.BashAuto[0] == name {
|
||||
// list the subcommands here
|
||||
fmt.Println("--bash patches checkout list dirty pull user devel master")
|
||||
fmt.Println("patch checkout list dirty pull")
|
||||
}
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// complete -F forge --bash forge
|
||||
func (args) doBashNotes() {
|
||||
fmt.Println("#/usr/bin/env bash")
|
||||
fmt.Println("")
|
||||
fmt.Println("# if we add a 'hidden' go-arg option --bash")
|
||||
fmt.Println("#")
|
||||
fmt.Println("# then this is all we have to output:")
|
||||
fmt.Println("# complete -C forge --bash go")
|
||||
fmt.Println("")
|
||||
fmt.Println("_forge_complete()")
|
||||
fmt.Println("{")
|
||||
fmt.Println(" # sets local to this func vars")
|
||||
fmt.Println(" local cur prev all")
|
||||
fmt.Println(" cur=${COMP_WORDS[COMP_CWORD]}")
|
||||
fmt.Println(" prev=${COMP_WORDS[COMP_CWORD-1]}")
|
||||
fmt.Println(" all=${COMP_WORDS[@]}")
|
||||
fmt.Println("")
|
||||
fmt.Println(" # this is where we generate the go-arg output")
|
||||
fmt.Println(" FORGE=$(forge --bash-auto -- $prev \\'$cur\\' $all)")
|
||||
fmt.Println("")
|
||||
fmt.Println(" # this compares the command line input from the user")
|
||||
fmt.Println(" # to whatever strings we output")
|
||||
fmt.Println(" COMPREPLY=( $(compgen -W \"$FORGE\" -- $cur) ) # THIS WORKS")
|
||||
fmt.Println(" return 0")
|
||||
fmt.Println("}")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// complete -F forge --bash forge
|
||||
func (args) doBash() {
|
||||
name := "forge"
|
||||
|
|
48
main.go
48
main.go
|
@ -51,31 +51,33 @@ func main() {
|
|||
me.forge = forgepb.Init()
|
||||
me.found = new(gitpb.Repos)
|
||||
|
||||
if argv.User != nil {
|
||||
me.forge.CheckoutUser()
|
||||
me.forge = forgepb.Init()
|
||||
me.found = new(gitpb.Repos)
|
||||
argv.User.findRepos()
|
||||
doCobol()
|
||||
okExit("")
|
||||
}
|
||||
if argv.Checkout != nil {
|
||||
if argv.Checkout.User != nil {
|
||||
me.forge.CheckoutUser()
|
||||
me.forge = forgepb.Init()
|
||||
me.found = new(gitpb.Repos)
|
||||
argv.Checkout.User.findRepos()
|
||||
doCobol()
|
||||
okExit("")
|
||||
}
|
||||
|
||||
if argv.Devel != nil {
|
||||
me.forge.CheckoutDevel()
|
||||
me.forge = forgepb.Init()
|
||||
me.found = new(gitpb.Repos)
|
||||
argv.Devel.findRepos()
|
||||
doCobol()
|
||||
okExit("")
|
||||
}
|
||||
if argv.Checkout.Devel != nil {
|
||||
me.forge.CheckoutDevel()
|
||||
me.forge = forgepb.Init()
|
||||
me.found = new(gitpb.Repos)
|
||||
argv.Checkout.Devel.findRepos()
|
||||
doCobol()
|
||||
okExit("")
|
||||
}
|
||||
|
||||
if argv.Master != nil {
|
||||
me.forge.CheckoutMaster()
|
||||
me.forge = forgepb.Init()
|
||||
me.found = new(gitpb.Repos)
|
||||
argv.Master.findRepos()
|
||||
doCobol()
|
||||
okExit("")
|
||||
if argv.Checkout.Master != nil {
|
||||
me.forge.CheckoutMaster()
|
||||
me.forge = forgepb.Init()
|
||||
me.found = new(gitpb.Repos)
|
||||
argv.Checkout.Master.findRepos()
|
||||
doCobol()
|
||||
okExit("")
|
||||
}
|
||||
}
|
||||
|
||||
if argv.Register != "" {
|
||||
|
|
Loading…
Reference in New Issue