awesome bash completion work. thank good. what a timesaver
This commit is contained in:
parent
ec8a3688eb
commit
5434ab498b
68
argv.go
68
argv.go
|
@ -19,6 +19,14 @@ type PatchCmd struct {
|
||||||
Show string `arg:"--show" help:"show a specific patch"`
|
Show string `arg:"--show" help:"show a specific patch"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ConfigCmd struct {
|
||||||
|
Add *EmptyCmd `arg:"subcommand:add" help:"add a config setting"`
|
||||||
|
Fix *EmptyCmd `arg:"subcommand:fix" help:"fix .config/forge/ and/or repos.pb protobuf file"`
|
||||||
|
List *EmptyCmd `arg:"subcommand:list" help:"list your config settings"`
|
||||||
|
Delete string `arg:"--delete" help:"delete this repo"`
|
||||||
|
Register string `arg:"--register" help:"register your git URL (foo.com/mystuff) or (github.com/foo/bar)"`
|
||||||
|
}
|
||||||
|
|
||||||
type CheckoutCmd struct {
|
type CheckoutCmd struct {
|
||||||
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"`
|
||||||
|
@ -35,28 +43,17 @@ type FindCmd struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
List *FindCmd `arg:"subcommand:list" help:"just show a table of the current state"`
|
Checkout *CheckoutCmd `arg:"subcommand:checkout" help:"switch git branches"`
|
||||||
Dirty *EmptyCmd `arg:"subcommand:dirty" help:"check if your git repos are dirty"`
|
Config *ConfigCmd `arg:"subcommand:config" help:"show your .config/forge/ settings"`
|
||||||
// User *FindCmd `arg:"subcommand:user" help:"git checkout user"`
|
Dirty *EmptyCmd `arg:"subcommand:dirty" help:"check if your git repos are dirty"`
|
||||||
// Devel *FindCmd `arg:"subcommand:devel" help:"git checkout devel"`
|
GitReset *EmptyCmd `arg:"subcommand:hard-reset" help:"hard reset your user git branch"`
|
||||||
// Master *FindCmd `arg:"subcommand:master" help:"git checkout master"`
|
List *FindCmd `arg:"subcommand:list" help:"just show a table of the current state"`
|
||||||
Checkout *CheckoutCmd `arg:"subcommand:checkout" help:"switch git branches"`
|
Patch *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'"`
|
Rescan *EmptyCmd `arg:"subcommand:rescan" help:"recreate the git protobuf repos.pb file"`
|
||||||
Config *FindCmd `arg:"subcommand:config" help:"show your .config/forge/ settings"`
|
URL string `arg:"--connect" help:"gowebd url"`
|
||||||
ListPatchSet bool `arg:"--list-patchset" help:"list patch sets"`
|
Bash bool `arg:"--bash" help:"generate bash completion"`
|
||||||
DryRun bool `arg:"--dry-run" help:"show what would be run"`
|
BashAuto []string `arg:"--auto-complete" help:"does the actual autocompletion"`
|
||||||
Fix bool `arg:"--fix" help:"fix config, save config & exit"`
|
|
||||||
Delete string `arg:"--delete" help:"delete this repo"`
|
|
||||||
URL string `arg:"--connect" help:"gowebd url"`
|
|
||||||
Register string `arg:"--register" help:"register your git URL (foo.com/mystuff) or (github.com/foo/bar)"`
|
|
||||||
GitReset bool `arg:"--git-reset" help:"run 'git reset --hard'"`
|
|
||||||
Scan bool `arg:"--scan" help:"reload protobuf from .git/"`
|
|
||||||
Force bool `arg:"--force" help:"force redo things"`
|
|
||||||
PatchSet string `arg:"--patchset" help:"make patch set"`
|
|
||||||
Apply string `arg:"--apply" help:"apply a patch set"`
|
|
||||||
Bash bool `arg:"--bash" help:"generage bash completion"`
|
|
||||||
BashAuto []string `arg:"--bash-auto" help:"generage bash completion"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (args) Version() string {
|
func (args) Version() string {
|
||||||
|
@ -68,13 +65,11 @@ func (a args) Description() string {
|
||||||
forge -- in the spirit of things like sourceforge
|
forge -- in the spirit of things like sourceforge
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
forge config # shows your forge config (~/.config/forge/)
|
forge # opens the GUI
|
||||||
forge list # show every repo state
|
forge list # show every repo state
|
||||||
forge dirty # show only dirty repos
|
forge dirty # check for dirty git repos
|
||||||
forge pull # run 'git pull' in every repo
|
forge pull # run 'git pull' in every repo
|
||||||
forge checkout user # git checkout the user branch
|
forge checkout # switch git branches
|
||||||
forge checkout devel # git checkout the devel branch
|
|
||||||
forge checkout master # git checkout the master branch
|
|
||||||
|
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
@ -120,13 +115,16 @@ func (args) doBashAuto() {
|
||||||
name := "forge"
|
name := "forge"
|
||||||
argv.doBashHelp()
|
argv.doBashHelp()
|
||||||
switch argv.BashAuto[0] {
|
switch argv.BashAuto[0] {
|
||||||
case "list":
|
|
||||||
fmt.Println("--all --mine --favorites --private")
|
|
||||||
case "checkout":
|
case "checkout":
|
||||||
fmt.Println("user devel master")
|
fmt.Println("user devel master")
|
||||||
|
case "config":
|
||||||
|
fmt.Println("add fix list delete")
|
||||||
|
case "list":
|
||||||
|
fmt.Println("--all --mine --favorites --private")
|
||||||
|
case "pull":
|
||||||
|
fmt.Println("--all --mine --favorites --private")
|
||||||
case "patch":
|
case "patch":
|
||||||
fmt.Println("--list --submit --show")
|
fmt.Println("--list --submit --show")
|
||||||
case "pull":
|
|
||||||
case "dirty":
|
case "dirty":
|
||||||
case "user":
|
case "user":
|
||||||
case "devel":
|
case "devel":
|
||||||
|
@ -134,7 +132,7 @@ func (args) doBashAuto() {
|
||||||
default:
|
default:
|
||||||
if argv.BashAuto[0] == name {
|
if argv.BashAuto[0] == name {
|
||||||
// list the subcommands here
|
// list the subcommands here
|
||||||
fmt.Println("patch checkout list dirty pull")
|
fmt.Println("--bash checkout config dirty hard-reset list patch pull rescan")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
@ -145,9 +143,9 @@ func (args) doBash() {
|
||||||
name := "forge"
|
name := "forge"
|
||||||
fmt.Println("# add this in your bashrc:")
|
fmt.Println("# add this in your bashrc:")
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
fmt.Println("# if we add a 'hidden' go-arg option --bash")
|
fmt.Println("# todo: add this to go-arg as a 'hidden' go-arg option --bash")
|
||||||
fmt.Println("#")
|
fmt.Println("#")
|
||||||
fmt.Println("# then this is all we have to output:")
|
fmt.Println("# todo: make this output work/parse with:")
|
||||||
fmt.Println("# complete -C " + name + " --bash go")
|
fmt.Println("# complete -C " + name + " --bash go")
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
fmt.Println("_" + name + "_complete()")
|
fmt.Println("_" + name + "_complete()")
|
||||||
|
@ -159,7 +157,7 @@ func (args) doBash() {
|
||||||
fmt.Println(" all=${COMP_WORDS[@]}")
|
fmt.Println(" all=${COMP_WORDS[@]}")
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
fmt.Println(" # this is where we generate the go-arg output")
|
fmt.Println(" # this is where we generate the go-arg output")
|
||||||
fmt.Println(" GOARGS=$(" + name + " --bash-auto $prev \\'$cur\\' $all)")
|
fmt.Println(" GOARGS=$(" + name + " --auto-complete $prev \\'$cur\\' $all)")
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
fmt.Println(" # this compares the command line input from the user")
|
fmt.Println(" # this compares the command line input from the user")
|
||||||
fmt.Println(" # to whatever strings we output")
|
fmt.Println(" # to whatever strings we output")
|
||||||
|
@ -167,5 +165,7 @@ func (args) doBash() {
|
||||||
fmt.Println(" return 0")
|
fmt.Println(" return 0")
|
||||||
fmt.Println("}")
|
fmt.Println("}")
|
||||||
fmt.Println("complete -F _" + name + "_complete " + name)
|
fmt.Println("complete -F _" + name + "_complete " + name)
|
||||||
|
fmt.Println("")
|
||||||
|
fmt.Println("# copy and paste the above into your bash shell should work")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
96
main.go
96
main.go
|
@ -76,50 +76,38 @@ func main() {
|
||||||
me.found = new(gitpb.Repos)
|
me.found = new(gitpb.Repos)
|
||||||
argv.Checkout.Master.findRepos()
|
argv.Checkout.Master.findRepos()
|
||||||
doCobol()
|
doCobol()
|
||||||
okExit("")
|
|
||||||
}
|
}
|
||||||
}
|
log.Info("make 'user' the default here?")
|
||||||
|
|
||||||
if argv.Register != "" {
|
|
||||||
if err := doRegister(argv.Register); err == nil {
|
|
||||||
okExit("attempting to register " + argv.Register)
|
|
||||||
} else {
|
|
||||||
badExit(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if argv.Apply != "" {
|
|
||||||
pset, err := readPatchFile(argv.Apply)
|
|
||||||
if err != nil {
|
|
||||||
badExit(err)
|
|
||||||
}
|
|
||||||
if err = applyPatchset(pset); err == nil {
|
|
||||||
okExit("applied patch ok")
|
|
||||||
}
|
|
||||||
badExit(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if argv.Delete != "" {
|
|
||||||
me.forge.DeleteByGoPath(argv.Delete)
|
|
||||||
me.forge.SetConfigSave(true)
|
|
||||||
okExit("")
|
|
||||||
}
|
|
||||||
|
|
||||||
if argv.Fix {
|
|
||||||
okExit("")
|
okExit("")
|
||||||
}
|
}
|
||||||
|
|
||||||
// first find the repos or gopaths to operate on
|
// first find the repos or gopaths to operate on
|
||||||
if argv.Config != nil {
|
if argv.Config != nil {
|
||||||
findConfig(argv.Config)
|
if argv.Config.Delete != "" {
|
||||||
|
me.forge.DeleteByGoPath(argv.Config.Delete)
|
||||||
|
me.forge.SetConfigSave(true)
|
||||||
|
okExit("")
|
||||||
|
}
|
||||||
|
|
||||||
|
if argv.Config.Fix != nil {
|
||||||
|
log.Info("todo")
|
||||||
|
okExit("")
|
||||||
|
}
|
||||||
|
if argv.Config.Register != "" {
|
||||||
|
if err := doRegister(argv.Config.Register); err == nil {
|
||||||
|
okExit("attempting to register " + argv.Config.Register)
|
||||||
|
} else {
|
||||||
|
badExit(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// findConfig(argv.Config)
|
||||||
me.forge.ConfigPrintTable()
|
me.forge.ConfigPrintTable()
|
||||||
okExit("")
|
okExit("")
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("found", me.found.Len(), "repos. found", len(me.foundPaths), "paths from .config/forge")
|
log.Info("found", me.found.Len(), "repos. found", len(me.foundPaths), "paths from .config/forge")
|
||||||
|
|
||||||
// now, do something to all of them (or just print out a table of them)
|
|
||||||
var done bool = false
|
|
||||||
if argv.Dirty != nil {
|
if argv.Dirty != nil {
|
||||||
findAll() // select all the repos
|
findAll() // select all the repos
|
||||||
doCheckDirtyAndConfigSave()
|
doCheckDirtyAndConfigSave()
|
||||||
|
@ -127,41 +115,42 @@ func main() {
|
||||||
findDirty()
|
findDirty()
|
||||||
doCobol()
|
doCobol()
|
||||||
okExit("")
|
okExit("")
|
||||||
done = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.Scan {
|
if argv.Rescan != nil {
|
||||||
me.forge.ScanGoSrc()
|
me.forge.ScanGoSrc()
|
||||||
done = true
|
okExit("")
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.GitPull != nil {
|
if argv.GitPull != nil {
|
||||||
argv.GitPull.findRepos()
|
argv.GitPull.findRepos()
|
||||||
doGitPull()
|
doGitPull()
|
||||||
done = true
|
okExit("")
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.GitReset {
|
if argv.GitReset != nil {
|
||||||
findAll() // select all the repos
|
findAll() // select all the repos
|
||||||
doGitReset()
|
doGitReset()
|
||||||
done = true
|
okExit("patches")
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.List != nil {
|
if argv.List != nil {
|
||||||
argv.List.findRepos()
|
argv.List.findRepos()
|
||||||
// print out the repos
|
// print out the repos
|
||||||
doCobol()
|
doCobol()
|
||||||
done = true
|
|
||||||
}
|
|
||||||
if argv.PatchSet != "" {
|
|
||||||
sendDevelDiff(argv.PatchSet)
|
|
||||||
// sendMasterDiff()
|
|
||||||
okExit("patches")
|
okExit("patches")
|
||||||
}
|
}
|
||||||
|
if argv.Patch != nil {
|
||||||
|
if argv.Patch.Show != "" {
|
||||||
|
sendDevelDiff(argv.Patch.Show)
|
||||||
|
// sendMasterDiff()
|
||||||
|
okExit("patches")
|
||||||
|
}
|
||||||
|
|
||||||
if argv.ListPatchSet {
|
if argv.Patch.List {
|
||||||
listPatches()
|
listPatches()
|
||||||
okExit("patches")
|
okExit("patches")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if configSave {
|
if configSave {
|
||||||
|
@ -173,17 +162,12 @@ func main() {
|
||||||
// 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
|
||||||
if gui.NoGui() {
|
if gui.NoGui() {
|
||||||
if !done {
|
doCobol()
|
||||||
// if nothing was selected, print out a table of them on STDOUT
|
okExit("")
|
||||||
doCobol()
|
|
||||||
okExit("")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// open the gui unless the user performed some other
|
// open the gui unless the user performed some other
|
||||||
// things from the command line
|
// basically, if you run just 'forge' it should open the GUI
|
||||||
// basically, if you run just 'forge' it'll open the GUI
|
doGui()
|
||||||
if !done {
|
|
||||||
doGui()
|
|
||||||
}
|
|
||||||
okExit("")
|
okExit("")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue