summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--argv.custom.go45
-rw-r--r--argv.go61
-rw-r--r--argv.struct.go14
-rw-r--r--argv.template.go80
-rw-r--r--build.go2
-rw-r--r--clone.go6
-rw-r--r--main.go27
-rw-r--r--structs.go21
-rw-r--r--work.go8
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
+}
diff --git a/build.go b/build.go
index 797efdb..b80be68 100644
--- a/build.go
+++ b/build.go
@@ -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)
diff --git a/clone.go b/clone.go
index dbec873..3e9a7f2 100644
--- a/clone.go
+++ b/clone.go
@@ -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
diff --git a/main.go b/main.go
index 8e60ad0..0884d10 100644
--- a/main.go
+++ b/main.go
@@ -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
+}
diff --git a/work.go b/work.go
index 28577e2..fd8baeb 100644
--- a/work.go
+++ b/work.go
@@ -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("")