summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-04 20:38:30 -0500
committerJeff Carr <[email protected]>2025-10-04 20:38:30 -0500
commit2bf54fd5a2ba9aa1bbf900dc3ca07053a15dfb6a (patch)
tree54ade39680438548ea7fdba774760caac1e0a6ce
parent6c645cb22ab96a8154053071360f4e45523733ce (diff)
redo mode handlingv0.25.52
-rw-r--r--argv.go14
-rw-r--r--doAdd.go30
-rw-r--r--doNormal.go4
-rw-r--r--main.go27
4 files changed, 51 insertions, 24 deletions
diff --git a/argv.go b/argv.go
index d4f6cd2..5c6a44c 100644
--- a/argv.go
+++ b/argv.go
@@ -22,7 +22,7 @@ type args struct {
Config *ConfigCmd `arg:"subcommand:config" help:"show your .config/forge/ settings"`
Gui *EmptyCmd `arg:"subcommand:gui" help:"open the gui"`
Merge *MergeCmd `arg:"subcommand:merge" help:"merge branches"`
- Normal *NormalCmd `arg:"subcommand:user" help:"makes a user branch in every git repo (The Default)"`
+ Mode *ModeCmd `arg:"subcommand:mode" help:"sets the mode (hacking, merging, publishing)"`
Patch *PatchCmd `arg:"subcommand:patch" help:"make patchsets"`
Pull *PullCmd `arg:"subcommand:pull" help:"run 'git pull'"`
Show *ShowCmd `arg:"subcommand:show" help:"print out things"`
@@ -31,6 +31,7 @@ type args struct {
All bool `arg:"--all" help:"git commit --all"`
Force bool `arg:"--force" help:"try to strong-arm things"`
Verbose bool `arg:"--verbose" help:"show more output"`
+ Fix bool `arg:"--fix" help:"try to fix things"`
}
func (args) Examples() string {
@@ -69,10 +70,11 @@ type RepoCmd struct {
// ReadOnly bool `arg:"--readonly" help:"include read-only repos"`
}
-type NormalCmd struct {
- Fix *EmptyCmd `arg:"subcommand:fix" help:"try to fix problems"`
- On *EmptyCmd `arg:"subcommand:on" help:"turn normal mode on"`
- Off *EmptyCmd `arg:"subcommand:off" help:"turn normal mode off"`
+type ModeCmd struct {
+ Master *EmptyCmd `arg:"subcommand:master" help:"keep all repos on the master branch"`
+ Devel *EmptyCmd `arg:"subcommand:devel" help:"use user branches"`
+ User *EmptyCmd `arg:"subcommand:user" help:"use user branches"`
+ Normal *EmptyCmd `arg:"subcommand:normal" help:"use the 'normal' forge development mode"`
}
type CommitCmd struct {
@@ -197,7 +199,7 @@ func (args) Appname() string {
func (a args) DoAutoComplete(pb *prep.Auto) {
if pb.Cmd == "" {
- pb.Autocomplete3([]string{"checkout", "reset", "commit", "config", "gui", "merge", "user", "patch", "pull", "show", "add", "--version", "--force"})
+ pb.Autocomplete3([]string{"checkout", "reset", "commit", "config", "gui", "merge", "mode", "patch", "pull", "show", "add", "--version", "--force"})
} else {
pb.SubCommand(pb.Goargs...)
}
diff --git a/doAdd.go b/doAdd.go
new file mode 100644
index 0000000..ce819f5
--- /dev/null
+++ b/doAdd.go
@@ -0,0 +1,30 @@
+// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
+// Use of this source code is governed by the GPL 3.0
+
+package main
+
+import (
+ "os"
+ "strings"
+
+ "go.wit.com/lib/protobuf/gitpb"
+ "go.wit.com/log"
+)
+
+func doAdd() error {
+ wd, _ := os.Getwd()
+ found := gitpb.NewRepos()
+ for repo := range me.forge.Repos.IterAll() {
+ if strings.HasPrefix(repo.FullPath, wd) {
+ found.Append(repo)
+ }
+ }
+
+ if found.Len() > 0 {
+ me.forge.PrintDefaultTB(found)
+ return nil
+ }
+
+ log.Info("todo: scan", wd, "here")
+ return nil
+}
diff --git a/doNormal.go b/doNormal.go
index 9075b82..242a7be 100644
--- a/doNormal.go
+++ b/doNormal.go
@@ -35,7 +35,7 @@ func doNormal() bool {
}
repo := me.forge.Repos.FindByFullPath(path)
if stat.Err == ErrorLocalDevelBranch {
- if argv.Normal.Fix != nil {
+ if argv.Fix {
bname := repo.GetDevelBranchName()
s := fmt.Sprintf("repair the %s branch on %s", bname, repo.FullPath)
if fhelp.QuestionUser(s) {
@@ -47,7 +47,7 @@ func doNormal() bool {
}
}
if stat.Err == ErrorLocalMasterBranch {
- if argv.Normal.Fix != nil {
+ if argv.Fix {
bname := repo.GetMasterBranchName()
s := fmt.Sprintf("repair the %s branch on %s", bname, repo.FullPath)
if fhelp.QuestionUser(s) {
diff --git a/main.go b/main.go
index 9ec860d..f756f92 100644
--- a/main.go
+++ b/main.go
@@ -97,8 +97,8 @@ func main() {
okExit("")
}
- if argv.Normal != nil {
- if argv.Normal.On != nil {
+ if argv.Mode != nil {
+ if argv.Mode.Normal != nil {
if me.forge.Config.Mode == forgepb.ForgeMode_NORMAL {
log.Info("you are already in the normal state")
okExit("")
@@ -108,22 +108,12 @@ func main() {
okExit("")
}
- if argv.Normal.Off != nil {
- if me.forge.Config.Mode != forgepb.ForgeMode_NORMAL {
- log.Info("you were aleady not in the normal state")
- okExit("")
- }
- setForgeMode(forgepb.ForgeMode_DEVEL)
- log.Info("normal mode off")
+ if argv.Mode.User != nil {
+ setForgeMode(forgepb.ForgeMode_USER)
okExit("")
}
-
- if doNormal() {
- log.Infof("all %d repos are on your user branch. It is safe to write code now.\n", me.forge.Repos.Len())
- if me.forge.Config.Mode != forgepb.ForgeMode_NORMAL {
- log.Infof("Forge has set the mode to 'Normal'\n")
- setForgeMode(forgepb.ForgeMode_NORMAL)
- }
+ if argv.Mode.Master != nil {
+ setForgeMode(forgepb.ForgeMode_MASTER)
okExit("")
}
okExit("")
@@ -144,6 +134,11 @@ func main() {
okExit("")
}
+ if argv.Add != nil {
+ doAdd()
+ okExit("")
+ }
+
if argv.Pull != nil {
doPull()
okExit("")