use subcommands
This commit is contained in:
parent
c5fcb2a6c0
commit
bd332301be
53
argv.go
53
argv.go
|
@ -6,13 +6,48 @@ package main
|
||||||
|
|
||||||
var argv args
|
var argv args
|
||||||
|
|
||||||
|
type FindCmd struct {
|
||||||
|
All bool `arg:"--all" help:"select every repo"`
|
||||||
|
ReadOnly bool `arg:"--readonly" help:"include read-only repos"`
|
||||||
|
Mine bool `arg:"--mine" help:"your repos as defined in the forge config"`
|
||||||
|
Favorites bool `arg:"--favorites" help:"your repos configured as favorites"`
|
||||||
|
Private bool `arg:"--private" help:"private repos from your .config/forge/"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DoCmd struct {
|
||||||
|
List bool `arg:"--list" help:"just show a table of the current state"`
|
||||||
|
Clone bool `arg:"--clone" help:"git clone build dependancies"`
|
||||||
|
Scan bool `arg:"--scan" help:"reload protobuf from .git/"`
|
||||||
|
Force bool `arg:"--force" help:"force redo things"`
|
||||||
|
GitPull bool `arg:"--git-pull" help:"run 'git pull'"`
|
||||||
|
GitReset bool `arg:"--git-reset" help:"run 'git reset --hard'"`
|
||||||
|
Build bool `arg:"--build" default:"true" help:"try to build it"`
|
||||||
|
Install bool `arg:"--install" help:"also try to install it"`
|
||||||
|
// DoRedoGoMod bool `arg:"--RedoGoMod" help:"remake all the go.sum and go.mod files"`
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
arg.MustParse(&args)
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case args.Checkout != nil:
|
||||||
|
fmt.Printf("checkout requested for branch %s\n", args.Checkout.Branch)
|
||||||
|
case args.Commit != nil:
|
||||||
|
fmt.Printf("commit requested with message \"%s\"\n", args.Commit.Message)
|
||||||
|
case args.Push != nil:
|
||||||
|
fmt.Printf("push requested from %s to %s\n", args.Push.Branch, args.Push.Remote)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
Config bool `arg:"--config" help:"work from your .config/forge/ configuration"`
|
Find *FindCmd `arg:"subcommand:find" help:"select repos (for example, dirty or mine or read-only)"`
|
||||||
FindAll bool `arg:"--find-all" help:"select every repo"`
|
Do *DoCmd `arg:"subcommand:do" help:"do something ('git pull', 'build', 'install', etc)"`
|
||||||
FindReadOnly bool `arg:"--find-readonly" help:"include read-only repos"`
|
Config bool `arg:"--config" help:"show your .config/forge/ settings"`
|
||||||
FindMine bool `arg:"--find-mine" help:"download private and writeable repos"`
|
// FindAll bool `arg:"--find-all" help:"select every repo"`
|
||||||
FindFavorites bool `arg:"--find-favorites" help:"download repos marked as favorites"`
|
// FindReadOnly bool `arg:"--find-readonly" help:"include read-only repos"`
|
||||||
FindPrivate bool `arg:"--find-private" help:"list private repos in .config/forge/"`
|
// FindMine bool `arg:"--find-mine" help:"download private and writeable repos"`
|
||||||
|
// FindFavorites bool `arg:"--find-favorites" help:"download repos marked as favorites"`
|
||||||
|
// FindPrivate bool `arg:"--find-private" help:"list private repos in .config/forge/"`
|
||||||
DoList bool `arg:"--do-list" help:"list found repos"`
|
DoList bool `arg:"--do-list" help:"list found repos"`
|
||||||
DoScan bool `arg:"--do-scan" help:"rescan your repos"`
|
DoScan bool `arg:"--do-scan" help:"rescan your repos"`
|
||||||
DoClone bool `arg:"--do-clone" help:"go-clone things you are missing"`
|
DoClone bool `arg:"--do-clone" help:"go-clone things you are missing"`
|
||||||
|
@ -22,17 +57,17 @@ type args struct {
|
||||||
DoBuild bool `arg:"--do-build" default:"true" help:"also try to build it"`
|
DoBuild bool `arg:"--do-build" default:"true" help:"also try to build it"`
|
||||||
DoInstall bool `arg:"--do-install" help:"try to install every binary package"`
|
DoInstall bool `arg:"--do-install" help:"try to install every binary package"`
|
||||||
DoRedoGoMod bool `arg:"--do-RedoGoMod" help:"remake all the go.sum and go.mod files"`
|
DoRedoGoMod bool `arg:"--do-RedoGoMod" help:"remake all the go.sum and go.mod files"`
|
||||||
|
DoGui bool `arg:"--do-gui" help:"run the gui"`
|
||||||
DoPatchSet bool `arg:"--do-patches" help:"make patch set"`
|
DoPatchSet bool `arg:"--do-patches" help:"make patch set"`
|
||||||
ListPatchSet bool `arg:"--list-patches" help:"make patch set"`
|
ListPatchSet bool `arg:"--list-patches" help:"make patch set"`
|
||||||
DoGui bool `arg:"--do-gui" help:"test the gui"`
|
|
||||||
DryRun bool `arg:"--dry-run" help:"show what would be run"`
|
DryRun bool `arg:"--dry-run" help:"show what would be run"`
|
||||||
Fix bool `arg:"--fix" help:"fix config, save config & exit"`
|
Fix bool `arg:"--fix" help:"fix config, save config & exit"`
|
||||||
URL string `arg:"--url" default:"http://go.wit.com/" help:"base url"`
|
|
||||||
Delete string `arg:"--delete" help:"delete this repo"`
|
Delete string `arg:"--delete" help:"delete this repo"`
|
||||||
Dirty bool `arg:"--dirty" help:"git CheckDirty() on every repo"`
|
Dirty bool `arg:"--dirty" help:"git CheckDirty() on every repo"`
|
||||||
User bool `arg:"--user" help:"git checkout user"`
|
User bool `arg:"--user" help:"git checkout user"`
|
||||||
Master bool `arg:"--master" help:"git checkout master"`
|
Master bool `arg:"--master" help:"git checkout master"`
|
||||||
Map []string `arg:"--map" help:"map a new 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)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (args) Version() string {
|
func (args) Version() string {
|
||||||
|
|
|
@ -5,14 +5,16 @@ import "go.wit.com/log"
|
||||||
// retuns true if nothing was done
|
// retuns true if nothing was done
|
||||||
func findConfig() bool {
|
func findConfig() bool {
|
||||||
var done bool = false
|
var done bool = false
|
||||||
if argv.FindMine {
|
if argv.Find != nil {
|
||||||
|
if argv.Find.Mine {
|
||||||
findConfigMine()
|
findConfigMine()
|
||||||
done = true
|
done = true
|
||||||
}
|
}
|
||||||
if argv.FindAll {
|
if argv.Find.All {
|
||||||
findConfigAll()
|
findConfigAll()
|
||||||
done = true
|
done = true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if !done {
|
if !done {
|
||||||
findConfigAll()
|
findConfigAll()
|
||||||
done = true
|
done = true
|
||||||
|
|
12
findRepos.go
12
findRepos.go
|
@ -6,24 +6,26 @@ import (
|
||||||
|
|
||||||
func findRepos() bool {
|
func findRepos() bool {
|
||||||
var done bool = false
|
var done bool = false
|
||||||
if argv.FindAll {
|
if argv.Find != nil {
|
||||||
|
if argv.Find.All {
|
||||||
findAll()
|
findAll()
|
||||||
done = true
|
done = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.FindPrivate {
|
if argv.Find.Private {
|
||||||
findPrivate()
|
findPrivate()
|
||||||
done = true
|
done = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.FindMine {
|
if argv.Find.Mine {
|
||||||
findMine()
|
findMine()
|
||||||
done = true
|
done = true
|
||||||
}
|
}
|
||||||
if argv.FindFavorites {
|
if argv.Find.Favorites {
|
||||||
findFavorites()
|
findFavorites()
|
||||||
done = true
|
done = true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// this is the 'default' behavior when no command line arguments are given
|
// this is the 'default' behavior when no command line arguments are given
|
||||||
// if no argv was set, select repos marked as 'mine'
|
// if no argv was set, select repos marked as 'mine'
|
||||||
|
@ -73,7 +75,7 @@ func findAll() {
|
||||||
for all.Scan() {
|
for all.Scan() {
|
||||||
repo := all.Next()
|
repo := all.Next()
|
||||||
me.found.AppendUniqueGoPath(repo)
|
me.found.AppendUniqueGoPath(repo)
|
||||||
if me.forge.Config.IsReadOnly(repo.GetGoPath()) && !argv.FindReadOnly {
|
if me.forge.Config.IsReadOnly(repo.GetGoPath()) && !argv.Find.ReadOnly {
|
||||||
if repo.ReadOnly {
|
if repo.ReadOnly {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
9
main.go
9
main.go
|
@ -54,9 +54,12 @@ func main() {
|
||||||
okExit("")
|
okExit("")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(argv.Map) != 0 {
|
if argv.Register != "" {
|
||||||
log.Info("need to map here", argv.Map)
|
if err := doRegister(argv.Register); err == nil {
|
||||||
okExit("")
|
okExit("attempting to register " + argv.Register)
|
||||||
|
} else {
|
||||||
|
badExit(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.Delete != "" {
|
if argv.Delete != "" {
|
||||||
|
|
17
send.go
17
send.go
|
@ -51,6 +51,23 @@ func listPatches() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func doRegister(newurl string) error {
|
||||||
|
var url string
|
||||||
|
url = me.urlbase + "/register?url=" + newurl
|
||||||
|
body, err := httpPost(url, nil)
|
||||||
|
if err != nil {
|
||||||
|
log.Info("httpPost() failed:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
test := strings.TrimSpace(string(body))
|
||||||
|
for _, line := range strings.Split(test, "\n") {
|
||||||
|
line = strings.TrimSpace(line)
|
||||||
|
log.Info("server returned:", line)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func getPatch(pbfile string) error {
|
func getPatch(pbfile string) error {
|
||||||
url := me.urlbase + "/patchsetget?filename=" + pbfile
|
url := me.urlbase + "/patchsetget?filename=" + pbfile
|
||||||
log.Info("getPatch() url", url)
|
log.Info("getPatch() url", url)
|
||||||
|
|
Loading…
Reference in New Issue