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 dirty # CheckDirty()"
|
||||||
@echo "make user # git checkout user"
|
@echo "make user # git checkout user"
|
||||||
@echo "make master # git checkout master"
|
@echo "make master # git checkout master"
|
||||||
forge
|
# forge
|
||||||
|
|
||||||
vet:
|
vet:
|
||||||
@GO111MODULE=off go vet
|
@GO111MODULE=off go vet
|
||||||
|
|
60
argv.go
60
argv.go
|
@ -37,11 +37,11 @@ type FindCmd struct {
|
||||||
type args struct {
|
type args struct {
|
||||||
List *FindCmd `arg:"subcommand:list" help:"just show a table of the current state"`
|
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"`
|
Dirty *EmptyCmd `arg:"subcommand:dirty" help:"check if your git repos are dirty"`
|
||||||
User *FindCmd `arg:"subcommand:user" help:"git checkout user"`
|
// User *FindCmd `arg:"subcommand:user" help:"git checkout user"`
|
||||||
Devel *FindCmd `arg:"subcommand:devel" help:"git checkout devel"`
|
// Devel *FindCmd `arg:"subcommand:devel" help:"git checkout devel"`
|
||||||
Master *FindCmd `arg:"subcommand:master" help:"git checkout master"`
|
// Master *FindCmd `arg:"subcommand:master" help:"git checkout master"`
|
||||||
Checkout *CheckoutCmd `arg:"subcommand:checkout" help:"switch git branches"`
|
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'"`
|
GitPull *FindCmd `arg:"subcommand:pull" help:"run 'git pull'"`
|
||||||
Config *FindCmd `arg:"subcommand:config" help:"show your .config/forge/ settings"`
|
Config *FindCmd `arg:"subcommand:config" help:"show your .config/forge/ settings"`
|
||||||
ListPatchSet bool `arg:"--list-patchset" help:"list patch sets"`
|
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
|
// if this is not the name of the command, the user already started doing something
|
||||||
return
|
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, "")
|
||||||
fmt.Fprintln(os.Stderr, "hello world")
|
fmt.Fprintln(os.Stderr, "hello world")
|
||||||
var more string
|
var more string
|
||||||
|
@ -110,54 +120,26 @@ func (args) doBashAuto() {
|
||||||
name := "forge"
|
name := "forge"
|
||||||
argv.doBashHelp()
|
argv.doBashHelp()
|
||||||
switch argv.BashAuto[0] {
|
switch argv.BashAuto[0] {
|
||||||
case "dirty":
|
|
||||||
fmt.Println("")
|
|
||||||
case "list":
|
case "list":
|
||||||
fmt.Println("--all --mine --favorites --private")
|
fmt.Println("--all --mine --favorites --private")
|
||||||
case "user":
|
|
||||||
case "devel":
|
|
||||||
fmt.Println("reset --mine")
|
|
||||||
case "checkout":
|
case "checkout":
|
||||||
fmt.Println("user devel master")
|
fmt.Println("user devel master")
|
||||||
case "patches":
|
case "patch":
|
||||||
fmt.Println("--list --submit --show")
|
fmt.Println("--list --submit --show")
|
||||||
|
case "pull":
|
||||||
|
case "dirty":
|
||||||
|
case "user":
|
||||||
|
case "devel":
|
||||||
|
case "master":
|
||||||
default:
|
default:
|
||||||
if argv.BashAuto[0] == name {
|
if argv.BashAuto[0] == name {
|
||||||
// list the subcommands here
|
// 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)
|
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
|
// complete -F forge --bash forge
|
||||||
func (args) doBash() {
|
func (args) doBash() {
|
||||||
name := "forge"
|
name := "forge"
|
||||||
|
|
14
main.go
14
main.go
|
@ -51,32 +51,34 @@ func main() {
|
||||||
me.forge = forgepb.Init()
|
me.forge = forgepb.Init()
|
||||||
me.found = new(gitpb.Repos)
|
me.found = new(gitpb.Repos)
|
||||||
|
|
||||||
if argv.User != nil {
|
if argv.Checkout != nil {
|
||||||
|
if argv.Checkout.User != nil {
|
||||||
me.forge.CheckoutUser()
|
me.forge.CheckoutUser()
|
||||||
me.forge = forgepb.Init()
|
me.forge = forgepb.Init()
|
||||||
me.found = new(gitpb.Repos)
|
me.found = new(gitpb.Repos)
|
||||||
argv.User.findRepos()
|
argv.Checkout.User.findRepos()
|
||||||
doCobol()
|
doCobol()
|
||||||
okExit("")
|
okExit("")
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.Devel != nil {
|
if argv.Checkout.Devel != nil {
|
||||||
me.forge.CheckoutDevel()
|
me.forge.CheckoutDevel()
|
||||||
me.forge = forgepb.Init()
|
me.forge = forgepb.Init()
|
||||||
me.found = new(gitpb.Repos)
|
me.found = new(gitpb.Repos)
|
||||||
argv.Devel.findRepos()
|
argv.Checkout.Devel.findRepos()
|
||||||
doCobol()
|
doCobol()
|
||||||
okExit("")
|
okExit("")
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.Master != nil {
|
if argv.Checkout.Master != nil {
|
||||||
me.forge.CheckoutMaster()
|
me.forge.CheckoutMaster()
|
||||||
me.forge = forgepb.Init()
|
me.forge = forgepb.Init()
|
||||||
me.found = new(gitpb.Repos)
|
me.found = new(gitpb.Repos)
|
||||||
argv.Master.findRepos()
|
argv.Checkout.Master.findRepos()
|
||||||
doCobol()
|
doCobol()
|
||||||
okExit("")
|
okExit("")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if argv.Register != "" {
|
if argv.Register != "" {
|
||||||
if err := doRegister(argv.Register); err == nil {
|
if err := doRegister(argv.Register); err == nil {
|
||||||
|
|
Loading…
Reference in New Issue