From e8e842929fb05149c83ec8e585e3b4470f7d6abc Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 5 Oct 2025 05:42:22 -0500 Subject: adding new argv --- argv.go | 41 ++++++++++++++++++++++++++++++----------- main.go | 7 ++++++- structs.go | 17 +++++++++++++++++ 3 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 structs.go diff --git a/argv.go b/argv.go index 3f78de3..e1756cc 100644 --- a/argv.go +++ b/argv.go @@ -1,27 +1,46 @@ package main +import ( + "os" + + "go.wit.com/lib/gui/prep" +) + /* this parses the command line arguements this enables command line options from other packages like 'gui' and 'log' */ -import ( - "go.wit.com/dev/alexflint/arg" -) - var argv args type args struct { - ListRepos bool `arg:"--list-repos" help:"list all repositories"` - Port int `arg:"--port" default:"2520" help:"port to run on"` - RepoMap string `arg:"--repomap" default:"/etc/gowebd/repomap" help:"repomap file"` - Hostname string `arg:"--hostname" default:"go.wit.com" help:"hostname to use"` + Test *EmptyCmd `arg:"subcommand:test" help:"test repomap"` + ListRepos bool `arg:"--list-repos" help:"list all repositories"` + Port int `arg:"--port" default:"2520" help:"port to run on"` + RepoMap string `arg:"--repomap" default:"/etc/gowebd/repomap" help:"repomap file"` + Hostname string `arg:"--hostname" default:"go.wit.com" help:"hostname to use"` +} + +type EmptyCmd struct { } func (args) Version() string { - return "gowebd " + VERSION + " Built on " + BUILDTIME + return ARGNAME + " " + VERSION + " Built on " + BUILDTIME +} + +func (args) Buildtime() (string, string) { + return BUILDTIME, VERSION +} + +func (args) Appname() string { + return ARGNAME } -func init() { - arg.MustParse(&argv) +func (a args) DoAutoComplete(pb *prep.Auto) { + if pb.Cmd == "" { + pb.Autocomplete3([]string{"test", "--version", "--force"}) + } else { + pb.SubCommand(pb.Goargs...) + } + os.Exit(0) } diff --git a/main.go b/main.go index d833b38..6e87070 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "net/http" "time" + "go.wit.com/lib/gui/prep" "go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" @@ -18,7 +19,8 @@ var BUILDTIME string //go:embed resources/* var resources embed.FS -// var accessf, clientf *os.File +// used for shell auto completion +var ARGNAME string = "gowebd" var repoMap map[string]string var gitMap map[string]*gitpb.Repo @@ -32,6 +34,9 @@ var FOOTER string = "/etc/gowebd/footer.html" var LIBDIR string = "/var/lib/gowebd/" func main() { + me = new(mainType) + me.sh = prep.Bash(&argv) // adds shell auto complete to go-args + if argv.RepoMap != "" { REPOMAP = argv.RepoMap } diff --git a/structs.go b/structs.go new file mode 100644 index 0000000..af1e4a1 --- /dev/null +++ b/structs.go @@ -0,0 +1,17 @@ +// 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/lib/gui/prep" + "go.wit.com/lib/protobuf/forgepb" +) + +var me *mainType + +// this app's variables +type mainType struct { + sh *prep.Auto // shell autocomplete + forge *forgepb.Forge // for holding the forge protobuf files +} -- cgit v1.2.3