diff options
| author | Jeff Carr <[email protected]> | 2025-10-19 04:48:28 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-19 04:48:28 -0500 |
| commit | 867b8dce9ea8f9f22718313691664f1f0e97e4c8 (patch) | |
| tree | d2d45fffa8e106475a09b766b6bf316aff92d56e | |
| parent | 2896bf0b1d58b27b331ea437c7c5a7d7318c8e43 (diff) | |
new argv
| -rw-r--r-- | argv.custom.go | 45 | ||||
| -rw-r--r-- | argv.go | 61 | ||||
| -rw-r--r-- | argv.struct.go | 14 | ||||
| -rw-r--r-- | argv.template.go | 80 | ||||
| -rw-r--r-- | build.go | 2 | ||||
| -rw-r--r-- | clone.go | 6 | ||||
| -rw-r--r-- | main.go | 27 | ||||
| -rw-r--r-- | structs.go | 21 | ||||
| -rw-r--r-- | work.go | 8 |
9 files changed, 176 insertions, 88 deletions
diff --git a/argv.custom.go b/argv.custom.go new file mode 100644 index 0000000..75d4327 --- /dev/null +++ b/argv.custom.go @@ -0,0 +1,45 @@ +package main + +import ( + "os" + + "go.wit.com/lib/protobuf/argvpb" +) + +// sent via -ldflags +var VERSION string +var BUILDTIME string + +var APPNAME string = "go-clone" + +func (args) Version() string { + return "go-clone " + VERSION + " Built on " + BUILDTIME +} + +func (args) Buildtime() (string, string) { + return BUILDTIME, VERSION +} + +func (a args) Description() string { + return ` +git clone go repositories recursively + +Examples: + go-clone go.wit.com/apps/go-clone # 'git clone' go-clone +` +} + +func (args) Appname() string { + return APPNAME +} + +func (a args) DoAutoComplete(pb *argvpb.Argv) { + // fmt.Fprintf(os.Stderr, "blah\n") + // fmt.Fprintf(os.Stderr, "\n") + if pb.Cmd == "" { + pb.SendStrings([]string{"--dry-run", "--non-recursive", "--work", "--version"}) + } else { + pb.SubCommand(pb.Goargs...) + } + os.Exit(0) +} diff --git a/argv.go b/argv.go deleted file mode 100644 index 3b8637c..0000000 --- a/argv.go +++ /dev/null @@ -1,61 +0,0 @@ -package main - -import ( - "os" - - "go.wit.com/lib/protobuf/argvpb" -) - -/* - this parses the command line arguements - - this enables command line options from other packages like 'gui' and 'log' -*/ - -// argv *argvpb.Argv // more experiments for bash handling -// me.argv = argvpb.Autocomplete(&argv) // adds shell auto complete to go-args - -var argv args - -type args struct { - Repo string `arg:"positional" help:"go import path"` - AutoWork bool `arg:"--work" default:"false" help:"recreate the go.work file"` - DryRun bool `arg:"--dry-run" help:"show what would be run"` - NonRecursive bool `arg:"--non-recursive" help:"recursively clone all dependencies"` - Build bool `arg:"--build" help:"try to build it after clone"` - Install bool `arg:"--install" help:"try to install it after clone"` - Ignore bool `arg:"--ignore" default:"false" help:"ignore weird clone errors from non-standard repos"` - // Fetch bool `arg:"--git-fetch" default:"false" help:"run 'git fetch' on all your repos"` -} - -func (args) Version() string { - return "go-clone " + VERSION + " Built on " + BUILDTIME -} - -func (args) Buildtime() (string, string) { - return BUILDTIME, VERSION -} - -func (a args) Description() string { - return ` -git clone go repositories recursively - -Examples: - go-clone go.wit.com/apps/go-clone # 'git clone' go-clone -` -} - -func (args) Appname() string { - return ARGNAME -} - -func (a args) DoAutoComplete(pb *argvpb.Argv) { - // fmt.Fprintf(os.Stderr, "blah\n") - // fmt.Fprintf(os.Stderr, "\n") - if pb.Cmd == "" { - pb.SendStrings([]string{"--dry-run", "--non-recursive", "--work", "--version"}) - } else { - pb.SubCommand(pb.Goargs...) - } - os.Exit(0) -} diff --git a/argv.struct.go b/argv.struct.go new file mode 100644 index 0000000..633b003 --- /dev/null +++ b/argv.struct.go @@ -0,0 +1,14 @@ +package main + +var argv args + +type args struct { + Repo string `arg:"positional" help:"go import path"` + AutoWork bool `arg:"--work" default:"false" help:"recreate the go.work file"` + DryRun bool `arg:"--dry-run" help:"show what would be run"` + NonRecursive bool `arg:"--non-recursive" help:"recursively clone all dependencies"` + Build bool `arg:"--build" help:"try to build it after clone"` + Install bool `arg:"--install" help:"try to install it after clone"` + Ignore bool `arg:"--ignore" default:"false" help:"ignore weird clone errors from non-standard repos"` + // Fetch bool `arg:"--git-fetch" default:"false" help:"run 'git fetch' on all your repos"` +} diff --git a/argv.template.go b/argv.template.go new file mode 100644 index 0000000..e7a9948 --- /dev/null +++ b/argv.template.go @@ -0,0 +1,80 @@ +package main + +// these are stubbed in functions needed +// just copy this file from another working app for now +// you shouldn't need to change anything here +// TODO: clean this up in argv + +import ( + "os" + + "go.wit.com/dev/alexflint/arg" + "go.wit.com/gui" + "go.wit.com/lib/fhelp" + "go.wit.com/log" +) + +func (args) InitArgv() (string, string, string) { + return APPNAME, BUILDTIME, VERSION +} + +// this function will send the current argv PB to go-args for parsing +func (args) ParseFlags(flags []string) error { + var err error + if me.pp == nil { + // log.Info("Parse Flags GOT flags:", flags) + me.pp, err = arg.ParseFlags(flags, &argv) + // panic("got to the app's ParseFlags()") + } else { + panic("me.pp was not nil") + } + return err +} + +// add this funcgion: this will print the help +func (args) WriteHelpForSubcommand(cmd string) error { + me.pp.WriteHelpForSubcommand(os.Stderr, cmd) + return nil +} + +// this will print the help for the subcmd +func (args) WriteHelpForAutocomplete(part string, subcmd ...string) error { + return me.pp.WriteHelpForAutocomplete(os.Stderr, os.Stdout, part, subcmd...) +} + +func (args) WriteHelpForAutocompleteDebug(part string, subcmd ...string) error { + f, _ := os.OpenFile("/tmp/argv.junk", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + return me.pp.WriteHelpForAutocomplete(f, os.Stdout, part, subcmd...) +} + +// add this funcgion: this will print the help +func (args) WriteHelp() error { + me.pp.WriteHelp(os.Stderr) + return nil +} + +func (args) InitGui() error { + // panic("got here") + arg.Register(&gui.ArgvGui) + // me.gui = gui.PreInit() + me.myGui = fhelp.Gui() + return nil +} + +func (args) Exit() { + gui.UnloadToolkits() + if me.argv.Verbose() { + log.Info("argv.Exit() called", APPNAME+".Exit()") + } + // remove this from the template for your app (or make one for youself if you need it) + // forgeExit() // custom forge shutdown function +} + +func (args) Help() string { + return "got app help" +} + +func (args) MustParse() error { + me.pp = arg.MustParse(&argv) + return nil +} @@ -8,7 +8,7 @@ import ( ) func build() error { - err := forge.Build(workingRepo, nil) + err := me.forge.Build(workingRepo, nil) pwd, _ := os.Getwd() if err == nil { log.Info("this totally worked", pwd) @@ -67,15 +67,15 @@ func clone(gopath string) (*gitpb.Repo, error) { } gopath = CleanRepoURL(gopath) os.Setenv("REPO_AUTO_CLONE", "true") - // pb, _ := forge.NewGoPath(gopath) - check := forge.FindAnyPath(filepath.Join(forge.Config.ReposDir, gopath)) + // pb, _ := me.forge.NewGoPath(gopath) + check := me.forge.FindAnyPath(filepath.Join(me.forge.Config.ReposDir, gopath)) if check != nil { if check.IsValidDir() { // repo already exists and is valid return check, nil } } - pb, err := forge.GoClone(gopath) + pb, err := me.forge.GoClone(gopath) if err != nil { log.Info("clone() could not download err:", err) return nil, err @@ -9,25 +9,14 @@ import ( "go.wit.com/log" ) -// argv *argvpb.Argv // more experiments for bash handling -// me.argv = argvpb.Autocomplete(&argv) // adds shell auto complete to go-args - -// sent via -ldflags -var VERSION string -var BUILDTIME string - -var ARGNAME string = "go-clone" - -var forge *forgepb.Forge -var newargv *argvpb.Argv // more experiments for bash handling - var workingRepo *gitpb.Repo func main() { - newargv = argvpb.Autocomplete(&argv) // adds shell auto complete to go-args + me = new(mainType) + me.argv = argvpb.Autocomplete(&argv) // adds shell auto complete to go-args var err error - forge, err = forgepb.Init() + me.forge, err = forgepb.Init() if err != nil { log.Info("This tool requires forge") badExit(err) @@ -55,7 +44,7 @@ func main() { if workingRepo.GetRepoType() == "binary" || workingRepo.GetRepoType() == "plugin" { log.Info("build will probably fail", workingRepo.GetGoPath(), "is", workingRepo.GetRepoType()) } - if err := forge.Build(workingRepo, nil); err != nil { + if err := me.forge.Build(workingRepo, nil); err != nil { log.Warn("BUILD FAILED", workingRepo.GetGoPath(), err) badExit(err) } @@ -66,7 +55,7 @@ func main() { if workingRepo.GetRepoType() == "binary" || workingRepo.GetRepoType() == "plugin" { log.Info("install will probably fail", workingRepo.GetGoPath(), "is", workingRepo.GetRepoType()) } - if err := forge.Install(workingRepo, nil); err != nil { + if err := me.forge.Install(workingRepo, nil); err != nil { log.Warn("INSTALL FAILED", workingRepo.GetGoPath(), err) badExit(err) } @@ -85,12 +74,12 @@ func okExit(thing string) { log.Info(thing, "ok") } log.Info("Finished clone on", workingRepo.GetGoPath(), "ok") - forge.ConfigSave() + me.forge.ConfigSave() os.Exit(0) } func badExit(err error) { - log.Info("Total repositories:", forge.Repos.Len()) - log.Info("Finished go-clone with error", err, forge.Config.ReposDir) + log.Info("Total repositories:", me.forge.Repos.Len()) + log.Info("Finished go-clone with error", err, me.forge.Config.ReposDir) os.Exit(-1) } diff --git a/structs.go b/structs.go new file mode 100644 index 0000000..c767cbb --- /dev/null +++ b/structs.go @@ -0,0 +1,21 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "go.wit.com/dev/alexflint/arg" + "go.wit.com/lib/fhelp" + "go.wit.com/lib/protobuf/argvpb" + "go.wit.com/lib/protobuf/forgepb" +) + +var me *mainType + +// this app's variables +type mainType struct { + argv *argvpb.Argv // more experiments for bash handling + pp *arg.Parser // for parsing the command line args. Yay to alexf lint! + myGui *fhelp.GuiPrep // for initializing the GUI toolkits + forge *forgepb.Forge +} @@ -10,10 +10,10 @@ func autoWork() { if !argv.AutoWork { return } - log.Info("About to re-create", forge.Config.ReposDir+"/go.work") - shell.PathRun(forge.Config.ReposDir, []string{"mv", "go.work", "go.work.last"}) - forge.MakeGoWork() - shell.PathRun(forge.Config.ReposDir, []string{"go", "work", "use"}) + log.Info("About to re-create", me.forge.Config.ReposDir+"/go.work") + shell.PathRun(me.forge.Config.ReposDir, []string{"mv", "go.work", "go.work.last"}) + me.forge.MakeGoWork() + shell.PathRun(me.forge.Config.ReposDir, []string{"go", "work", "use"}) log.Info("") log.Info("original go.work file saved as go.work.last") log.Info("") |
