From b5240fccf2df4a6f2a4ee99847a9d5c3901fe4a5 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 28 Oct 2025 12:11:57 -0500 Subject: better argv handling --- argv.go | 20 +++++++------- doVerify.go | 76 ---------------------------------------------------- doVerifyNamespace.go | 65 ++++++++++++++++++++++++++++++++++++++++++++ subCommand.go | 7 +++-- 4 files changed, 78 insertions(+), 90 deletions(-) delete mode 100644 doVerify.go create mode 100644 doVerifyNamespace.go diff --git a/argv.go b/argv.go index 4d1b935..fc828e9 100644 --- a/argv.go +++ b/argv.go @@ -10,12 +10,12 @@ package main var argv args type args struct { - Rebuild *RebuildCmd `arg:"subcommand:rebuild" help:"download all the forge sources and rebuild forge"` - Generate *GenerateCmd `arg:"subcommand:generate" help:"helps run autogenpb in repos with .proto files"` Show *ShowCmd `arg:"subcommand:show" help:"show tables"` - Clean *EmptyCmd `arg:"subcommand:clean" help:"'git clean' + reset repos to original state"` Commit *CommitCmd `arg:"subcommand:commit" help:"'git commit'"` Merge *MergeCmd `arg:"subcommand:merge" help:"merge branches"` + Rebuild *RebuildCmd `arg:"subcommand:rebuild" help:"download all the forge sources and rebuild forge"` + Generate *GenerateCmd `arg:"subcommand:generate" help:"helps run autogenpb in repos with .proto files"` + Clean *EmptyCmd `arg:"subcommand:clean" help:"'git clean' + reset repos to original state"` Pull *PullCmd `arg:"subcommand:pull" help:"'git pull'"` Normal *EmptyCmd `arg:"subcommand:normal" help:"shortcut to 'forge mode normal'"` Patch *PatchCmd `arg:"subcommand:patch" help:"work with patches"` @@ -62,8 +62,7 @@ type FixCmd struct { } type VerifyCmd struct { - Namespace *EmptyCmd `arg:"subcommand:namespace" help:"check the namespaces"` - DryRun bool `arg:"--dry-run" help:"try not to change anything"` + DryRun bool `arg:"--dry-run" help:"try not to change anything"` } type StatsCmd struct { @@ -101,11 +100,12 @@ type CommitCmd struct { } type DevCmd struct { - Build *EmptyCmd `arg:"subcommand:build" help:"build this repo"` - Install *EmptyCmd `arg:"subcommand:install" help:"build & install this repo"` - Fixer *FixCmd `arg:"subcommand:fixer" help:"send in the fixer"` - URL string `arg:"--connect" help:"forge url"` - Stats *StatsCmd `arg:"subcommand:stats" help:"generate origin.pb"` + Build *EmptyCmd `arg:"subcommand:build" help:"build this repo"` + Install *EmptyCmd `arg:"subcommand:install" help:"build & install this repo"` + Fixer *FixCmd `arg:"subcommand:fixer" help:"send in the fixer"` + URL string `arg:"--connect" help:"forge url"` + Stats *StatsCmd `arg:"subcommand:stats" help:"generate origin.pb"` + Namespace *EmptyCmd `arg:"subcommand:namespace" help:"check the namespaces"` } type GenerateCmd struct { diff --git a/doVerify.go b/doVerify.go deleted file mode 100644 index 846c4b9..0000000 --- a/doVerify.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2017-2025 WIT.COM Inc. All rights reserved. -// Use of this source code is governed by the GPL 3.0 - -package main - -import ( - "errors" - "path/filepath" - - "go.wit.com/lib/env" - "go.wit.com/lib/protobuf/gitpb" - "go.wit.com/log" -) - -func doVerify() (string, error) { - var s string = "doVerify()" - var err error - - if argv.Verify.Namespace != nil { - s, err = doVerifyNamespace() - } - - return s, err -} - -func cleanNamespace(r *gitpb.Repo) string { - // check for GO repos - gowork := env.Get("gopath") - // todo: detect if using go.work file - newpath, err := filepath.Rel(gowork, r.FullPath) - // log.Info("cleanNamespace()", newpath, gowork, "is gowork. fullpath:", r.FullPath) - if err == nil { - // log.Info("cleanNamespace returned", newpath) - // relative path to gosrc or gowork is the namespace - return newpath - } - log.Info("cleanNamespace got err", newpath, err) - // check for other stuff. use the URLs - return "" -} - -// checks to see if the r.Namespace seems right -func doVerifyNamespace() (string, error) { - var s string = "doVerifyNamespace()" - var err error - var counter int - for r := range me.forge.Repos.IterAll() { - newpath := cleanNamespace(r) - if newpath == "" { - // log.Info("didn't work", r.Namespace, "to", newpath) - // didn't work - } else if newpath == r.Namespace { - // already good namespace. - continue - } else if newpath != r.Namespace { - counter += 1 - log.Info("Changed", r.FullPath, "to", newpath) - r.Namespace = newpath - continue - } - counter += 1 - log.Info("cleanNamespace() didn't match", r.Namespace) - } - if counter != 0 { - err = errors.New(log.Sprintf("%d namespaces were invalid", counter)) - } - - if env.True("DryRun") { - return s, err - } - if counter != 0 { - me.forge.Repos.SaveVerbose() - } - - return s, err -} diff --git a/doVerifyNamespace.go b/doVerifyNamespace.go new file mode 100644 index 0000000..b3a6820 --- /dev/null +++ b/doVerifyNamespace.go @@ -0,0 +1,65 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "errors" + "path/filepath" + + "go.wit.com/lib/env" + "go.wit.com/lib/protobuf/gitpb" + "go.wit.com/log" +) + +func cleanNamespace(r *gitpb.Repo) string { + // check for GO repos + gowork := env.Get("gopath") + // todo: detect if using go.work file + newpath, err := filepath.Rel(gowork, r.FullPath) + // log.Info("cleanNamespace()", newpath, gowork, "is gowork. fullpath:", r.FullPath) + if err == nil { + // log.Info("cleanNamespace returned", newpath) + // relative path to gosrc or gowork is the namespace + return newpath + } + log.Info("cleanNamespace got err", newpath, err) + // check for other stuff. use the URLs + return "" +} + +// checks to see if the r.Namespace seems right +func doVerifyNamespace() (string, error) { + var s string = "doVerifyNamespace()" + var err error + var counter int + for r := range me.forge.Repos.IterAll() { + newpath := cleanNamespace(r) + if newpath == "" { + // log.Info("didn't work", r.Namespace, "to", newpath) + // didn't work + } else if newpath == r.Namespace { + // already good namespace. + continue + } else if newpath != r.Namespace { + counter += 1 + log.Info("Changed", r.FullPath, "to", newpath) + r.Namespace = newpath + continue + } + counter += 1 + log.Info("cleanNamespace() didn't match", r.Namespace) + } + if counter != 0 { + err = errors.New(log.Sprintf("%d namespaces were invalid", counter)) + } + + if env.True("DryRun") { + return s, err + } + if counter != 0 { + me.forge.Repos.SaveVerbose() + } + + return s, err +} diff --git a/subCommand.go b/subCommand.go index 57fdafb..be19e18 100644 --- a/subCommand.go +++ b/subCommand.go @@ -34,6 +34,9 @@ func doSubcommand() (string, error) { if argv.Dev.Stats != nil { s, err = doStats(argv.Dev.Stats) } + if argv.Dev.Namespace != nil { + s, err = doVerifyNamespace() + } } if argv.Clean != nil { @@ -90,9 +93,5 @@ func doSubcommand() (string, error) { s, err = doRebuild() } - if argv.Verify != nil { - s, err = doVerify() - } - return s, err } -- cgit v1.2.3