awesome bash completion work. thank good. what a timesaver
This commit is contained in:
parent
ec8a3688eb
commit
5434ab498b
60
argv.go
60
argv.go
|
@ -19,6 +19,14 @@ type PatchCmd struct {
|
|||
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 {
|
||||
User *FindCmd `arg:"subcommand:user" help:"git checkout user"`
|
||||
Devel *FindCmd `arg:"subcommand:devel" help:"git checkout devel"`
|
||||
|
@ -35,28 +43,17 @@ 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"`
|
||||
Checkout *CheckoutCmd `arg:"subcommand:checkout" help:"switch git branches"`
|
||||
Config *ConfigCmd `arg:"subcommand:config" help:"show your .config/forge/ settings"`
|
||||
Dirty *EmptyCmd `arg:"subcommand:dirty" help:"check if your git repos are dirty"`
|
||||
GitReset *EmptyCmd `arg:"subcommand:hard-reset" help:"hard reset your user git branch"`
|
||||
List *FindCmd `arg:"subcommand:list" help:"just show a table of the current state"`
|
||||
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"`
|
||||
DryRun bool `arg:"--dry-run" help:"show what would be run"`
|
||||
Fix bool `arg:"--fix" help:"fix config, save config & exit"`
|
||||
Delete string `arg:"--delete" help:"delete this repo"`
|
||||
Rescan *EmptyCmd `arg:"subcommand:rescan" help:"recreate the git protobuf repos.pb file"`
|
||||
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"`
|
||||
Bash bool `arg:"--bash" help:"generate bash completion"`
|
||||
BashAuto []string `arg:"--auto-complete" help:"does the actual autocompletion"`
|
||||
}
|
||||
|
||||
func (args) Version() string {
|
||||
|
@ -68,13 +65,11 @@ func (a args) Description() string {
|
|||
forge -- in the spirit of things like sourceforge
|
||||
|
||||
Examples:
|
||||
forge config # shows your forge config (~/.config/forge/)
|
||||
forge # opens the GUI
|
||||
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 checkout user # git checkout the user branch
|
||||
forge checkout devel # git checkout the devel branch
|
||||
forge checkout master # git checkout the master branch
|
||||
forge checkout # switch git branches
|
||||
|
||||
`
|
||||
}
|
||||
|
@ -120,13 +115,16 @@ func (args) doBashAuto() {
|
|||
name := "forge"
|
||||
argv.doBashHelp()
|
||||
switch argv.BashAuto[0] {
|
||||
case "list":
|
||||
fmt.Println("--all --mine --favorites --private")
|
||||
case "checkout":
|
||||
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":
|
||||
fmt.Println("--list --submit --show")
|
||||
case "pull":
|
||||
case "dirty":
|
||||
case "user":
|
||||
case "devel":
|
||||
|
@ -134,7 +132,7 @@ func (args) doBashAuto() {
|
|||
default:
|
||||
if argv.BashAuto[0] == name {
|
||||
// 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)
|
||||
|
@ -145,9 +143,9 @@ func (args) doBash() {
|
|||
name := "forge"
|
||||
fmt.Println("# add this in your bashrc:")
|
||||
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("# 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("")
|
||||
fmt.Println("_" + name + "_complete()")
|
||||
|
@ -159,7 +157,7 @@ func (args) doBash() {
|
|||
fmt.Println(" all=${COMP_WORDS[@]}")
|
||||
fmt.Println("")
|
||||
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(" # this compares the command line input from the user")
|
||||
fmt.Println(" # to whatever strings we output")
|
||||
|
@ -167,5 +165,7 @@ func (args) doBash() {
|
|||
fmt.Println(" return 0")
|
||||
fmt.Println("}")
|
||||
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)
|
||||
}
|
||||
|
|
82
main.go
82
main.go
|
@ -76,50 +76,38 @@ func main() {
|
|||
me.found = new(gitpb.Repos)
|
||||
argv.Checkout.Master.findRepos()
|
||||
doCobol()
|
||||
okExit("")
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
log.Info("make 'user' the default here?")
|
||||
okExit("")
|
||||
}
|
||||
|
||||
// first find the repos or gopaths to operate on
|
||||
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()
|
||||
okExit("")
|
||||
}
|
||||
|
||||
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 {
|
||||
findAll() // select all the repos
|
||||
doCheckDirtyAndConfigSave()
|
||||
|
@ -127,42 +115,43 @@ func main() {
|
|||
findDirty()
|
||||
doCobol()
|
||||
okExit("")
|
||||
done = true
|
||||
}
|
||||
|
||||
if argv.Scan {
|
||||
if argv.Rescan != nil {
|
||||
me.forge.ScanGoSrc()
|
||||
done = true
|
||||
okExit("")
|
||||
}
|
||||
|
||||
if argv.GitPull != nil {
|
||||
argv.GitPull.findRepos()
|
||||
doGitPull()
|
||||
done = true
|
||||
okExit("")
|
||||
}
|
||||
|
||||
if argv.GitReset {
|
||||
if argv.GitReset != nil {
|
||||
findAll() // select all the repos
|
||||
doGitReset()
|
||||
done = true
|
||||
okExit("patches")
|
||||
}
|
||||
|
||||
if argv.List != nil {
|
||||
argv.List.findRepos()
|
||||
// print out the repos
|
||||
doCobol()
|
||||
done = true
|
||||
okExit("patches")
|
||||
}
|
||||
if argv.PatchSet != "" {
|
||||
sendDevelDiff(argv.PatchSet)
|
||||
if argv.Patch != nil {
|
||||
if argv.Patch.Show != "" {
|
||||
sendDevelDiff(argv.Patch.Show)
|
||||
// sendMasterDiff()
|
||||
okExit("patches")
|
||||
}
|
||||
|
||||
if argv.ListPatchSet {
|
||||
if argv.Patch.List {
|
||||
listPatches()
|
||||
okExit("patches")
|
||||
}
|
||||
}
|
||||
|
||||
if configSave {
|
||||
me.forge.ConfigSave()
|
||||
|
@ -173,17 +162,12 @@ func main() {
|
|||
// nothing else was specified to be done,
|
||||
// then just list the table to stdout
|
||||
if gui.NoGui() {
|
||||
if !done {
|
||||
// if nothing was selected, print out a table of them on STDOUT
|
||||
doCobol()
|
||||
okExit("")
|
||||
}
|
||||
}
|
||||
|
||||
// open the gui unless the user performed some other
|
||||
// things from the command line
|
||||
// basically, if you run just 'forge' it'll open the GUI
|
||||
if !done {
|
||||
// basically, if you run just 'forge' it should open the GUI
|
||||
doGui()
|
||||
}
|
||||
okExit("")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue