Skip to content
Open
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
22 changes: 19 additions & 3 deletions components/ambient-cli/cmd/acpctl/create/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"context"
"fmt"
"strings"
"time"

"github.com/ambient-code/platform/components/ambient-cli/pkg/config"
"github.com/ambient-code/platform/components/ambient-cli/pkg/connection"
"github.com/ambient-code/platform/components/ambient-cli/pkg/output"
sdkclient "github.com/ambient-code/platform/components/ambient-sdk/go-sdk/client"
Expand Down Expand Up @@ -60,7 +60,12 @@ func run(cmd *cobra.Command, cmdArgs []string) error {
return err
}

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
cfg, err := config.Load()
if err != nil {
return err
}

ctx, cancel := context.WithTimeout(context.Background(), cfg.GetRequestTimeout())
defer cancel()

switch resource {
Expand Down Expand Up @@ -88,7 +93,18 @@ func createSession(cmd *cobra.Command, ctx context.Context, client *sdkclient.Cl
return fmt.Errorf("--name is required")
}

builder := sdktypes.NewSessionBuilder().Name(createArgs.name)
// Get current project from config
cfg, err := config.Load()
if err != nil {
return fmt.Errorf("load config: %w", err)
}

currentProject := cfg.GetProject()
if currentProject == "" {
return fmt.Errorf("no project set; run 'acpctl project <name>' first")
}

builder := sdktypes.NewSessionBuilder().Name(createArgs.name).ProjectID(currentProject)

if createArgs.prompt != "" {
builder = builder.Prompt(createArgs.prompt)
Expand Down
13 changes: 10 additions & 3 deletions components/ambient-cli/cmd/acpctl/delete/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ var Cmd = &cobra.Command{

Valid resource types:
project (aliases: proj)
project-settings (aliases: ps)`,
project-settings (aliases: ps)
session (aliases: sess)`,
Args: cobra.ExactArgs(2),
RunE: run,
}
Expand Down Expand Up @@ -71,8 +72,14 @@ func run(cmd *cobra.Command, cmdArgs []string) error {
fmt.Fprintf(cmd.OutOrStdout(), "project-settings/%s deleted\n", name)
return nil

// TODO: Add "session" deletion once the SDK exposes Sessions().Delete().
case "session", "sessions", "sess":
if err := client.Sessions().Delete(ctx, name); err != nil {
return fmt.Errorf("delete session %q: %w", name, err)
}
fmt.Fprintf(cmd.OutOrStdout(), "session/%s deleted\n", name)
return nil

default:
return fmt.Errorf("unknown or non-deletable resource type: %s\nDeletable types: project, project-settings", cmdArgs[0])
return fmt.Errorf("unknown or non-deletable resource type: %s\nDeletable types: project, project-settings, session", cmdArgs[0])
}
}
24 changes: 19 additions & 5 deletions components/ambient-cli/cmd/acpctl/describe/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"context"
"fmt"
"strings"
"time"

"github.com/ambient-code/platform/components/ambient-cli/pkg/config"
"github.com/ambient-code/platform/components/ambient-cli/pkg/connection"
"github.com/ambient-code/platform/components/ambient-cli/pkg/output"
"github.com/spf13/cobra"
Expand All @@ -18,8 +18,10 @@ var Cmd = &cobra.Command{
Long: `Show detailed information about a specific resource.

Valid resource types:
session (aliases: sess)
project (aliases: proj)`,
session (aliases: sess)
project (aliases: proj)
project-settings (aliases: ps)
user (aliases: usr)`,
Args: cobra.ExactArgs(2),
RunE: run,
}
Expand All @@ -33,7 +35,12 @@ func run(cmd *cobra.Command, cmdArgs []string) error {
return err
}

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
cfg, err := config.Load()
if err != nil {
return fmt.Errorf("load config: %w", err)
}

ctx, cancel := context.WithTimeout(context.Background(), cfg.GetRequestTimeout())
defer cancel()

printer := output.NewPrinter(output.FormatJSON)
Expand All @@ -60,7 +67,14 @@ func run(cmd *cobra.Command, cmdArgs []string) error {
}
return printer.PrintJSON(settings)

case "user", "users", "usr":
user, err := client.Users().Get(ctx, name)
if err != nil {
return fmt.Errorf("describe user %q: %w", name, err)
}
return printer.PrintJSON(user)

default:
return fmt.Errorf("unknown resource type: %s\nValid types: session, project, project-settings", cmdArgs[0])
return fmt.Errorf("unknown resource type: %s\nValid types: session, project, project-settings, user", cmdArgs[0])
}
}
Loading
Loading