Przeglądaj źródła

feat: --mode flag passed to tui

adamdottv 7 miesięcy temu
rodzic
commit
6603d9a9f0

+ 5 - 0
packages/opencode/src/cli/cmd/tui.ts

@@ -31,6 +31,10 @@ export const TuiCommand = cmd({
         alias: ["p"],
         type: "string",
         describe: "prompt to use",
+      })
+      .option("mode", {
+        type: "string",
+        describe: "mode to use",
       }),
   handler: async (args) => {
     while (true) {
@@ -78,6 +82,7 @@ export const TuiCommand = cmd({
             ...cmd,
             ...(args.model ? ["--model", args.model] : []),
             ...(args.prompt ? ["--prompt", args.prompt] : []),
+            ...(args.mode ? ["--mode", args.mode] : []),
           ],
           cwd,
           stdout: "inherit",

+ 2 - 1
packages/tui/cmd/opencode/main.go

@@ -27,6 +27,7 @@ func main() {
 
 	var model *string = flag.String("model", "", "model to begin with")
 	var prompt *string = flag.String("prompt", "", "prompt to begin with")
+	var mode *string = flag.String("mode", "", "mode to begin with")
 	flag.Parse()
 
 	url := os.Getenv("OPENCODE_SERVER")
@@ -68,7 +69,7 @@ func main() {
 	ctx, cancel := context.WithCancel(context.Background())
 	defer cancel()
 
-	app_, err := app.New(ctx, version, appInfo, modes, httpClient, model, prompt)
+	app_, err := app.New(ctx, version, appInfo, modes, httpClient, model, prompt, mode)
 	if err != nil {
 		panic(err)
 	}

+ 10 - 4
packages/tui/internal/app/app.go

@@ -39,6 +39,7 @@ type App struct {
 	Commands      commands.CommandRegistry
 	InitialModel  *string
 	InitialPrompt *string
+	IntitialMode  *string
 	compactCancel context.CancelFunc
 }
 
@@ -70,8 +71,9 @@ func New(
 	appInfo opencode.App,
 	modes []opencode.Mode,
 	httpClient *opencode.Client,
-	model *string,
-	prompt *string,
+	initialModel *string,
+	initialPrompt *string,
+	initialMode *string,
 ) (*App, error) {
 	util.RootPath = appInfo.Path.Root
 	util.CwdPath = appInfo.Path.Cwd
@@ -106,6 +108,9 @@ func New(
 	if appState.Mode != "" {
 		modeName = appState.Mode
 	}
+	if initialMode != nil && *initialMode != "" {
+		modeName = *initialMode
+	}
 	for i, m := range modes {
 		if m.Name == modeName {
 			modeIndex = i
@@ -154,8 +159,9 @@ func New(
 		Session:       &opencode.Session{},
 		Messages:      []opencode.MessageUnion{},
 		Commands:      commands.LoadFromConfig(configInfo),
-		InitialModel:  model,
-		InitialPrompt: prompt,
+		InitialModel:  initialModel,
+		InitialPrompt: initialPrompt,
+		IntitialMode:  initialMode,
 	}
 
 	return app, nil

+ 1 - 0
packages/web/src/content/docs/docs/cli.mdx

@@ -129,3 +129,4 @@ The opencode CLI takes the following flags.
 | `--print-logs` |       | Print logs to stderr |
 | `--prompt`     | `-p`  | Prompt to use        |
 | `--model`      | `-m`  | Model to use in the form of provider/model |
+| `--mode`       |       | Mode to use          |