diff options
| author | Jay V <[email protected]> | 2025-05-21 15:01:25 -0400 |
|---|---|---|
| committer | Jay V <[email protected]> | 2025-05-21 15:01:25 -0400 |
| commit | 9049295cc961b250be6144585dde322e778534d7 (patch) | |
| tree | c8a2f09ed6cea54eb9587243eb7dbe298fef1b20 /cmd/root.go | |
| parent | 4526b14b17dc49f3ef4f3b1a1d02eff5c6b6b59f (diff) | |
| parent | dff8e77eb6d1709fa1ddeb52d0d9c19afd13d385 (diff) | |
| download | opencode-9049295cc961b250be6144585dde322e778534d7.tar.gz opencode-9049295cc961b250be6144585dde322e778534d7.zip | |
Merge branch 'dev' into docs
Diffstat (limited to 'cmd/root.go')
| -rw-r--r-- | cmd/root.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/cmd/root.go b/cmd/root.go index 1e96e20c4..39d58eab6 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -15,6 +15,7 @@ import ( "github.com/sst/opencode/internal/app" "github.com/sst/opencode/internal/config" "github.com/sst/opencode/internal/db" + "github.com/sst/opencode/internal/format" "github.com/sst/opencode/internal/llm/agent" "github.com/sst/opencode/internal/logging" "github.com/sst/opencode/internal/lsp/discovery" @@ -88,6 +89,25 @@ to assist developers in writing, debugging, and understanding code directly from return err } + // Check if we're in non-interactive mode + prompt, _ := cmd.Flags().GetString("prompt") + if prompt != "" { + outputFormatStr, _ := cmd.Flags().GetString("output-format") + outputFormat := format.OutputFormat(outputFormatStr) + if !outputFormat.IsValid() { + return fmt.Errorf("invalid output format: %s", outputFormatStr) + } + + quiet, _ := cmd.Flags().GetBool("quiet") + verbose, _ := cmd.Flags().GetBool("verbose") + + // Get tool restriction flags + allowedTools, _ := cmd.Flags().GetStringSlice("allowedTools") + excludedTools, _ := cmd.Flags().GetStringSlice("excludedTools") + + return handleNonInteractiveMode(cmd.Context(), prompt, outputFormat, quiet, verbose, allowedTools, excludedTools) + } + // Run LSP auto-discovery if err := discovery.IntegrateLSPServers(cwd); err != nil { slog.Warn("Failed to auto-discover LSP servers", "error", err) @@ -296,4 +316,16 @@ func init() { rootCmd.Flags().BoolP("version", "v", false, "Version") rootCmd.Flags().BoolP("debug", "d", false, "Debug") rootCmd.Flags().StringP("cwd", "c", "", "Current working directory") + rootCmd.Flags().StringP("prompt", "p", "", "Run a single prompt in non-interactive mode") + rootCmd.Flags().StringP("output-format", "f", "text", "Output format for non-interactive mode (text, json)") + rootCmd.Flags().BoolP("quiet", "q", false, "Hide spinner in non-interactive mode") + rootCmd.Flags().BoolP("verbose", "", false, "Display logs to stderr in non-interactive mode") + rootCmd.Flags().StringSlice("allowedTools", nil, "Restrict the agent to only use the specified tools in non-interactive mode (comma-separated list)") + rootCmd.Flags().StringSlice("excludedTools", nil, "Prevent the agent from using the specified tools in non-interactive mode (comma-separated list)") + + // Make allowedTools and excludedTools mutually exclusive + rootCmd.MarkFlagsMutuallyExclusive("allowedTools", "excludedTools") + + // Make quiet and verbose mutually exclusive + rootCmd.MarkFlagsMutuallyExclusive("quiet", "verbose") } |
