Skip to content

Commit f98309a

Browse files
authored
Merge pull request #445 from dgageot/consistant-flags
Consistant flags
2 parents aef1b81 + b237b22 commit f98309a

5 files changed

Lines changed: 23 additions & 17 deletions

File tree

cmd/root/api.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,12 @@ import (
99

1010
"github.com/spf13/cobra"
1111

12-
"github.com/docker/cagent/pkg/config"
1312
"github.com/docker/cagent/pkg/server"
1413
"github.com/docker/cagent/pkg/session"
1514
"github.com/docker/cagent/pkg/teamloader"
1615
"github.com/docker/cagent/pkg/telemetry"
1716
)
1817

19-
var (
20-
listenAddr string
21-
sessionDb string
22-
runConfig config.RuntimeConfig
23-
)
24-
2518
// NewApiCmd creates a new api command
2619
func NewApiCmd() *cobra.Command {
2720
cmd := &cobra.Command{
@@ -37,10 +30,8 @@ func NewApiCmd() *cobra.Command {
3730

3831
cmd.PersistentFlags().StringVarP(&listenAddr, "listen", "l", ":8080", "Address to listen on")
3932
cmd.PersistentFlags().StringVarP(&sessionDb, "session-db", "s", "session.db", "Path to the session database")
40-
cmd.PersistentFlags().StringSliceVar(&runConfig.EnvFiles, "env-from-file", nil, "Set environment variables from file")
41-
cmd.PersistentFlags().BoolVar(&runConfig.GlobalCodeMode, "code-mode-tools", false, "Provide a single tool to call other tools via Javascript")
42-
cmd.PersistentFlags().StringVar(&runConfig.RedirectURI, "redirect-uri", "", "Set the redirect URI for OAuth2 flows")
4333
addGatewayFlags(cmd)
34+
addRuntimeConfigFlags(cmd)
4435

4536
return cmd
4637
}

cmd/root/eval.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ func NewEvalCmd() *cobra.Command {
1818
RunE: runEvalCommand,
1919
}
2020

21-
cmd.PersistentFlags().StringSliceVar(&runConfig.EnvFiles, "env-from-file", nil, "Set environment variables from file")
22-
cmd.PersistentFlags().BoolVar(&runConfig.GlobalCodeMode, "code-mode-tools", false, "Provide a single tool to call other tools via Javascript")
2321
addGatewayFlags(cmd)
22+
addRuntimeConfigFlags(cmd)
2423

2524
return cmd
2625
}

cmd/root/exec.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ func NewExecCmd() *cobra.Command {
1111
}
1212

1313
cmd.PersistentFlags().StringVarP(&agentName, "agent", "a", "root", "Name of the agent to run")
14-
cmd.PersistentFlags().StringSliceVar(&runConfig.EnvFiles, "env-from-file", nil, "Set environment variables from file")
15-
cmd.PersistentFlags().BoolVar(&runConfig.GlobalCodeMode, "code-mode-tools", false, "Provide a single tool to call other tools via Javascript")
1614
cmd.PersistentFlags().StringVar(&workingDir, "working-dir", "", "Set the working directory for the session (applies to tools and relative paths)")
1715
cmd.PersistentFlags().BoolVar(&autoApprove, "yolo", false, "Automatically approve all tool calls without prompting")
1816
cmd.PersistentFlags().StringVar(&attachmentPath, "attach", "", "Attach an image file to the message")
19-
2017
cmd.PersistentFlags().BoolVar(&dryRun, "dry-run", false, "Initialize the agent without executing anything")
2118
_ = cmd.PersistentFlags().MarkHidden("dry-run")
2219

2320
addGatewayFlags(cmd)
21+
addRuntimeConfigFlags(cmd)
2422

2523
return cmd
2624
}

cmd/root/flags.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package root
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
"github.com/docker/cagent/pkg/config"
7+
)
8+
9+
var (
10+
listenAddr string
11+
sessionDb string
12+
runConfig config.RuntimeConfig
13+
)
14+
15+
func addRuntimeConfigFlags(cmd *cobra.Command) {
16+
cmd.PersistentFlags().StringSliceVar(&runConfig.EnvFiles, "env-from-file", nil, "Set environment variables from file")
17+
cmd.PersistentFlags().StringVar(&runConfig.RedirectURI, "redirect-uri", "", "Set the redirect URI for OAuth2 flows")
18+
cmd.PersistentFlags().BoolVar(&runConfig.GlobalCodeMode, "code-mode-tools", false, "Provide a single tool to call other tools via Javascript")
19+
}

cmd/root/run.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ func NewRunCmd() *cobra.Command {
6262
}
6363

6464
cmd.PersistentFlags().StringVarP(&agentName, "agent", "a", "root", "Name of the agent to run")
65-
cmd.PersistentFlags().StringSliceVar(&runConfig.EnvFiles, "env-from-file", nil, "Set environment variables from file")
66-
cmd.PersistentFlags().BoolVar(&runConfig.GlobalCodeMode, "code-mode-tools", false, "Provide a single tool to call other tools via Javascript")
6765
cmd.PersistentFlags().StringVar(&workingDir, "working-dir", "", "Set the working directory for the session (applies to tools and relative paths)")
6866
cmd.PersistentFlags().BoolVar(&autoApprove, "yolo", false, "Automatically approve all tool calls without prompting")
6967
cmd.PersistentFlags().StringVar(&attachmentPath, "attach", "", "Attach an image file to the message")
@@ -75,6 +73,7 @@ func NewRunCmd() *cobra.Command {
7573
f.NoOptDefVal = commandListSentinel
7674
}
7775
addGatewayFlags(cmd)
76+
addRuntimeConfigFlags(cmd)
7877

7978
return cmd
8079
}

0 commit comments

Comments
 (0)