Skip to content

Commit 73f43b1

Browse files
Copilotfriggeri
andcommitted
Add CLIArgs field to Go SDK for complete cross-SDK consistency
Co-authored-by: friggeri <106686+friggeri@users.noreply.github.com>
1 parent 9e40ff5 commit 73f43b1

4 files changed

Lines changed: 45 additions & 1 deletion

File tree

go/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Event types: `SessionLifecycleCreated`, `SessionLifecycleDeleted`, `SessionLifec
109109
**ClientOptions:**
110110

111111
- `CLIPath` (string): Path to CLI executable (default: "copilot" or `COPILOT_CLI_PATH` env var)
112+
- `CLIArgs` ([]string): Extra arguments to pass to the CLI executable (inserted before SDK-managed args)
112113
- `CLIUrl` (string): URL of existing CLI server (e.g., `"localhost:8080"`, `"http://127.0.0.1:9000"`, or just `"8080"`). When provided, the client will not spawn a CLI process.
113114
- `Cwd` (string): Working directory for CLI process
114115
- `Port` (int): Server port for TCP mode (default: 0 for random)

go/client.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ func NewClient(options *ClientOptions) *Client {
143143
if options.CLIPath != "" {
144144
opts.CLIPath = options.CLIPath
145145
}
146+
if options.CLIArgs != nil {
147+
opts.CLIArgs = options.CLIArgs
148+
}
146149
if options.Cwd != "" {
147150
opts.Cwd = options.Cwd
148151
}
@@ -994,7 +997,11 @@ func (c *Client) verifyProtocolVersion(ctx context.Context) error {
994997
// This spawns the CLI server as a subprocess using the configured transport
995998
// mode (stdio or TCP).
996999
func (c *Client) startCLIServer(ctx context.Context) error {
997-
args := []string{"--headless", "--no-auto-update", "--log-level", c.options.LogLevel}
1000+
// Start with user-provided CLI args (inserted before SDK-managed args)
1001+
args := append([]string{}, c.options.CLIArgs...)
1002+
1003+
// Add SDK-managed args
1004+
args = append(args, "--headless", "--no-auto-update", "--log-level", c.options.LogLevel)
9981005

9991006
// Choose transport mode
10001007
if c.useStdio {

go/client_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,40 @@ func TestClient_AuthOptions(t *testing.T) {
330330
})
331331
}
332332

333+
func TestClient_CLIArgs(t *testing.T) {
334+
t.Run("should default CLIArgs to nil when not provided", func(t *testing.T) {
335+
client := NewClient(&ClientOptions{})
336+
337+
if client.options.CLIArgs != nil {
338+
t.Errorf("Expected CLIArgs to be nil, got %v", client.options.CLIArgs)
339+
}
340+
})
341+
342+
t.Run("should accept CLIArgs option", func(t *testing.T) {
343+
args := []string{"--custom-flag", "--another-arg", "value"}
344+
client := NewClient(&ClientOptions{
345+
CLIArgs: args,
346+
})
347+
348+
if !reflect.DeepEqual(client.options.CLIArgs, args) {
349+
t.Errorf("Expected CLIArgs to be %v, got %v", args, client.options.CLIArgs)
350+
}
351+
})
352+
353+
t.Run("should store empty CLIArgs slice", func(t *testing.T) {
354+
client := NewClient(&ClientOptions{
355+
CLIArgs: []string{},
356+
})
357+
358+
if client.options.CLIArgs == nil {
359+
t.Error("Expected CLIArgs to be non-nil empty slice")
360+
}
361+
if len(client.options.CLIArgs) != 0 {
362+
t.Errorf("Expected 0 CLI args, got %d", len(client.options.CLIArgs))
363+
}
364+
})
365+
}
366+
333367
func TestClient_EnvOptions(t *testing.T) {
334368
t.Run("should store custom environment variables", func(t *testing.T) {
335369
client := NewClient(&ClientOptions{

go/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const (
1616
type ClientOptions struct {
1717
// CLIPath is the path to the Copilot CLI executable (default: "copilot")
1818
CLIPath string
19+
// CLIArgs are extra arguments to pass to the CLI executable (inserted before SDK-managed args)
20+
CLIArgs []string
1921
// Cwd is the working directory for the CLI process (default: "" = inherit from current process)
2022
Cwd string
2123
// Port for TCP transport (default: 0 = random port)

0 commit comments

Comments
 (0)