summaryrefslogtreecommitdiff
path: root/forgeConfig
diff options
context:
space:
mode:
Diffstat (limited to 'forgeConfig')
-rw-r--r--forgeConfig/Makefile12
-rw-r--r--forgeConfig/argv.go43
-rw-r--r--forgeConfig/main.go27
3 files changed, 81 insertions, 1 deletions
diff --git a/forgeConfig/Makefile b/forgeConfig/Makefile
index 9c34ac1..8c6325d 100644
--- a/forgeConfig/Makefile
+++ b/forgeConfig/Makefile
@@ -1,8 +1,18 @@
+VERSION = $(shell git describe --tags)
+BUILDTIME = $(shell date +%Y.%m.%d)
+
build:
- GO111MODULE=off go build
+ GO111MODULE=off go build \
+ -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
./forgeConfig
FORGE_HOME=/tmp/forge ./forgeConfig
+list:
+ ./forgeConfig --list
+
+add:
+ ./forgeConfig --add --name 'foo' --gopath 'go.wit.com/apps/foo'
+
goimports:
goimports -w *.go
diff --git a/forgeConfig/argv.go b/forgeConfig/argv.go
new file mode 100644
index 0000000..44aff23
--- /dev/null
+++ b/forgeConfig/argv.go
@@ -0,0 +1,43 @@
+package main
+
+import (
+ "os"
+
+ "github.com/alexflint/go-arg"
+)
+
+var argv args
+
+type args struct {
+ ConfigDir string `arg:"env:FORGE_HOME" help:"defaults to ~/.config/forge/"`
+ List bool `arg:"--list" default:"false" help:"list repos in your config"`
+ Add bool `arg:"--add" default:"false" help:"add a new repo"`
+ Name string `arg:"--name" help:"name of the repo"`
+ GoPath string `arg:"--gopath" help:"gopath of the repo"`
+}
+
+func (a args) Description() string {
+ return `
+ forgeConfig -- add entries to your config files
+
+This is just example protobuf code to test forgepb is working
+but it could be used to automagically create a config file too.
+
+If you need to change your config file, just edit the forge.text or forge.json
+files then remove the forge.pb and ConfigLoad() will attempt to load those files instead
+`
+}
+
+func (args) Version() string {
+ return "virtigo " + VERSION
+}
+
+func init() {
+ var pp *arg.Parser
+ pp = arg.MustParse(&argv)
+
+ if pp == nil {
+ pp.WriteHelp(os.Stdout)
+ os.Exit(0)
+ }
+}
diff --git a/forgeConfig/main.go b/forgeConfig/main.go
index 058412d..cdd70cf 100644
--- a/forgeConfig/main.go
+++ b/forgeConfig/main.go
@@ -8,6 +8,9 @@ import (
"go.wit.com/log"
)
+// sent via ldflags
+var VERSION string
+
func main() {
var repos *forgepb.Repos
repos = new(forgepb.Repos)
@@ -15,6 +18,30 @@ func main() {
log.Warn("forgepb.ConfigLoad() failed", err)
os.Exit(-1)
}
+ if argv.List {
+ log.Info(forgepb.RepoHeader())
+ loop := repos.SortByName() // get the list of droplets
+ for loop.Scan() {
+ r := loop.Repo()
+ log.Info("repo:", r.Name, r.Gopath)
+ }
+ os.Exit(0)
+ }
+ if argv.Add {
+ log.Info("going to add a new repo", argv.Name, argv.GoPath)
+ new1 := new(forgepb.Repo)
+ new1.Name = argv.Name
+ new1.Gopath = argv.GoPath
+ if repos.Append(new1) {
+ log.Info("added", new1.Name, "ok")
+ } else {
+ log.Info("added", new1.Name, "failed")
+ os.Exit(-1)
+ }
+ repos.ConfigSave()
+ os.Exit(0)
+ }
+
testAddRepos(repos)
repos.ConfigSave()
}