Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/cli/exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ func NewCloudClient() (*ags.Client, error) {
// disabled by global flags.
func NonInteractive() bool { return nonInteractive }

// IsJSONOutput reports whether the resolved output format is JSON or NDJSON.
func IsJSONOutput() bool { return isJSON() || isNDJSON() }

// NoColor reports whether ANSI color/escape output is disabled.
func NoColor() bool { return noColor }

// CfgFile returns the config file path supplied on the command line.
func CfgFile() string { return cfgFile }

Expand Down
13 changes: 13 additions & 0 deletions internal/commands/instance/create/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"strings"

"github.com/TencentCloudAgentRuntime/ags-cli/internal/apicli"
"github.com/TencentCloudAgentRuntime/ags-cli/internal/cli"
"github.com/TencentCloudAgentRuntime/ags-cli/internal/command"
instanceview "github.com/TencentCloudAgentRuntime/ags-cli/internal/commands/instance/internal/instanceview"
"github.com/TencentCloudAgentRuntime/ags-cli/internal/output"
"github.com/TencentCloudAgentRuntime/ags-cli/internal/progress"
ags "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ags/v20250920"
)

Expand All @@ -36,6 +38,7 @@ func Module() command.Module {
Source: "mixed-api",
},
Build: func(deps command.Deps) (command.Runtime, error) {
deps = deps.WithDefaults()
builder := apicli.NewRequestBuilder(api)
executor := apicli.NewExecutor(api, deps.ControlPlane)
return command.Runtime{Handler: command.HandlerFunc(func(ctx context.Context, req command.Request) (*command.Result, error) {
Expand All @@ -48,22 +51,32 @@ func Module() command.Module {
if err != nil {
return nil, err
}

// Show spinner for interactive text mode only.
sp := progress.NewForCLI(deps.IO.ErrOut, cli.IsJSONOutput(), cli.NonInteractive(), deps.IO.IsStderrTTY(), cli.NoColor())
sp.Start("Creating instance...")

result, err := executor.Execute(ctx, apiReq)
if err != nil {
sp.Stop("✗", "Failed to create instance")
return nil, err
}
response, ok := result.Data.(*ags.StartSandboxInstanceResponseParams)
if !ok {
// Response type mismatch — we cannot confirm creation succeeded.
sp.Cleanup()
return result, nil
}
if response.Instance == nil {
sp.Stop("✗", "Failed to create instance")
return nil, output.NewCLIError(&output.Failure{
Code: "INTERNAL_ERROR",
Kind: output.KindGenericError,
Message: "no instance returned from API",
Hint: "Rerun with --debug. If the issue persists, inspect the control-plane response.",
})
}
sp.Stop("✓", "Instance created")
return instanceCreateResult(response, result), nil
})}, nil
},
Expand Down
Loading