Skip to content

Open source AI coding agent. Designed for large projects and real world tasks.

refactor for consistent 'no current plan' error

Dane Schneidera80ecc2141d0
diff --git a/app/cli/cmd/apply.go b/app/cli/cmd/apply.go
index 7e35d03d..b93919ba 100644
--- a/app/cli/cmd/apply.go
+++ b/app/cli/cmd/apply.go
@@ -1,9 +1,9 @@
package cmd
import (
- "fmt"
"plandex/auth"
"plandex/lib"
+ "plandex/term"
"github.com/spf13/cobra"
)
@@ -28,8 +28,7 @@ func apply(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
if lib.CurrentPlanId == "" {
- fmt.Println("πŸ€·β€β™‚οΈ No current plan")
- return
+ term.OutputNoCurrentPlanErrorAndExit()
}
lib.MustApplyPlan(lib.CurrentPlanId, lib.CurrentBranch, autoConfirm)
diff --git a/app/cli/cmd/branches.go b/app/cli/cmd/branches.go
index 2dee665d..da27098e 100644
--- a/app/cli/cmd/branches.go
+++ b/app/cli/cmd/branches.go
@@ -31,8 +31,7 @@ func branches(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
if lib.CurrentPlanId == "" {
- fmt.Println("πŸ€·β€β™‚οΈ No current plan")
- return
+ term.OutputNoCurrentPlanErrorAndExit()
}
term.StartSpinner("")
diff --git a/app/cli/cmd/build.go b/app/cli/cmd/build.go
index 01fd78bb..bc447cdd 100644
--- a/app/cli/cmd/build.go
+++ b/app/cli/cmd/build.go
@@ -32,8 +32,7 @@ func build(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
if lib.CurrentPlanId == "" {
- fmt.Println("πŸ€·β€β™‚οΈ No current plan")
- return
+ term.OutputNoCurrentPlanErrorAndExit()
}
apiKeys := lib.MustVerifyApiKeys()
diff --git a/app/cli/cmd/checkout.go b/app/cli/cmd/checkout.go
index 10f0b2ef..493fc5d9 100644
--- a/app/cli/cmd/checkout.go
+++ b/app/cli/cmd/checkout.go
@@ -35,8 +35,7 @@ func checkout(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
if lib.CurrentPlanId == "" {
- fmt.Println("πŸ€·β€β™‚οΈ No current plan")
- return
+ term.OutputNoCurrentPlanErrorAndExit()
}
branchName := ""
diff --git a/app/cli/cmd/clear.go b/app/cli/cmd/clear.go
index ad1e17ad..18c32ed2 100644
--- a/app/cli/cmd/clear.go
+++ b/app/cli/cmd/clear.go
@@ -23,8 +23,7 @@ func clearAllContext(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
if lib.CurrentPlanId == "" {
- fmt.Println("πŸ€·β€β™‚οΈ No current plan")
- return
+ term.OutputNoCurrentPlanErrorAndExit()
}
term.StartSpinner("")
diff --git a/app/cli/cmd/connect.go b/app/cli/cmd/connect.go
index 495fd041..796714a3 100644
--- a/app/cli/cmd/connect.go
+++ b/app/cli/cmd/connect.go
@@ -32,8 +32,7 @@ func connect(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
if lib.CurrentPlanId == "" {
- fmt.Println("πŸ€·β€β™‚οΈ No current plan")
- return
+ term.OutputNoCurrentPlanErrorAndExit()
}
planId, branch, shouldContinue := lib.SelectActiveStream(args)
diff --git a/app/cli/cmd/continue.go b/app/cli/cmd/continue.go
index dad0b8cf..11b15b38 100644
--- a/app/cli/cmd/continue.go
+++ b/app/cli/cmd/continue.go
@@ -1,10 +1,10 @@
package cmd
import (
- "fmt"
"plandex/auth"
"plandex/lib"
"plandex/plan_exec"
+ "plandex/term"
"github.com/plandex/plandex/shared"
"github.com/spf13/cobra"
@@ -30,8 +30,7 @@ func doContinue(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
if lib.CurrentPlanId == "" {
- fmt.Println("πŸ€·β€β™‚οΈ No current plan")
- return
+ term.OutputNoCurrentPlanErrorAndExit()
}
apiKeys := lib.MustVerifyApiKeys()
diff --git a/app/cli/cmd/current.go b/app/cli/cmd/current.go
index 104bd935..5d84745f 100644
--- a/app/cli/cmd/current.go
+++ b/app/cli/cmd/current.go
@@ -32,8 +32,7 @@ func current(cmd *cobra.Command, args []string) {
lib.MaybeResolveProject()
if lib.CurrentPlanId == "" {
- fmt.Println("πŸ€·β€β™‚οΈ No current plan")
- return
+ term.OutputNoCurrentPlanErrorAndExit()
}
term.StartSpinner("")
diff --git a/app/cli/cmd/delete_branch.go b/app/cli/cmd/delete_branch.go
index 42443efb..92d6fc99 100644
--- a/app/cli/cmd/delete_branch.go
+++ b/app/cli/cmd/delete_branch.go
@@ -30,8 +30,7 @@ func deleteBranch(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
if lib.CurrentPlanId == "" {
- fmt.Println("πŸ€·β€β™‚οΈ No current plan")
- return
+ term.OutputNoCurrentPlanErrorAndExit()
}
var branch string
diff --git a/app/cli/cmd/diffs.go b/app/cli/cmd/diffs.go
index c07acb12..c20270dd 100644
--- a/app/cli/cmd/diffs.go
+++ b/app/cli/cmd/diffs.go
@@ -1,7 +1,6 @@
package cmd
import (
- "fmt"
"plandex/api"
"plandex/auth"
"plandex/lib"
@@ -26,8 +25,7 @@ func diffs(cmd *cobra.Command, args []string) {
lib.MaybeResolveProject()
if lib.CurrentPlanId == "" {
- fmt.Println("πŸ€·β€β™‚οΈ No current plan")
- return
+ term.OutputNoCurrentPlanErrorAndExit()
}
diffs, err := api.Client.GetPlanDiffs(lib.CurrentPlanId, lib.CurrentBranch)
diff --git a/app/cli/cmd/load.go b/app/cli/cmd/load.go
index d94a5861..803ec93c 100644
--- a/app/cli/cmd/load.go
+++ b/app/cli/cmd/load.go
@@ -38,7 +38,7 @@ func contextLoad(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
if lib.CurrentPlanId == "" {
- fmt.Println("πŸ€·β€β™‚οΈ No current plan")
+ term.OutputNoCurrentPlanErrorAndExit()
return
}
diff --git a/app/cli/cmd/log.go b/app/cli/cmd/log.go
index c86ce036..3c02d2ff 100644
--- a/app/cli/cmd/log.go
+++ b/app/cli/cmd/log.go
@@ -32,8 +32,7 @@ func runLog(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
if lib.CurrentPlanId == "" {
- fmt.Println("No current plan")
- return
+ term.OutputNoCurrentPlanErrorAndExit()
}
term.StartSpinner("")
diff --git a/app/cli/cmd/models.go b/app/cli/cmd/models.go
index ed5096c4..5702d43a 100644
--- a/app/cli/cmd/models.go
+++ b/app/cli/cmd/models.go
@@ -209,7 +209,7 @@ func models(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
if lib.CurrentPlanId == "" {
- term.OutputErrorAndExit("No current plan")
+ term.OutputNoCurrentPlanErrorAndExit()
}
term.StartSpinner("")
diff --git a/app/cli/cmd/ps.go b/app/cli/cmd/ps.go
index bdf8f5f9..9bc96757 100644
--- a/app/cli/cmd/ps.go
+++ b/app/cli/cmd/ps.go
@@ -29,8 +29,7 @@ func ps(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
if lib.CurrentPlanId == "" {
- fmt.Println("πŸ€·β€β™‚οΈ No current plan")
- return
+ term.OutputNoCurrentPlanErrorAndExit()
}
term.StartSpinner("")
diff --git a/app/cli/cmd/rename.go b/app/cli/cmd/rename.go
index 4c45cc11..7f041eab 100644
--- a/app/cli/cmd/rename.go
+++ b/app/cli/cmd/rename.go
@@ -27,8 +27,7 @@ func rename(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
if lib.CurrentPlanId == "" {
- fmt.Println("πŸ€·β€β™‚οΈ No current plan")
- return
+ term.OutputNoCurrentPlanErrorAndExit()
}
var newName string
diff --git a/app/cli/cmd/rewind.go b/app/cli/cmd/rewind.go
index 2d101b31..667413d3 100644
--- a/app/cli/cmd/rewind.go
+++ b/app/cli/cmd/rewind.go
@@ -35,8 +35,7 @@ func rewind(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
if lib.CurrentPlanId == "" {
- fmt.Println("πŸ€·β€β™‚οΈ No current plan")
- return
+ term.OutputNoCurrentPlanErrorAndExit()
}
var stepsOrSha string
diff --git a/app/cli/cmd/rm.go b/app/cli/cmd/rm.go
index c90eeb79..4ca22a93 100644
--- a/app/cli/cmd/rm.go
+++ b/app/cli/cmd/rm.go
@@ -26,8 +26,7 @@ func contextRm(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
if lib.CurrentPlanId == "" {
- fmt.Println("πŸ€·β€β™‚οΈ No current plan")
- return
+ term.OutputNoCurrentPlanErrorAndExit()
}
term.StartSpinner("")
diff --git a/app/cli/cmd/stop.go b/app/cli/cmd/stop.go
index a9a02d06..2d90739f 100644
--- a/app/cli/cmd/stop.go
+++ b/app/cli/cmd/stop.go
@@ -27,8 +27,7 @@ func stop(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
if lib.CurrentPlanId == "" {
- fmt.Println("πŸ€·β€β™‚οΈ No current plan")
- return
+ term.OutputNoCurrentPlanErrorAndExit()
}
planId, branch, shouldContinue := lib.SelectActiveStream(args)
diff --git a/app/cli/cmd/tell.go b/app/cli/cmd/tell.go
index 2c34eb34..0ac86b2c 100644
--- a/app/cli/cmd/tell.go
+++ b/app/cli/cmd/tell.go
@@ -48,8 +48,7 @@ func doTell(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
if lib.CurrentPlanId == "" {
- fmt.Println("πŸ€·β€β™‚οΈ No current plan")
- return
+ term.OutputNoCurrentPlanErrorAndExit()
}
apiKeys := lib.MustVerifyApiKeys()
diff --git a/app/cli/term/errors.go b/app/cli/term/errors.go
index f6920785..acf4daea 100644
--- a/app/cli/term/errors.go
+++ b/app/cli/term/errors.go
@@ -81,3 +81,10 @@ func OutputUnformattedErrorAndExit(msg string) {
fmt.Fprintln(os.Stderr, msg)
os.Exit(1)
}
+
+func OutputNoCurrentPlanErrorAndExit() {
+ fmt.Println("πŸ€·β€β™‚οΈ No current plan")
+ fmt.Println()
+ PrintCmds("", "new", "cd")
+ os.Exit(1)
+}