-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroot.go
More file actions
89 lines (79 loc) · 2.97 KB
/
Copy pathroot.go
File metadata and controls
89 lines (79 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"fmt"
"github.com/spf13/cobra"
"os"
)
var (
flagDirs []string
flagPrompt string
flagRepo string
flagYes bool
flagProfile string
flagOverview = false
flagNoOverview = false
flagNamespace string
flagNoUpdateCheck bool
)
var rootCmd = &cobra.Command{
Use: "oss-back2base [flags] [prompt]",
Short: "Containerized Claude Code (OSS)",
Long: `oss-back2base runs Claude Code in a Docker container with a
configurable MCP server registry, an outbound network firewall, and
persistent state. Configs and profiles live in ~/.config/back2base/.
Update: oss-back2base update`,
Args: cobra.ArbitraryArgs,
SilenceUsage: true,
SilenceErrors: true,
}
func init() {
rootCmd.Flags().StringArrayVarP(&flagDirs, "dir", "d", nil, "Mount an additional directory (repeatable)")
rootCmd.Flags().StringVarP(&flagPrompt, "prompt", "p", "", "Run a one-shot prompt and exit")
rootCmd.Flags().StringVarP(&flagRepo, "repo", "r", "", "Override the default repo mount")
rootCmd.PersistentFlags().BoolVarP(&flagYes, "yes", "y", false, "Skip confirmation prompts")
rootCmd.PersistentFlags().BoolVar(&flagNoUpdateCheck, "no-update-check", false, "Skip the once-daily new-release check")
rootCmd.Flags().StringVar(&flagProfile, "profile", "", "MCP server profile (auto, full, go, frontend, infra, research, minimal)")
rootCmd.Flags().BoolVar(&flagOverview, "overview", false, "Run a pre-launch repo overview before Claude starts")
rootCmd.Flags().BoolVar(&flagNoOverview, "no-overview", false, "Skip the pre-launch repo overview (overrides remembered preference)")
rootCmd.Flags().StringVar(&flagNamespace, "namespace", "", "Memory namespace (overrides auto-derivation from git remote or .back2base/namespace)")
// Prepend the workspace-aware banner to the default help output so
// the box contents always reflect the cwd, not a compile-time const.
defaultHelp := rootCmd.HelpFunc()
rootCmd.SetHelpFunc(func(c *cobra.Command, args []string) {
if c == rootCmd {
fmt.Print(Banner())
}
defaultHelp(c, args)
})
rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
home := os.Getenv("HOME")
_ = home // legacy-launcher detection removed in OSS build
if shouldRunUpdateCheck(cmd) {
if info := checkForUpdates(); info != nil {
fmt.Fprintf(os.Stderr,
":: update available: v%s -> %s (run `oss-back2base update`)\n",
info.Current, info.Latest)
}
}
return nil
}
}
// shouldRunUpdateCheck returns true when the current invocation should
// perform the once-daily nag check. We skip it for `version`, `update`,
// and `selfupdate` (subcommand or any descendant), and when the user
// passed --no-update-check.
func shouldRunUpdateCheck(cmd *cobra.Command) bool {
if flagNoUpdateCheck {
return false
}
for c := cmd; c != nil; c = c.Parent() {
switch c.Name() {
case "version", "update", "selfupdate":
return false
}
}
return true
}
func Execute() error {
return rootCmd.Execute()
}