Skip to content

Modern Docker Management, Designed for Everyone

feat(cli): initial arcane-cli release (#1150)

Kyle Mendell6cfc2fcefe43
diff --git a/cli/README.md b/cli/README.md
index 5dd8eaf37..5aa083969 100644
--- a/cli/README.md
+++ b/cli/README.md
@@ -1,6 +1,6 @@
<div align="center">
- <img src=".github/assets/arcane-full.png" alt="Arcane Logo" width="500" />
+ <img src="../.github/assets/IMG/PNG-3.png" alt="Arcane Logo" width="500" />
<p>The Official Command Line Client</p>
<a href="https://pkg.go.dev/go.getarcane.app/cli"><img src="https://pkg.go.dev/badge/go.getarcane.app/cli.svg" alt="Go Reference"></a>
@@ -10,3 +10,27 @@
<br />
</div>
+
+## Install
+
+This module lives inside the main Arcane repo. To build the CLI locally:
+
+- `go install go.getarcane.app/cli@latest`
+
+## Configure
+
+The CLI stores config in `~/.config/arcanecli.yml`.
+
+Set the Arcane server URL:
+
+- `arcane config set --server-url http://localhost:3552`
+
+### Authenticate (choose one)
+
+#### Option A: JWT login
+
+- `arcane auth login`
+
+#### Option B: API key
+
+- `arcane config set --api-key arc_xxxxxxxxxxxxx`
diff --git a/cli/go.mod b/cli/go.mod
index 02d24b554..df81beedc 100644
--- a/cli/go.mod
+++ b/cli/go.mod
@@ -2,9 +2,6 @@ module go.getarcane.app/cli
go 1.25.4
-// TODO: Remove this replace directive after merging the types module
-replace go.getarcane.app/types => ../types
-
require (
github.com/fatih/color v1.18.0
github.com/olekukonko/tablewriter v0.0.5
diff --git a/cli/internal/client/client.go b/cli/internal/client/client.go
index b1584cad3..06ea9b5bd 100644
--- a/cli/internal/client/client.go
+++ b/cli/internal/client/client.go
@@ -37,7 +37,7 @@ import (
)
const (
- headerAPIToken = "X-API-TOKEN" //nolint:gosec
+ headerAPIKey = "X-API-KEY" //nolint:gosec
defaultTimeout = 30 * time.Second
defaultEnvID = "0"
)
@@ -49,6 +49,7 @@ const (
type Client struct {
baseURL string
apiKey string
+ jwtToken string
envID string
httpClient *http.Client
}
@@ -67,9 +68,31 @@ func New(cfg *types.Config) (*Client, error) {
envID = defaultEnvID
}
+ return &Client{
+ baseURL: cfg.ServerURL,
+ apiKey: cfg.APIKey,
+ jwtToken: cfg.JWTToken,
+ envID: envID,
+ httpClient: &http.Client{
+ Timeout: defaultTimeout,
+ },
+ }, nil
+}
+
+// NewUnauthenticated creates a client that can call unauthenticated endpoints
+// (e.g. /api/auth/login). It only validates that server_url is configured.
+func NewUnauthenticated(cfg *types.Config) (*Client, error) {
+ if err := cfg.ValidateServerURL(); err != nil {
+ return nil, err
+ }
+
+ envID := cfg.DefaultEnvironment
+ if envID == "" {
+ envID = defaultEnvID
+ }
+
return &Client{
baseURL: cfg.ServerURL,
- apiKey: cfg.APIKey,
envID: envID,
httpClient: &http.Client{
Timeout: defaultTimeout,
@@ -88,6 +111,15 @@ func NewFromConfig() (*Client, error) {
return New(cfg)
}
+// NewFromConfigUnauthenticated loads config and returns an unauthenticated client.
+func NewFromConfigUnauthenticated() (*Client, error) {
+ cfg, err := config.Load()
+ if err != nil {
+ return nil, fmt.Errorf("failed to load config: %w", err)
+ }
+ return NewUnauthenticated(cfg)
+}
+
// SetEnvironment changes the environment ID for subsequent requests.
// This allows switching between different Arcane environments without
// creating a new client instance.
@@ -143,11 +175,23 @@ func (c *Client) Request(ctx context.Context, method, path string, body any) (*h
var bodyReader io.Reader
if body != nil {
- jsonBody, err := json.Marshal(body)
- if err != nil {
- return nil, fmt.Errorf("failed to marshal request body: %w", err)
+ switch v := body.(type) {
+ case []byte:
+ // Callers commonly pre-marshal JSON and pass the raw bytes.
+ // Treat as already-encoded JSON to avoid double-marshalling.
+ bodyReader = bytes.NewReader(v)
+ case json.RawMessage:
+ bodyReader = bytes.NewReader(v)
+ case io.Reader:
+ // Allow streaming bodies when needed.
+ bodyReader = v
+ default:
+ jsonBody, err := json.Marshal(body)
+ if err != nil {
+ return nil, fmt.Errorf("failed to marshal request body: %w", err)
+ }
+ bodyReader = bytes.NewReader(jsonBody)
}
- bodyReader = bytes.NewReader(jsonBody)
}
req, err := http.NewRequestWithContext(ctx, method, fullURL, bodyReader)
@@ -155,7 +199,7 @@ func (c *Client) Request(ctx context.Context, method, path string, body any) (*h
return nil, fmt.Errorf("failed to create request: %w", err)
}
- req.Header.Set(headerAPIToken, c.apiKey)
+ c.applyAuth(req)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
@@ -189,7 +233,7 @@ func (c *Client) RequestRaw(ctx context.Context, method, path string, body io.Re
return nil, fmt.Errorf("failed to create request: %w", err)
}
- req.Header.Set(headerAPIToken, c.apiKey)
+ c.applyAuth(req)
req.Header.Set("Accept", "application/json")
for k, v := range headers {
@@ -204,6 +248,17 @@ func (c *Client) RequestRaw(ctx context.Context, method, path string, body io.Re
return resp, nil
}
+func (c *Client) applyAuth(req *http.Request) {
+ // Prefer JWT bearer token if present.
+ if c.jwtToken != "" {
+ req.Header.Set("Authorization", "Bearer "+c.jwtToken)
+ return
+ }
+ if c.apiKey != "" {
+ req.Header.Set(headerAPIKey, c.apiKey)
+ }
+}
+
// Get makes a GET request to the specified path.
// It is a convenience wrapper around Request for retrieving resources.
func (c *Client) Get(ctx context.Context, path string) (*http.Response, error) {
diff --git a/cli/internal/client/client_test.go b/cli/internal/client/client_test.go
new file mode 100644
index 000000000..e5201e5f6
--- /dev/null
+++ b/cli/internal/client/client_test.go
@@ -0,0 +1,146 @@
+package client
+
+import (
+ "context"
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "testing"
+
+ "go.getarcane.app/cli/internal/types"
+)
+
+func TestClient_UsesAPIKeyHeader(t *testing.T) {
+ t.Parallel()
+
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if got := r.Header.Get("X-API-KEY"); got != "arc_test_key" {
+ w.WriteHeader(http.StatusUnauthorized)
+ return
+ }
+ if got := r.Header.Get("Authorization"); got != "" {
+ w.WriteHeader(http.StatusBadRequest)
+ return
+ }
+ w.WriteHeader(http.StatusOK)
+ }))
+ defer srv.Close()
+
+ cfg := &types.Config{ServerURL: srv.URL, APIKey: "arc_test_key"}
+ c, err := New(cfg)
+ if err != nil {
+ t.Fatalf("New() error: %v", err)
+ }
+
+ resp, err := c.Get(context.Background(), "/api/version")
+ if err != nil {
+
+ t.Fatalf("Get() error: %v", err)
+ }
+ _ = resp.Body.Close()
+ if resp.StatusCode != http.StatusOK {
+ t.Fatalf("unexpected status: %d", resp.StatusCode)
+ }
+}
+
+func TestClient_UsesBearerTokenHeader(t *testing.T) {
+ t.Parallel()
+
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if got := r.Header.Get("Authorization"); got != "Bearer header.payload.sig" {
+ w.WriteHeader(http.StatusUnauthorized)
+ return
+ }
+ if got := r.Header.Get("X-API-KEY"); got != "" {
+ w.WriteHeader(http.StatusBadRequest)
+ return
+ }
+ w.WriteHeader(http.StatusOK)
+ }))
+ defer srv.Close()
+
+ cfg := &types.Config{ServerURL: srv.URL, JWTToken: "header.payload.sig"}
+ c, err := New(cfg)
+ if err != nil {
+ t.Fatalf("New() error: %v", err)
+ }
+
+ resp, err := c.Get(context.Background(), "/api/version")
+ if err != nil {
+ t.Fatalf("Get() error: %v", err)
+ }
+ _ = resp.Body.Close()
+ if resp.StatusCode != http.StatusOK {
+ t.Fatalf("unexpected status: %d", resp.StatusCode)
+ }
+}
+
+func TestClient_NewUnauthenticated_DoesNotSendAuthHeaders(t *testing.T) {
+ t.Parallel()
+
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.Header.Get("Authorization") != "" || r.Header.Get("X-API-KEY") != "" {
+ w.WriteHeader(http.StatusBadRequest)
+ return
+ }
+ w.WriteHeader(http.StatusOK)
+ }))
+ defer srv.Close()
+
+ cfg := &types.Config{ServerURL: srv.URL}
+ c, err := NewUnauthenticated(cfg)
+ if err != nil {
+ t.Fatalf("NewUnauthenticated() error: %v", err)
+ }
+
+ resp, err := c.Get(context.Background(), "/api/auth/login")
+ if err != nil {
+ t.Fatalf("Get() error: %v", err)
+ }
+ _ = resp.Body.Close()
+ if resp.StatusCode != http.StatusOK {
+ t.Fatalf("unexpected status: %d", resp.StatusCode)
+ }
+}
+
+func TestClient_Request_DoesNotDoubleMarshalBytes(t *testing.T) {
+ t.Parallel()
+
+ type payload struct {
+ Username string `json:"username"`
+ Password string `json:"password"`
+ }
+
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ var p payload
+ if err := json.NewDecoder(r.Body).Decode(&p); err != nil {
+ w.WriteHeader(http.StatusBadRequest)
+ return
+ }
+ if p.Username != "arcane" || p.Password != "secret" {
+ w.WriteHeader(http.StatusUnprocessableEntity)
+ return
+ }
+ w.WriteHeader(http.StatusOK)
+ }))
+ defer srv.Close()
+
+ cfg := &types.Config{ServerURL: srv.URL, JWTToken: "header.payload.sig"}
+ c, err := New(cfg)
+ if err != nil {
+ t.Fatalf("New() error: %v", err)
+ }
+
+ raw, err := json.Marshal(payload{Username: "arcane", Password: "secret"})
+ if err != nil {
+ t.Fatalf("json.Marshal() error: %v", err)
+ }
+ resp, err := c.Post(context.Background(), "/api/auth/login", raw)
+ if err != nil {
+ t.Fatalf("Post() error: %v", err)
+ }
+ _ = resp.Body.Close()
+ if resp.StatusCode != http.StatusOK {
+ t.Fatalf("unexpected status: %d", resp.StatusCode)
+ }
+}
diff --git a/cli/internal/types/config.go b/cli/internal/types/config.go
index 4fbe5dda6..d094c1e55 100644
--- a/cli/internal/types/config.go
+++ b/cli/internal/types/config.go
@@ -7,23 +7,39 @@ import "fmt"
type Config struct {
// ServerURL is the base URL of the Arcane server (e.g., http://localhost:3552)
ServerURL string `yaml:"server_url"`
- // APIKey is the API key for authentication
- APIKey string `yaml:"api_key"`
+ // APIKey is the API key for authentication (sent as X-API-KEY)
+ APIKey string `yaml:"api_key,omitempty"`
+ // JWTToken is the JWT access token for authentication (sent as Authorization: Bearer)
+ JWTToken string `yaml:"jwt_token,omitempty"`
// DefaultEnvironment is the default environment ID to use
DefaultEnvironment string `yaml:"default_environment,omitempty"`
// LogLevel is the logging level (debug, info, warn, error, fatal, panic)
LogLevel string `yaml:"log_level,omitempty"`
}
+// HasAuth returns true if either an API key or JWT token is configured.
+func (c *Config) HasAuth() bool {
+ return c.APIKey != "" || c.JWTToken != ""
+}
+
+// ValidateServerURL checks if the configuration has the server URL set.
+// This is useful for commands like `auth login` that do not require prior authentication.
+func (c *Config) ValidateServerURL() error {
+ if c.ServerURL == "" {
+ return fmt.Errorf("server_url is not configured. Run: arcane config set --server-url <url>")
+ }
+ return nil
+}
+
// Validate checks if the configuration has all required fields set.
// It returns an error with instructions if ServerURL or APIKey is missing.
// This should be called before using the config to make API requests.
func (c *Config) Validate() error {
- if c.ServerURL == "" {
- return fmt.Errorf("server_url is not configured. Run: arcane api config set --server-url <url>")
+ if err := c.ValidateServerURL(); err != nil {
+ return err
}
- if c.APIKey == "" {
- return fmt.Errorf("api_key is not configured. Run: arcane api config set --api-key <key>")
+ if !c.HasAuth() {
+ return fmt.Errorf("authentication is not configured. Run: arcane config set --api-key <key> OR arcane auth login")
}
return nil
}
@@ -32,5 +48,5 @@ func (c *Config) Validate() error {
// This is a quick check to determine if the CLI has been configured
// without triggering validation errors.
func (c *Config) IsConfigured() bool {
- return c.ServerURL != "" && c.APIKey != ""
+ return c.ServerURL != "" && c.HasAuth()
}
diff --git a/cli/internal/types/endpoints.go b/cli/internal/types/endpoints.go
index d7bae73f6..a8a2f97ee 100644
--- a/cli/internal/types/endpoints.go
+++ b/cli/internal/types/endpoints.go
@@ -2,68 +2,614 @@ package types
import "fmt"
-// ImageEndpointAction represents the type of action to perform on the images API endpoint.
-// It is used to route requests to the appropriate API path.
-type ImageEndpointAction string
-
-// ImageEndpointAction constants define the available image API operations.
-const (
- // ImageEndpointActionList lists all images.
- ImageEndpointActionList ImageEndpointAction = "list"
- // ImageEndpointActionGet retrieves details for a specific image.
- ImageEndpointActionGet ImageEndpointAction = "get"
- // ImageEndpointActionPull pulls an image from a registry.
- ImageEndpointActionPull ImageEndpointAction = "pull"
- // ImageEndpointActionDelete removes an image.
- ImageEndpointActionDelete ImageEndpointAction = "delete"
- // ImageEndpointActionPrune removes unused images.
- ImageEndpointActionPrune ImageEndpointAction = "prune"
- // ImageEndpointActionCounts retrieves image usage statistics.
- ImageEndpointActionCounts ImageEndpointAction = "counts"
- // ImageEndpointActionUpload uploads an image from a tar archive.
- ImageEndpointActionUpload ImageEndpointAction = "upload"
-)
-
// ArcaneApiEndpoints holds the API endpoint path templates for the Arcane API.
-// Endpoint paths may contain format specifiers (e.g., %s) for environment IDs.
+// Endpoint paths may contain format specifiers (e.g., %s) for environment IDs or resource IDs.
type ArcaneApiEndpoints struct {
+ // Version & Health
+ AppVersionEndpoint string
VersionEndpoint string
- ContainersEndpoint string
- ImagesEndpoint string
+ HealthEndpoint string
+
+ // Authentication
+ AuthLoginEndpoint string
+ AuthLogoutEndpoint string
+ AuthMeEndpoint string
+ AuthPasswordEndpoint string
+ AuthRefreshEndpoint string
+
+ // OIDC
+ OIDCStatusEndpoint string
+ OIDCConfigEndpoint string
+ OIDCUrlEndpoint string
+ OIDCCallbackEndpoint string
+
+ // API Keys
+ ApiKeysEndpoint string
+ ApiKeyEndpoint string
+
+ // Users
+ UsersEndpoint string
+ UserEndpoint string
+
+ // Environments
+ EnvironmentsEndpoint string
+ EnvironmentEndpoint string
+ EnvironmentPairEndpoint string
+ EnvironmentAgentEndpoint string
+ EnvironmentTestEndpoint string
+
+ // Containers
+ ContainersEndpoint string
+ ContainerEndpoint string
+ ContainerStartEndpoint string
+ ContainerStopEndpoint string
+ ContainerRestartEndpoint string
+ ContainerUpdateEndpoint string
+ ContainersCountsEndpoint string
+
+ // Images
+ ImagesEndpoint string
+ ImageEndpoint string
+ ImagesPullEndpoint string
+ ImagesPruneEndpoint string
+ ImagesCountsEndpoint string
+ ImagesUploadEndpoint string
+
+ // Image Updates
+ ImageUpdatesCheckEndpoint string
+ ImageUpdatesCheckAllEndpoint string
+ ImageUpdatesCheckBatchEndpoint string
+ ImageUpdatesCheckByIdEndpoint string
+ ImageUpdatesSummaryEndpoint string
+
+ // Networks
+ NetworksEndpoint string
+ NetworkEndpoint string
+ NetworksCountsEndpoint string
+ NetworksPruneEndpoint string
+
+ // Volumes
+ VolumesEndpoint string
+ VolumeEndpoint string
+ VolumesCountsEndpoint string
+ VolumesPruneEndpoint string
+ VolumesSizesEndpoint string
+ VolumeUsageEndpoint string
+
+ // Projects (Stacks)
+ ProjectsEndpoint string
+ ProjectEndpoint string
+ ProjectsCountsEndpoint string
+ ProjectDestroyEndpoint string
+ ProjectUpEndpoint string
+ ProjectDownEndpoint string
+ ProjectRestartEndpoint string
+ ProjectRedeployEndpoint string
+ ProjectPullEndpoint string
+ ProjectIncludesEndpoint string
+
+ // System
+ SystemPruneEndpoint string
+ SystemHealthEndpoint string
+ SystemDockerInfoEndpoint string
+ SystemConvertEndpoint string
+ SystemContainersStartAllEndpoint string
+ SystemContainersStopAllEndpoint string
+ SystemContainersStartStoppedEndpoint string
+ SystemUpgradeCheckEndpoint string
+ SystemUpgradeEndpoint string
+
+ // Updater
+ UpdaterStatusEndpoint string
+ UpdaterRunEndpoint string
+ UpdaterHistoryEndpoint string
+
+ // Settings
+ SettingsEndpoint string
+ SettingsPublicEndpoint string
+ SettingsCategoriesEndpoint string
+ SettingsSearchEndpoint string
+
+ // Notifications
+ NotificationsAppriseEndpoint string
+ NotificationsAppriseTestEndpoint string
+ NotificationsSettingsEndpoint string
+ NotificationSettingEndpoint string
+ NotificationTestEndpoint string
+
+ // Container Registries
+ ContainerRegistriesEndpoint string
+ ContainerRegistryEndpoint string
+ ContainerRegistrySyncEndpoint string
+ ContainerRegistryTestEndpoint string
+ EnvironmentSyncRegistriesEndpoint string
+
+ // Events
+ EventsEndpoint string
+ EventEndpoint string
+ EventsEnvironmentEndpoint string
+
+ // Templates
+ TemplatesEndpoint string
+ TemplateEndpoint string
+ TemplatesAllEndpoint string
+ TemplatesDefaultEndpoint string
+ TemplatesFetchEndpoint string
+ TemplatesRegistriesEndpoint string
+ TemplateRegistryEndpoint string
+ TemplatesVariablesEndpoint string
+ TemplateContentEndpoint string
+ TemplateDownloadEndpoint string
+
+ // Deployment
+ DeploymentEndpoint string
+ HeartbeatEndpoint string
+
+ // Assets
+ AppImagesFaviconEndpoint string
+ AppImagesLogoEndpoint string
+ AppImagesProfileEndpoint string
+ FontsMonoEndpoint string
+ FontsSansEndpoint string
+ FontsSerifEndpoint string
+
+ // Customization
+ CustomizeCategoriesEndpoint string
+ CustomizeSearchEndpoint string
}
// Endpoints contains the defined API endpoints
var Endpoints = ArcaneApiEndpoints{
- VersionEndpoint: "/api/app-version",
- ContainersEndpoint: "/api/environments/%s/containers",
- ImagesEndpoint: "/api/environments/%s/images",
+ // Version & Health
+ AppVersionEndpoint: "/api/app-version",
+ VersionEndpoint: "/api/version",
+ HealthEndpoint: "/api/health",
+
+ // Authentication
+ AuthLoginEndpoint: "/api/auth/login",
+ AuthLogoutEndpoint: "/api/auth/logout",
+ AuthMeEndpoint: "/api/auth/me",
+ AuthPasswordEndpoint: "/api/auth/password",
+ AuthRefreshEndpoint: "/api/auth/refresh",
+
+ // OIDC
+ OIDCStatusEndpoint: "/api/oidc/status",
+ OIDCConfigEndpoint: "/api/oidc/config",
+ OIDCUrlEndpoint: "/api/oidc/url",
+ OIDCCallbackEndpoint: "/api/oidc/callback",
+
+ // API Keys
+ ApiKeysEndpoint: "/api/api-keys",
+ ApiKeyEndpoint: "/api/api-keys/%s",
+
+ // Users
+ UsersEndpoint: "/api/users",
+ UserEndpoint: "/api/users/%s",
+
+ // Environments
+ EnvironmentsEndpoint: "/api/environments",
+ EnvironmentEndpoint: "/api/environments/%s",
+ EnvironmentPairEndpoint: "/api/environments/pair",
+ EnvironmentAgentEndpoint: "/api/environments/%s/agent/pair",
+ EnvironmentTestEndpoint: "/api/environments/%s/test",
+
+ // Containers
+ ContainersEndpoint: "/api/environments/%s/containers",
+ ContainerEndpoint: "/api/environments/%s/containers/%s",
+ ContainerStartEndpoint: "/api/environments/%s/containers/%s/start",
+ ContainerStopEndpoint: "/api/environments/%s/containers/%s/stop",
+ ContainerRestartEndpoint: "/api/environments/%s/containers/%s/restart",
+ ContainerUpdateEndpoint: "/api/environments/%s/containers/%s/update",
+ ContainersCountsEndpoint: "/api/environments/%s/containers/counts",
+
+ // Images
+ ImagesEndpoint: "/api/environments/%s/images",
+ ImageEndpoint: "/api/environments/%s/images/%s",
+ ImagesPullEndpoint: "/api/environments/%s/images/pull",
+ ImagesPruneEndpoint: "/api/environments/%s/images/prune",
+ ImagesCountsEndpoint: "/api/environments/%s/images/counts",
+ ImagesUploadEndpoint: "/api/environments/%s/images/upload",
+
+ // Image Updates
+ ImageUpdatesCheckEndpoint: "/api/environments/%s/image-updates/check",
+ ImageUpdatesCheckAllEndpoint: "/api/environments/%s/image-updates/check-all",
+ ImageUpdatesCheckBatchEndpoint: "/api/environments/%s/image-updates/check-batch",
+ ImageUpdatesCheckByIdEndpoint: "/api/environments/%s/image-updates/check/%s",
+ ImageUpdatesSummaryEndpoint: "/api/environments/%s/image-updates/summary",
+
+ // Networks
+ NetworksEndpoint: "/api/environments/%s/networks",
+ NetworkEndpoint: "/api/environments/%s/networks/%s",
+ NetworksCountsEndpoint: "/api/environments/%s/networks/counts",
+ NetworksPruneEndpoint: "/api/environments/%s/networks/prune",
+
+ // Volumes
+ VolumesEndpoint: "/api/environments/%s/volumes",
+ VolumeEndpoint: "/api/environments/%s/volumes/%s",
+ VolumesCountsEndpoint: "/api/environments/%s/volumes/counts",
+ VolumesPruneEndpoint: "/api/environments/%s/volumes/prune",
+ VolumesSizesEndpoint: "/api/environments/%s/volumes/sizes",
+ VolumeUsageEndpoint: "/api/environments/%s/volumes/%s/usage",
+
+ // Projects (Stacks)
+ ProjectsEndpoint: "/api/environments/%s/projects",
+ ProjectEndpoint: "/api/environments/%s/projects/%s",
+ ProjectsCountsEndpoint: "/api/environments/%s/projects/counts",
+ ProjectDestroyEndpoint: "/api/environments/%s/projects/%s/destroy",
+ ProjectUpEndpoint: "/api/environments/%s/projects/%s/up",
+ ProjectDownEndpoint: "/api/environments/%s/projects/%s/down",
+ ProjectRestartEndpoint: "/api/environments/%s/projects/%s/restart",
+ ProjectRedeployEndpoint: "/api/environments/%s/projects/%s/redeploy",
+ ProjectPullEndpoint: "/api/environments/%s/projects/%s/pull",
+ ProjectIncludesEndpoint: "/api/environments/%s/projects/%s/includes",
+
+ // System
+ SystemPruneEndpoint: "/api/environments/%s/system/prune",
+ SystemHealthEndpoint: "/api/environments/%s/system/health",
+ SystemDockerInfoEndpoint: "/api/environments/%s/system/docker/info",
+ SystemConvertEndpoint: "/api/environments/%s/system/convert",
+ SystemContainersStartAllEndpoint: "/api/environments/%s/system/containers/start-all",
+ SystemContainersStopAllEndpoint: "/api/environments/%s/system/containers/stop-all",
+ SystemContainersStartStoppedEndpoint: "/api/environments/%s/system/containers/start-stopped",
+ SystemUpgradeCheckEndpoint: "/api/environments/%s/system/upgrade/check",
+ SystemUpgradeEndpoint: "/api/environments/%s/system/upgrade",
+
+ // Updater
+ UpdaterStatusEndpoint: "/api/environments/%s/updater/status",
+ UpdaterRunEndpoint: "/api/environments/%s/updater/run",
+ UpdaterHistoryEndpoint: "/api/environments/%s/updater/history",
+
+ // Settings
+ SettingsEndpoint: "/api/environments/%s/settings",
+ SettingsPublicEndpoint: "/api/environments/%s/settings/public",
+ SettingsCategoriesEndpoint: "/api/settings/categories",
+ SettingsSearchEndpoint: "/api/settings/search",
+
+ // Notifications
+ NotificationsAppriseEndpoint: "/api/environments/%s/notifications/apprise",
+ NotificationsAppriseTestEndpoint: "/api/environments/%s/notifications/apprise/test",
+ NotificationsSettingsEndpoint: "/api/environments/%s/notifications/settings",
+ NotificationSettingEndpoint: "/api/environments/%s/notifications/settings/%s",
+ NotificationTestEndpoint: "/api/environments/%s/notifications/test/%s",
+
+ // Container Registries
+ ContainerRegistriesEndpoint: "/api/container-registries",
+ ContainerRegistryEndpoint: "/api/container-registries/%s",
+ ContainerRegistrySyncEndpoint: "/api/container-registries/sync",
+ ContainerRegistryTestEndpoint: "/api/container-registries/%s/test",
+ EnvironmentSyncRegistriesEndpoint: "/api/environments/%s/sync-registries",
+
+ // Events
+ EventsEndpoint: "/api/events",
+ EventEndpoint: "/api/events/%s",
+ EventsEnvironmentEndpoint: "/api/events/environment/%s",
+
+ // Templates
+ TemplatesEndpoint: "/api/templates",
+ TemplateEndpoint: "/api/templates/%s",
+ TemplatesAllEndpoint: "/api/templates/all",
+ TemplatesDefaultEndpoint: "/api/templates/default",
+ TemplatesFetchEndpoint: "/api/templates/fetch",
+ TemplatesRegistriesEndpoint: "/api/templates/registries",
+ TemplateRegistryEndpoint: "/api/templates/registries/%s",
+ TemplatesVariablesEndpoint: "/api/templates/variables",
+ TemplateContentEndpoint: "/api/templates/%s/content",
+ TemplateDownloadEndpoint: "/api/templates/%s/download",
+
+ // Deployment & Heartbeat
+ DeploymentEndpoint: "/api/environments/%s/deployment",
+ HeartbeatEndpoint: "/api/environments/%s/heartbeat",
+
+ // Assets
+ AppImagesFaviconEndpoint: "/api/app-images/favicon",
+ AppImagesLogoEndpoint: "/api/app-images/logo",
+ AppImagesProfileEndpoint: "/api/app-images/profile",
+ FontsMonoEndpoint: "/api/fonts/mono",
+ FontsSansEndpoint: "/api/fonts/sans",
+ FontsSerifEndpoint: "/api/fonts/serif",
+
+ // Customization
+ CustomizeCategoriesEndpoint: "/api/customize/categories",
+ CustomizeSearchEndpoint: "/api/customize/search",
}
-// FormatContainers returns the containers endpoint path for the given environment ID.
-// The returned path is suitable for listing and managing containers.
-func (e ArcaneApiEndpoints) FormatContainers(envID string) string {
+// Auth endpoints
+func (e ArcaneApiEndpoints) AuthLogin() string { return e.AuthLoginEndpoint }
+func (e ArcaneApiEndpoints) AuthLogout() string { return e.AuthLogoutEndpoint }
+func (e ArcaneApiEndpoints) AuthMe() string { return e.AuthMeEndpoint }
+func (e ArcaneApiEndpoints) AuthPassword() string { return e.AuthPasswordEndpoint }
+func (e ArcaneApiEndpoints) AuthRefresh() string { return e.AuthRefreshEndpoint }
+
+// OIDC endpoints
+func (e ArcaneApiEndpoints) OIDCStatus() string { return e.OIDCStatusEndpoint }
+func (e ArcaneApiEndpoints) OIDCConfig() string { return e.OIDCConfigEndpoint }
+func (e ArcaneApiEndpoints) OIDCUrl() string { return e.OIDCUrlEndpoint }
+func (e ArcaneApiEndpoints) OIDCCallback() string { return e.OIDCCallbackEndpoint }
+
+// API Key endpoints
+func (e ArcaneApiEndpoints) ApiKeys() string { return e.ApiKeysEndpoint }
+func (e ArcaneApiEndpoints) ApiKey(id string) string { return fmt.Sprintf(e.ApiKeyEndpoint, id) }
+
+// User endpoints
+func (e ArcaneApiEndpoints) Users() string { return e.UsersEndpoint }
+func (e ArcaneApiEndpoints) User(id string) string { return fmt.Sprintf(e.UserEndpoint, id) }
+
+// Environment endpoints
+func (e ArcaneApiEndpoints) Environments() string { return e.EnvironmentsEndpoint }
+func (e ArcaneApiEndpoints) Environment(id string) string {
+ return fmt.Sprintf(e.EnvironmentEndpoint, id)
+}
+func (e ArcaneApiEndpoints) EnvironmentPair() string { return e.EnvironmentPairEndpoint }
+func (e ArcaneApiEndpoints) EnvironmentAgent(envID string) string {
+ return fmt.Sprintf(e.EnvironmentAgentEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) EnvironmentTest(envID string) string {
+ return fmt.Sprintf(e.EnvironmentTestEndpoint, envID)
+}
+
+// Container endpoints
+func (e ArcaneApiEndpoints) Containers(envID string) string {
return fmt.Sprintf(e.ContainersEndpoint, envID)
}
+func (e ArcaneApiEndpoints) Container(envID, containerID string) string {
+ return fmt.Sprintf(e.ContainerEndpoint, envID, containerID)
+}
+func (e ArcaneApiEndpoints) ContainerStart(envID, containerID string) string {
+ return fmt.Sprintf(e.ContainerStartEndpoint, envID, containerID)
+}
+func (e ArcaneApiEndpoints) ContainerStop(envID, containerID string) string {
+ return fmt.Sprintf(e.ContainerStopEndpoint, envID, containerID)
+}
+func (e ArcaneApiEndpoints) ContainerRestart(envID, containerID string) string {
+ return fmt.Sprintf(e.ContainerRestartEndpoint, envID, containerID)
+}
+func (e ArcaneApiEndpoints) ContainerUpdate(envID, containerID string) string {
+ return fmt.Sprintf(e.ContainerUpdateEndpoint, envID, containerID)
+}
+func (e ArcaneApiEndpoints) ContainersCounts(envID string) string {
+ return fmt.Sprintf(e.ContainersCountsEndpoint, envID)
+}
+
+// Image endpoints
+func (e ArcaneApiEndpoints) Images(envID string) string { return fmt.Sprintf(e.ImagesEndpoint, envID) }
+func (e ArcaneApiEndpoints) Image(envID, imageID string) string {
+ return fmt.Sprintf(e.ImageEndpoint, envID, imageID)
+}
+func (e ArcaneApiEndpoints) ImagesPull(envID string) string {
+ return fmt.Sprintf(e.ImagesPullEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) ImagesPrune(envID string) string {
+ return fmt.Sprintf(e.ImagesPruneEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) ImagesCounts(envID string) string {
+ return fmt.Sprintf(e.ImagesCountsEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) ImagesUpload(envID string) string {
+ return fmt.Sprintf(e.ImagesUploadEndpoint, envID)
+}
+
+// Image Update endpoints
+func (e ArcaneApiEndpoints) ImageUpdatesCheck(envID string) string {
+ return fmt.Sprintf(e.ImageUpdatesCheckEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) ImageUpdatesCheckAll(envID string) string {
+ return fmt.Sprintf(e.ImageUpdatesCheckAllEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) ImageUpdatesCheckBatch(envID string) string {
+ return fmt.Sprintf(e.ImageUpdatesCheckBatchEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) ImageUpdatesCheckById(envID, imageID string) string {
+ return fmt.Sprintf(e.ImageUpdatesCheckByIdEndpoint, envID, imageID)
+}
+func (e ArcaneApiEndpoints) ImageUpdatesSummary(envID string) string {
+ return fmt.Sprintf(e.ImageUpdatesSummaryEndpoint, envID)
+}
+
+// Network endpoints
+func (e ArcaneApiEndpoints) Networks(envID string) string {
+ return fmt.Sprintf(e.NetworksEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) Network(envID, networkID string) string {
+ return fmt.Sprintf(e.NetworkEndpoint, envID, networkID)
+}
+func (e ArcaneApiEndpoints) NetworksCounts(envID string) string {
+ return fmt.Sprintf(e.NetworksCountsEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) NetworksPrune(envID string) string {
+ return fmt.Sprintf(e.NetworksPruneEndpoint, envID)
+}
+
+// Volume endpoints
+func (e ArcaneApiEndpoints) Volumes(envID string) string {
+ return fmt.Sprintf(e.VolumesEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) Volume(envID, volumeName string) string {
+ return fmt.Sprintf(e.VolumeEndpoint, envID, volumeName)
+}
+func (e ArcaneApiEndpoints) VolumesCounts(envID string) string {
+ return fmt.Sprintf(e.VolumesCountsEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) VolumesPrune(envID string) string {
+ return fmt.Sprintf(e.VolumesPruneEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) VolumesSizes(envID string) string {
+ return fmt.Sprintf(e.VolumesSizesEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) VolumeUsage(envID, volumeName string) string {
+ return fmt.Sprintf(e.VolumeUsageEndpoint, envID, volumeName)
+}
+
+// Project endpoints
+func (e ArcaneApiEndpoints) Projects(envID string) string {
+ return fmt.Sprintf(e.ProjectsEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) Project(envID, projectID string) string {
+ return fmt.Sprintf(e.ProjectEndpoint, envID, projectID)
+}
+func (e ArcaneApiEndpoints) ProjectsCounts(envID string) string {
+ return fmt.Sprintf(e.ProjectsCountsEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) ProjectDestroy(envID, projectID string) string {
+ return fmt.Sprintf(e.ProjectDestroyEndpoint, envID, projectID)
+}
+func (e ArcaneApiEndpoints) ProjectUp(envID, projectID string) string {
+ return fmt.Sprintf(e.ProjectUpEndpoint, envID, projectID)
+}
+func (e ArcaneApiEndpoints) ProjectDown(envID, projectID string) string {
+ return fmt.Sprintf(e.ProjectDownEndpoint, envID, projectID)
+}
+func (e ArcaneApiEndpoints) ProjectRestart(envID, projectID string) string {
+ return fmt.Sprintf(e.ProjectRestartEndpoint, envID, projectID)
+}
+func (e ArcaneApiEndpoints) ProjectRedeploy(envID, projectID string) string {
+ return fmt.Sprintf(e.ProjectRedeployEndpoint, envID, projectID)
+}
+func (e ArcaneApiEndpoints) ProjectPull(envID, projectID string) string {
+ return fmt.Sprintf(e.ProjectPullEndpoint, envID, projectID)
+}
+func (e ArcaneApiEndpoints) ProjectIncludes(envID, projectID string) string {
+ return fmt.Sprintf(e.ProjectIncludesEndpoint, envID, projectID)
+}
+
+// System endpoints
+func (e ArcaneApiEndpoints) SystemPrune(envID string) string {
+ return fmt.Sprintf(e.SystemPruneEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) SystemHealth(envID string) string {
+ return fmt.Sprintf(e.SystemHealthEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) SystemDockerInfo(envID string) string {
+ return fmt.Sprintf(e.SystemDockerInfoEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) SystemConvert(envID string) string {
+ return fmt.Sprintf(e.SystemConvertEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) SystemContainersStartAll(envID string) string {
+ return fmt.Sprintf(e.SystemContainersStartAllEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) SystemContainersStopAll(envID string) string {
+ return fmt.Sprintf(e.SystemContainersStopAllEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) SystemContainersStartStopped(envID string) string {
+ return fmt.Sprintf(e.SystemContainersStartStoppedEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) SystemUpgradeCheck(envID string) string {
+ return fmt.Sprintf(e.SystemUpgradeCheckEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) SystemUpgrade(envID string) string {
+ return fmt.Sprintf(e.SystemUpgradeEndpoint, envID)
+}
+
+// Updater endpoints
+func (e ArcaneApiEndpoints) UpdaterStatus(envID string) string {
+ return fmt.Sprintf(e.UpdaterStatusEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) UpdaterRun(envID string) string {
+ return fmt.Sprintf(e.UpdaterRunEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) UpdaterHistory(envID string) string {
+ return fmt.Sprintf(e.UpdaterHistoryEndpoint, envID)
+}
+
+// Settings endpoints
+func (e ArcaneApiEndpoints) Settings(envID string) string {
+ return fmt.Sprintf(e.SettingsEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) SettingsPublic(envID string) string {
+ return fmt.Sprintf(e.SettingsPublicEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) SettingsCategories() string { return e.SettingsCategoriesEndpoint }
+func (e ArcaneApiEndpoints) SettingsSearch() string { return e.SettingsSearchEndpoint }
+
+// Notification endpoints
+func (e ArcaneApiEndpoints) NotificationsApprise(envID string) string {
+ return fmt.Sprintf(e.NotificationsAppriseEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) NotificationsAppriseTest(envID string) string {
+ return fmt.Sprintf(e.NotificationsAppriseTestEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) NotificationsSettings(envID string) string {
+ return fmt.Sprintf(e.NotificationsSettingsEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) NotificationSetting(envID, provider string) string {
+ return fmt.Sprintf(e.NotificationSettingEndpoint, envID, provider)
+}
+func (e ArcaneApiEndpoints) NotificationTest(envID, provider string) string {
+ return fmt.Sprintf(e.NotificationTestEndpoint, envID, provider)
+}
+
+// Container Registry endpoints
+func (e ArcaneApiEndpoints) ContainerRegistries() string { return e.ContainerRegistriesEndpoint }
+func (e ArcaneApiEndpoints) ContainerRegistry(id string) string {
+ return fmt.Sprintf(e.ContainerRegistryEndpoint, id)
+}
+func (e ArcaneApiEndpoints) ContainerRegistrySync() string { return e.ContainerRegistrySyncEndpoint }
+func (e ArcaneApiEndpoints) ContainerRegistryTest(id string) string {
+ return fmt.Sprintf(e.ContainerRegistryTestEndpoint, id)
+}
+func (e ArcaneApiEndpoints) EnvironmentSyncRegistries(envID string) string {
+ return fmt.Sprintf(e.EnvironmentSyncRegistriesEndpoint, envID)
+}
+
+// Event endpoints
+func (e ArcaneApiEndpoints) Events() string { return e.EventsEndpoint }
+func (e ArcaneApiEndpoints) Event(id string) string { return fmt.Sprintf(e.EventEndpoint, id) }
+func (e ArcaneApiEndpoints) EventsEnvironment(envID string) string {
+ return fmt.Sprintf(e.EventsEnvironmentEndpoint, envID)
+}
+
+// Template endpoints
+func (e ArcaneApiEndpoints) Templates() string { return e.TemplatesEndpoint }
+func (e ArcaneApiEndpoints) Template(id string) string { return fmt.Sprintf(e.TemplateEndpoint, id) }
+func (e ArcaneApiEndpoints) TemplatesAll() string { return e.TemplatesAllEndpoint }
+func (e ArcaneApiEndpoints) TemplatesDefault() string { return e.TemplatesDefaultEndpoint }
+func (e ArcaneApiEndpoints) TemplatesFetch() string { return e.TemplatesFetchEndpoint }
+func (e ArcaneApiEndpoints) TemplatesRegistries() string { return e.TemplatesRegistriesEndpoint }
+func (e ArcaneApiEndpoints) TemplateRegistry(id string) string {
+ return fmt.Sprintf(e.TemplateRegistryEndpoint, id)
+}
+func (e ArcaneApiEndpoints) TemplatesVariables() string { return e.TemplatesVariablesEndpoint }
+func (e ArcaneApiEndpoints) TemplateContent(id string) string {
+ return fmt.Sprintf(e.TemplateContentEndpoint, id)
+}
+func (e ArcaneApiEndpoints) TemplateDownload(id string) string {
+ return fmt.Sprintf(e.TemplateDownloadEndpoint, id)
+}
+
+// Deployment & Heartbeat endpoints
+func (e ArcaneApiEndpoints) Deployment(envID string) string {
+ return fmt.Sprintf(e.DeploymentEndpoint, envID)
+}
+func (e ArcaneApiEndpoints) Heartbeat(envID string) string {
+ return fmt.Sprintf(e.HeartbeatEndpoint, envID)
+}
+
+// Version & Health endpoints
+func (e ArcaneApiEndpoints) AppVersion() string { return e.AppVersionEndpoint }
+func (e ArcaneApiEndpoints) Version() string { return e.VersionEndpoint }
+func (e ArcaneApiEndpoints) Health() string { return e.HealthEndpoint }
+
+// Legacy methods for backwards compatibility
+func (e ArcaneApiEndpoints) FormatContainers(envID string) string {
+ return e.Containers(envID)
+}
-// UseImageEndpoint returns the appropriate API endpoint path for the given
-// image action and environment ID. It handles routing to different image
-// API endpoints based on the requested action.
-func (e ArcaneApiEndpoints) UseImageEndpoint(action ImageEndpointAction, envID string) string {
+func (e ArcaneApiEndpoints) UseImageEndpoint(action string, envID string) string {
switch action {
- case ImageEndpointActionList:
- return fmt.Sprintf(e.ImagesEndpoint, envID)
- case ImageEndpointActionGet:
- return fmt.Sprintf(e.ImagesEndpoint, envID)
- case ImageEndpointActionPull:
- return fmt.Sprintf(e.ImagesEndpoint+"/pull", envID)
- case ImageEndpointActionDelete:
- return fmt.Sprintf(e.ImagesEndpoint, envID)
- case ImageEndpointActionPrune:
- return fmt.Sprintf(e.ImagesEndpoint+"/prune", envID)
- case ImageEndpointActionCounts:
- return fmt.Sprintf(e.ImagesEndpoint+"/counts", envID)
- case ImageEndpointActionUpload:
- return fmt.Sprintf(e.ImagesEndpoint+"/upload", envID)
+ case "list":
+ return e.Images(envID)
+ case "get":
+ return e.Images(envID)
+ case "pull":
+ return e.ImagesPull(envID)
+ case "delete":
+ return e.Images(envID)
+ case "prune":
+ return e.ImagesPrune(envID)
+ case "counts":
+ return e.ImagesCounts(envID)
+ case "upload":
+ return e.ImagesUpload(envID)
default:
return ""
}
diff --git a/cli/pkg/apikeys/cmd.go b/cli/pkg/apikeys/cmd.go
new file mode 100644
index 000000000..f6f1d34e6
--- /dev/null
+++ b/cli/pkg/apikeys/cmd.go
@@ -0,0 +1,273 @@
+package apikeys
+
+import (
+ "encoding/json"
+ "fmt"
+ "strings"
+
+ "github.com/spf13/cobra"
+ "go.getarcane.app/cli/internal/client"
+ "go.getarcane.app/cli/internal/output"
+ "go.getarcane.app/cli/internal/types"
+ "go.getarcane.app/types/apikey"
+ "go.getarcane.app/types/base"
+)
+
+var (
+ limitFlag int
+ forceFlag bool
+ jsonOutput bool
+)
+
+// ApiKeysCmd is the parent command for API key operations
+var ApiKeysCmd = &cobra.Command{
+ Use: "api-keys",
+ Aliases: []string{"apikey", "keys", "key"},
+ Short: "Manage API keys",
+}
+
+var listCmd = &cobra.Command{
+ Use: "list",
+ Aliases: []string{"ls"},
+ Short: "List API keys",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ path := types.Endpoints.ApiKeys()
+ if limitFlag > 0 {
+ path = fmt.Sprintf("%s?limit=%d", path, limitFlag)
+ }
+
+ resp, err := c.Get(cmd.Context(), path)
+ if err != nil {
+ return fmt.Errorf("failed to list API keys: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.Paginated[apikey.ApiKey]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ headers := []string{"ID", "NAME", "DESCRIPTION", "CREATED", "LAST USED"}
+ rows := make([][]string, len(result.Data))
+ for i, key := range result.Data {
+ description := ""
+ if key.Description != nil {
+ description = *key.Description
+ }
+ lastUsed := "Never"
+ if key.LastUsedAt != nil {
+ lastUsed = key.LastUsedAt.Format("2006-01-02 15:04")
+ }
+ rows[i] = []string{
+ key.ID,
+ key.Name,
+ description,
+ key.CreatedAt.Format("2006-01-02 15:04"),
+ lastUsed,
+ }
+ }
+
+ output.Table(headers, rows)
+ fmt.Printf("\nTotal: %d API keys\n", result.Pagination.TotalItems)
+ return nil
+ },
+}
+
+var createCmd = &cobra.Command{
+ Use: "create <name>",
+ Short: "Create a new API key",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ description, _ := cmd.Flags().GetString("description")
+
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ createReq := apikey.CreateApiKey{
+ Name: args[0],
+ }
+ if description != "" {
+ createReq.Description = &description
+ }
+ // TODO: Parse expiresAt string to time.Time if needed
+ // if expiresAt != "" {
+ // parsedTime, err := time.Parse(time.RFC3339, expiresAt)
+ // if err == nil {
+ // createReq.ExpiresAt = &parsedTime
+ // }
+ // }
+
+ reqBody, err := json.Marshal(createReq)
+ if err != nil {
+ return fmt.Errorf("failed to marshal request: %w", err)
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.ApiKeys(), reqBody)
+ if err != nil {
+ return fmt.Errorf("failed to create API key: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[apikey.ApiKeyCreatedDto]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Success("API key created successfully")
+ output.Header("API Key Details")
+ output.KeyValue("ID", result.Data.ID)
+ output.KeyValue("Name", result.Data.Name)
+ output.KeyValue("Key", result.Data.Key)
+ output.KeyValue("Created", result.Data.CreatedAt.Format("2006-01-02 15:04"))
+ output.Warning("Store the token securely - it will not be shown again!")
+ return nil
+ },
+}
+
+var deleteCmd = &cobra.Command{
+ Use: "delete <id>",
+ Aliases: []string{"rm", "remove"},
+ Short: "Delete API key",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if !forceFlag {
+ fmt.Printf("Are you sure you want to delete API key %s? (y/N): ", args[0])
+ var response string
+ if _, err := fmt.Scanln(&response); err != nil {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ if strings.ToLower(response) != "y" && strings.ToLower(response) != "yes" {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ }
+
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Delete(cmd.Context(), types.Endpoints.ApiKey(args[0]))
+ if err != nil {
+ return fmt.Errorf("failed to delete API key: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ if jsonOutput {
+ var result base.ApiResponse[interface{}]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Success("API key deleted successfully")
+ return nil
+ },
+}
+
+var getCmd = &cobra.Command{
+ Use: "get <id>",
+ Short: "Get API key details",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.ApiKey(args[0]))
+ if err != nil {
+ return fmt.Errorf("failed to get API key: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[apikey.ApiKey]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("API Key Details")
+ output.KeyValue("ID", result.Data.ID)
+ output.KeyValue("Name", result.Data.Name)
+ if result.Data.Description != nil {
+ output.KeyValue("Description", *result.Data.Description)
+ }
+ output.KeyValue("Key Prefix", result.Data.KeyPrefix)
+ output.KeyValue("Created", result.Data.CreatedAt.Format("2006-01-02 15:04"))
+ if result.Data.LastUsedAt != nil {
+ output.KeyValue("Last Used", result.Data.LastUsedAt.Format("2006-01-02 15:04"))
+ }
+ if result.Data.ExpiresAt != nil {
+ output.KeyValue("Expires", result.Data.ExpiresAt.Format("2006-01-02 15:04"))
+ }
+ return nil
+ },
+}
+
+func init() {
+ ApiKeysCmd.AddCommand(listCmd)
+ ApiKeysCmd.AddCommand(createCmd)
+ ApiKeysCmd.AddCommand(getCmd)
+ ApiKeysCmd.AddCommand(deleteCmd)
+
+ // List command flags
+ listCmd.Flags().IntVarP(&limitFlag, "limit", "n", 20, "Number of API keys to show")
+ listCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Create command flags
+ createCmd.Flags().StringP("description", "d", "", "Description for the API key")
+ createCmd.Flags().String("expires-at", "", "Expiration date (ISO 8601 format)")
+ createCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Get command flags
+ getCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Delete command flags
+ deleteCmd.Flags().BoolVarP(&forceFlag, "force", "f", false, "Force deletion without confirmation")
+ deleteCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+}
diff --git a/cli/pkg/auth/cmd.go b/cli/pkg/auth/cmd.go
new file mode 100644
index 000000000..efd72b3e8
--- /dev/null
+++ b/cli/pkg/auth/cmd.go
@@ -0,0 +1,357 @@
+package auth
+
+import (
+ "encoding/json"
+ "fmt"
+ "io"
+ "strings"
+ "syscall"
+
+ "github.com/spf13/cobra"
+ "go.getarcane.app/cli/internal/client"
+ "go.getarcane.app/cli/internal/config"
+ "go.getarcane.app/cli/internal/output"
+ "go.getarcane.app/cli/internal/types"
+ "go.getarcane.app/types/auth"
+ "go.getarcane.app/types/base"
+ "golang.org/x/term"
+)
+
+var jsonOutput bool
+
+// AuthCmd is the parent command for authentication operations
+var AuthCmd = &cobra.Command{
+ Use: "auth",
+ Aliases: []string{"authentication"},
+ Short: "Authentication operations",
+}
+
+var loginCmd = &cobra.Command{
+ Use: "login",
+ Short: "Login to Arcane",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ username, _ := cmd.Flags().GetString("username")
+ password, _ := cmd.Flags().GetString("password")
+
+ if username == "" {
+ fmt.Print("Username: ")
+ if _, err := fmt.Scanln(&username); err != nil {
+ return fmt.Errorf("failed to read username: %w", err)
+ }
+ }
+
+ if password == "" {
+ fmt.Print("Password: ")
+ bytePassword, err := term.ReadPassword(int(syscall.Stdin))
+ if err != nil {
+ return fmt.Errorf("failed to read password: %w", err)
+ }
+ password = string(bytePassword)
+ fmt.Println() // Add newline after hidden password input
+ }
+
+ c, err := client.NewFromConfig()
+ if err != nil {
+ // Login should work even when no auth has been configured yet.
+ c, err = client.NewFromConfigUnauthenticated()
+ if err != nil {
+ return err
+ }
+ }
+
+ loginReq := auth.Login{
+ Username: username,
+ Password: password,
+ }
+
+ reqBody, err := json.Marshal(loginReq)
+ if err != nil {
+ return fmt.Errorf("failed to marshal request: %w", err)
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.AuthLogin(), reqBody)
+ if err != nil {
+ return fmt.Errorf("login failed: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ bodyBytes, err := io.ReadAll(resp.Body)
+ if err != nil {
+ return fmt.Errorf("failed to read response: %w", err)
+ }
+
+ if resp.StatusCode < 200 || resp.StatusCode >= 300 {
+ return fmt.Errorf("login failed (status %d): %s", resp.StatusCode, strings.TrimSpace(string(bodyBytes)))
+ }
+
+ var result base.ApiResponse[auth.LoginResponse]
+ if err := json.Unmarshal(bodyBytes, &result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+ if !result.Success || result.Data.Token == "" {
+ return fmt.Errorf("login failed: unexpected response from server")
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ // Save JWT token to config
+ cfg, err := config.Load()
+ if err != nil {
+ return fmt.Errorf("failed to load config: %w", err)
+ }
+ cfg.JWTToken = result.Data.Token
+ if err := config.Save(cfg); err != nil {
+ return fmt.Errorf("failed to save token: %w", err)
+ }
+
+ output.Success("Login successful")
+ path, _ := config.ConfigPath()
+ output.KeyValue("JWT token saved to config", path)
+ return nil
+ },
+}
+
+var logoutCmd = &cobra.Command{
+ Use: "logout",
+ Short: "Logout from Arcane",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.AuthLogout(), nil)
+ if err != nil {
+ return fmt.Errorf("logout failed: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ // Clear token from config regardless of API response
+ cfg, err := config.Load()
+ if err != nil {
+ return fmt.Errorf("failed to load config: %w", err)
+ }
+ cfg.JWTToken = ""
+ if err := config.Save(cfg); err != nil {
+ return fmt.Errorf("failed to clear token: %w", err)
+ }
+
+ if jsonOutput {
+ var result base.ApiResponse[interface{}]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err == nil {
+ if resultBytes, err := json.MarshalIndent(result.Data, "", " "); err == nil {
+ fmt.Println(string(resultBytes))
+ }
+ }
+ return nil
+ }
+
+ output.Success("Logout successful")
+ path, _ := config.ConfigPath()
+ output.KeyValue("JWT token cleared from config", path)
+ return nil
+ },
+}
+var meCmd = &cobra.Command{
+ Use: "me",
+ Short: "Get current user information",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.AuthMe())
+ if err != nil {
+ return fmt.Errorf("failed to get user info: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[interface{}]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Current User")
+ userBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal user data: %w", err)
+ }
+ fmt.Println(string(userBytes))
+ return nil
+ },
+}
+
+var passwordCmd = &cobra.Command{
+ Use: "password",
+ Short: "Change password",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ currentPassword, _ := cmd.Flags().GetString("current")
+ newPassword, _ := cmd.Flags().GetString("new")
+
+ if currentPassword == "" {
+ fmt.Print("Current password: ")
+ bytePassword, err := term.ReadPassword(int(syscall.Stdin))
+ if err != nil {
+ return fmt.Errorf("failed to read current password: %w", err)
+ }
+ currentPassword = string(bytePassword)
+ fmt.Println()
+ }
+
+ if newPassword == "" {
+ fmt.Print("New password: ")
+ bytePassword, err := term.ReadPassword(int(syscall.Stdin))
+ if err != nil {
+ return fmt.Errorf("failed to read new password: %w", err)
+ }
+ newPassword = string(bytePassword)
+ fmt.Println()
+ }
+
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ changeReq := auth.PasswordChange{
+ CurrentPassword: currentPassword,
+ NewPassword: newPassword,
+ }
+
+ reqBody, err := json.Marshal(changeReq)
+ if err != nil {
+ return fmt.Errorf("failed to marshal request: %w", err)
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.AuthPassword(), reqBody)
+ if err != nil {
+ return fmt.Errorf("password change failed: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ if jsonOutput {
+ var result base.ApiResponse[interface{}]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err == nil {
+ if resultBytes, err := json.MarshalIndent(result.Data, "", " "); err == nil {
+ fmt.Println(string(resultBytes))
+ }
+ }
+ return nil
+ }
+
+ output.Success("Password changed successfully")
+ return nil
+ },
+}
+
+var refreshCmd = &cobra.Command{
+ Use: "refresh",
+ Short: "Refresh authentication token",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ refreshToken, _ := cmd.Flags().GetString("refresh-token")
+
+ if refreshToken == "" {
+ fmt.Print("Refresh token: ")
+ if _, err := fmt.Scanln(&refreshToken); err != nil {
+ return fmt.Errorf("failed to read refresh token: %w", err)
+ }
+ }
+
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ refreshReq := auth.Refresh{
+ RefreshToken: refreshToken,
+ }
+
+ reqBody, err := json.Marshal(refreshReq)
+ if err != nil {
+ return fmt.Errorf("failed to marshal request: %w", err)
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.AuthRefresh(), reqBody)
+ if err != nil {
+ return fmt.Errorf("token refresh failed: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[auth.TokenRefreshResponse]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ // Save new JWT token to config
+ cfg, err := config.Load()
+ if err != nil {
+ return fmt.Errorf("failed to load config: %w", err)
+ }
+ cfg.JWTToken = result.Data.Token
+ if err := config.Save(cfg); err != nil {
+ return fmt.Errorf("failed to save token: %w", err)
+ }
+
+ output.Success("Token refreshed successfully")
+ path, _ := config.ConfigPath()
+ output.KeyValue("New JWT token saved to config", path)
+ return nil
+ },
+}
+
+func init() {
+ AuthCmd.AddCommand(loginCmd)
+ AuthCmd.AddCommand(logoutCmd)
+ AuthCmd.AddCommand(meCmd)
+ AuthCmd.AddCommand(passwordCmd)
+ AuthCmd.AddCommand(refreshCmd)
+
+ // Login command flags
+ loginCmd.Flags().StringP("username", "u", "", "Username")
+ loginCmd.Flags().StringP("password", "p", "", "Password")
+ loginCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Password command flags
+ passwordCmd.Flags().String("current", "", "Current password")
+ passwordCmd.Flags().String("new", "", "New password")
+ passwordCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Refresh command flags
+ refreshCmd.Flags().String("refresh-token", "", "Refresh token")
+ refreshCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Global JSON output flags
+ logoutCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ meCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+}
diff --git a/cli/pkg/config/cmd.go b/cli/pkg/config/cmd.go
index d857bcd3a..bccd47661 100644
--- a/cli/pkg/config/cmd.go
+++ b/cli/pkg/config/cmd.go
@@ -13,6 +13,7 @@ import (
var (
setServerURL string
setAPIKey string
+ setJWTToken string
setEnvironment string
setLogLevel string
)
@@ -36,13 +37,14 @@ var configShowCmd = &cobra.Command{
fmt.Printf("Config file: %s\n\n", path)
fmt.Printf("Server URL: %s\n", maskIfEmpty(cfg.ServerURL, "(not set)"))
fmt.Printf("API Key: %s\n", maskAPIKey(cfg.APIKey))
+ fmt.Printf("JWT Token: %s\n", maskAPIKey(cfg.JWTToken))
fmt.Printf("Default Environment: %s\n", maskIfEmpty(cfg.DefaultEnvironment, "0 (local)"))
fmt.Printf("Log Level: %s\n", maskIfEmpty(cfg.LogLevel, "info (default)"))
if cfg.IsConfigured() {
fmt.Println("\n✓ Configuration is complete")
} else {
- fmt.Println("\n✗ Configuration is incomplete. Run: arcane api config set --help")
+ fmt.Println("\n✗ Configuration is incomplete. Run: arcane config set --help")
}
return nil
@@ -55,9 +57,10 @@ var configSetCmd = &cobra.Command{
Long: `Set configuration values for connecting to an Arcane server.
Examples:
- arcane api config set --server-url http://localhost:3553
- arcane api config set --api-key arc_xxxxxxxxxxxxx
- arcane api config set --server-url http://my-server:3553 --api-key arc_xxxxxxxxxxxxx`,
+ arcane config set --server-url http://localhost:3553
+ arcane config set --api-key arc_xxxxxxxxxxxxx
+ arcane auth login --username admin
+ arcane config set --jwt-token eyJhbGciOi...`,
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := config.Load()
if err != nil {
@@ -74,10 +77,20 @@ Examples:
if setAPIKey != "" {
cfg.APIKey = setAPIKey
+ // If switching to API key auth, clear any existing JWT token.
+ cfg.JWTToken = ""
fmt.Printf("Set api_key = %s\n", maskAPIKey(setAPIKey))
updated = true
}
+ if setJWTToken != "" {
+ cfg.JWTToken = setJWTToken
+ // If switching to JWT auth, clear any existing API key.
+ cfg.APIKey = ""
+ fmt.Printf("Set jwt_token = %s\n", maskAPIKey(setJWTToken))
+ updated = true
+ }
+
if setEnvironment != "" {
cfg.DefaultEnvironment = setEnvironment
fmt.Printf("Set default_environment = %s\n", setEnvironment)
@@ -91,7 +104,7 @@ Examples:
}
if !updated {
- return fmt.Errorf("no configuration values provided. Use --server-url, --api-key, --environment, or --log-level")
+ return fmt.Errorf("no configuration values provided. Use --server-url, --api-key, --jwt-token, --environment, or --log-level")
}
if err := config.Save(cfg); err != nil {
@@ -139,7 +152,12 @@ var configTestCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("failed to create request: %w", err)
}
- req.Header.Set("X-API-TOKEN", cfg.APIKey)
+ // Prefer JWT bearer if present, else API key.
+ if cfg.JWTToken != "" {
+ req.Header.Set("Authorization", "Bearer "+cfg.JWTToken)
+ } else {
+ req.Header.Set("X-API-KEY", cfg.APIKey)
+ }
resp, err := httpClient.Do(req)
if err != nil {
@@ -165,6 +183,7 @@ func init() {
configSetCmd.Flags().StringVar(&setServerURL, "server-url", "", "Arcane server URL (e.g., http://localhost:3553)")
configSetCmd.Flags().StringVar(&setAPIKey, "api-key", "", "API key for authentication")
+ configSetCmd.Flags().StringVar(&setJWTToken, "jwt-token", "", "JWT access token for authentication (Bearer token)")
configSetCmd.Flags().StringVar(&setEnvironment, "environment", "", "Default environment ID")
configSetCmd.Flags().StringVar(&setLogLevel, "log-level", "", "Default log level (debug, info, warn, error)")
}
diff --git a/cli/pkg/containers/cmd.go b/cli/pkg/containers/cmd.go
index 85c179222..36e231019 100644
--- a/cli/pkg/containers/cmd.go
+++ b/cli/pkg/containers/cmd.go
@@ -3,18 +3,21 @@ package containers
import (
"encoding/json"
"fmt"
- "io"
- "os"
- "text/tabwriter"
+ "strings"
"github.com/spf13/cobra"
"go.getarcane.app/cli/internal/client"
+ "go.getarcane.app/cli/internal/output"
"go.getarcane.app/cli/internal/types"
+ "go.getarcane.app/types/base"
+ "go.getarcane.app/types/container"
)
var (
containersLimit int
containersAll bool
+ forceFlag bool
+ jsonOutput bool
)
// ContainersCmd is the parent command for container operations
@@ -25,19 +28,27 @@ var ContainersCmd = &cobra.Command{
}
var containersListCmd = &cobra.Command{
- Use: "list",
- Aliases: []string{"ls"},
- Short: "List containers",
+ Use: "list",
+ Aliases: []string{"ls"},
+ Short: "List containers",
+ SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
c, err := client.NewFromConfig()
if err != nil {
return err
}
- path := types.Endpoints.FormatContainers(c.EnvID())
+ path := types.Endpoints.Containers(c.EnvID())
if containersLimit > 0 {
path = fmt.Sprintf("%s?pageSize=%d", path, containersLimit)
}
+ if containersAll {
+ separator := "?"
+ if strings.Contains(path, "?") {
+ separator = "&"
+ }
+ path = fmt.Sprintf("%s%sall=true", path, separator)
+ }
resp, err := c.Get(cmd.Context(), path)
if err != nil {
@@ -45,50 +56,348 @@ var containersListCmd = &cobra.Command{
}
defer func() { _ = resp.Body.Close() }()
- body, err := io.ReadAll(resp.Body)
+ var result base.Paginated[container.Summary]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ headers := []string{"ID", "NAME", "IMAGE", "STATE", "STATUS"}
+ rows := make([][]string, len(result.Data))
+ for i, container := range result.Data {
+ name := ""
+ if len(container.Names) > 0 {
+ name = strings.TrimPrefix(container.Names[0], "/")
+ }
+ rows[i] = []string{
+ shortID(container.ID),
+ name,
+ container.Image,
+ container.State,
+ container.Status,
+ }
+ }
+
+ output.Table(headers, rows)
+ fmt.Printf("\nTotal: %d containers\n", result.Pagination.TotalItems)
+ return nil
+ },
+}
+
+var containersGetCmd = &cobra.Command{
+ Use: "get <container-id>",
+ Short: "Get detailed container information",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
if err != nil {
- return fmt.Errorf("failed to read response: %w", err)
+ return err
}
- var result struct {
- Items []struct {
- ID string `json:"id"`
- Names []string `json:"names"`
- Image string `json:"image"`
- State string `json:"state"`
- Status string `json:"status"`
- } `json:"items"`
- Pagination struct {
- TotalItems int64 `json:"totalItems"`
- } `json:"pagination"`
+ path := types.Endpoints.Container(c.EnvID(), args[0])
+ resp, err := c.Get(cmd.Context(), path)
+ if err != nil {
+ return fmt.Errorf("failed to get container: %w", err)
}
+ defer func() { _ = resp.Body.Close() }()
- if err := json.Unmarshal(body, &result); err != nil {
+ var result base.ApiResponse[container.Details]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return fmt.Errorf("failed to parse response: %w", err)
}
- w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
- _, _ = fmt.Fprintln(w, "ID\tNAME\tIMAGE\tSTATE\tSTATUS")
- for _, container := range result.Items {
- name := ""
- if len(container.Names) > 0 {
- name = container.Names[0]
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
}
- _, _ = fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", shortID(container.ID), name, container.Image, container.State, container.Status)
+ fmt.Println(string(resultBytes))
+ return nil
}
- _ = w.Flush()
- fmt.Printf("\nTotal: %d containers\n", result.Pagination.TotalItems)
+ output.Header("Container Details")
+ output.KeyValue("ID", result.Data.ID)
+ output.KeyValue("Name", result.Data.Name)
+ output.KeyValue("Image", result.Data.Image)
+ output.KeyValue("State", fmt.Sprintf("%s (Running: %v)", result.Data.State.Status, result.Data.State.Running))
+ output.KeyValue("Created", result.Data.Created)
+ return nil
+ },
+}
+
+var containersStartCmd = &cobra.Command{
+ Use: "start <container-id>",
+ Short: "Start a container",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ path := types.Endpoints.ContainerStart(c.EnvID(), args[0])
+ resp, err := c.Post(cmd.Context(), path, nil)
+ if err != nil {
+ return fmt.Errorf("failed to start container: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[container.ActionResult]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Success("Container %s started successfully", shortID(args[0]))
+ return nil
+ },
+}
+
+var containersStopCmd = &cobra.Command{
+ Use: "stop <container-id>",
+ Short: "Stop a container",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ path := types.Endpoints.ContainerStop(c.EnvID(), args[0])
+ resp, err := c.Post(cmd.Context(), path, nil)
+ if err != nil {
+ return fmt.Errorf("failed to stop container: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[container.ActionResult]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Success("Container %s stopped successfully", shortID(args[0]))
+ return nil
+ },
+}
+
+var containersRestartCmd = &cobra.Command{
+ Use: "restart <container-id>",
+ Short: "Restart a container",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+ path := types.Endpoints.ContainerRestart(c.EnvID(), args[0])
+ resp, err := c.Post(cmd.Context(), path, nil)
+ if err != nil {
+ return fmt.Errorf("failed to restart container: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[container.ActionResult]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Success("Container %s restarted successfully", shortID(args[0]))
+ return nil
+ },
+}
+
+var containersUpdateCmd = &cobra.Command{
+ Use: "update <container-id>",
+ Short: "Update a container",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ path := types.Endpoints.ContainerUpdate(c.EnvID(), args[0])
+ resp, err := c.Post(cmd.Context(), path, nil)
+ if err != nil {
+ return fmt.Errorf("failed to update container: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[container.ActionResult]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Success("Container %s updated successfully", shortID(args[0]))
+ return nil
+ },
+}
+
+var containersDeleteCmd = &cobra.Command{
+ Use: "delete <container-id>",
+ Aliases: []string{"rm", "remove"},
+ Short: "Delete a container",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if !forceFlag {
+ fmt.Printf("Are you sure you want to delete container %s? (y/N): ", shortID(args[0]))
+ var response string
+ if _, err := fmt.Scanln(&response); err != nil {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ if strings.ToLower(response) != "y" && strings.ToLower(response) != "yes" {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ }
+
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ path := types.Endpoints.Container(c.EnvID(), args[0])
+ resp, err := c.Delete(cmd.Context(), path)
+ if err != nil {
+ return fmt.Errorf("failed to delete container: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[container.ActionResult]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Success("Container %s deleted successfully", shortID(args[0]))
+ return nil
+ },
+}
+
+var containersCountsCmd = &cobra.Command{
+ Use: "counts",
+ Short: "Get container status counts",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ path := types.Endpoints.ContainersCounts(c.EnvID())
+ resp, err := c.Get(cmd.Context(), path)
+ if err != nil {
+ return fmt.Errorf("failed to get container counts: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[container.StatusCounts]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Container Status Counts")
+ output.KeyValue("Running", result.Data.RunningContainers)
+ output.KeyValue("Stopped", result.Data.StoppedContainers)
+ output.KeyValue("Total", result.Data.TotalContainers)
return nil
},
}
func init() {
ContainersCmd.AddCommand(containersListCmd)
+ ContainersCmd.AddCommand(containersGetCmd)
+ ContainersCmd.AddCommand(containersStartCmd)
+ ContainersCmd.AddCommand(containersStopCmd)
+ ContainersCmd.AddCommand(containersRestartCmd)
+ ContainersCmd.AddCommand(containersUpdateCmd)
+ ContainersCmd.AddCommand(containersDeleteCmd)
+ ContainersCmd.AddCommand(containersCountsCmd)
+ // List command flags
containersListCmd.Flags().IntVarP(&containersLimit, "limit", "n", 20, "Number of containers to show")
containersListCmd.Flags().BoolVarP(&containersAll, "all", "a", false, "Show all containers (including stopped)")
+ containersListCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Delete command flags
+ containersDeleteCmd.Flags().BoolVarP(&forceFlag, "force", "f", false, "Force deletion without confirmation")
+
+ // Global JSON output flags
+ containersGetCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ containersStartCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ containersStopCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ containersRestartCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ containersUpdateCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ containersDeleteCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ containersCountsCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
}
func shortID(id string) string {
diff --git a/cli/pkg/environments/cmd.go b/cli/pkg/environments/cmd.go
new file mode 100644
index 000000000..6c7cbdb38
--- /dev/null
+++ b/cli/pkg/environments/cmd.go
@@ -0,0 +1,215 @@
+package environments
+
+import (
+ "encoding/json"
+ "fmt"
+ "strings"
+
+ "github.com/spf13/cobra"
+ "go.getarcane.app/cli/internal/client"
+ "go.getarcane.app/cli/internal/output"
+ "go.getarcane.app/cli/internal/types"
+ "go.getarcane.app/types/base"
+ "go.getarcane.app/types/environment"
+)
+
+var (
+ limitFlag int
+ forceFlag bool
+ jsonOutput bool
+)
+
+// EnvironmentsCmd is the parent command for environment operations
+var EnvironmentsCmd = &cobra.Command{
+ Use: "environments",
+ Aliases: []string{"environment", "env", "e"},
+ Short: "Manage environments",
+}
+
+var listCmd = &cobra.Command{
+ Use: "list",
+ Aliases: []string{"ls"},
+ Short: "List environments",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ path := types.Endpoints.Environments()
+ if limitFlag > 0 {
+ path = fmt.Sprintf("%s?limit=%d", path, limitFlag)
+ }
+
+ resp, err := c.Get(cmd.Context(), path)
+ if err != nil {
+ return fmt.Errorf("failed to list environments: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.Paginated[environment.Environment]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ headers := []string{"ID", "NAME", "API URL", "STATUS", "ENABLED"}
+ rows := make([][]string, len(result.Data))
+ for i, env := range result.Data {
+ enabled := "false"
+ if env.Enabled {
+ enabled = "true"
+ }
+ rows[i] = []string{
+ env.ID,
+ env.Name,
+ env.ApiUrl,
+ env.Status,
+ enabled,
+ }
+ }
+
+ output.Table(headers, rows)
+ fmt.Printf("\nTotal: %d environments\n", result.Pagination.TotalItems)
+ return nil
+ },
+}
+
+var deleteCmd = &cobra.Command{
+ Use: "delete <id>",
+ Aliases: []string{"rm", "remove"},
+ Short: "Delete environment",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if !forceFlag {
+ fmt.Printf("Are you sure you want to delete environment %s? (y/N): ", args[0])
+ var response string
+ if _, err := fmt.Scanln(&response); err != nil {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ if strings.ToLower(response) != "y" && strings.ToLower(response) != "yes" {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ }
+
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Delete(cmd.Context(), types.Endpoints.Environment(args[0]))
+ if err != nil {
+ return fmt.Errorf("failed to delete environment: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ output.Success("Environment deleted successfully")
+ return nil
+ },
+}
+
+var getCmd = &cobra.Command{
+ Use: "get <id>",
+ Short: "Get environment details",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.Environment(args[0]))
+ if err != nil {
+ return fmt.Errorf("failed to get environment: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[environment.Environment]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Environment Details")
+ output.KeyValue("ID", result.Data.ID)
+ output.KeyValue("Name", result.Data.Name)
+ output.KeyValue("API URL", result.Data.ApiUrl)
+ output.KeyValue("Status", result.Data.Status)
+ output.KeyValue("Enabled", result.Data.Enabled)
+ return nil
+ },
+}
+
+var testCmd = &cobra.Command{
+ Use: "test <id>",
+ Short: "Test environment connection",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.EnvironmentTest(args[0]), nil)
+ if err != nil {
+ return fmt.Errorf("failed to test environment: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ if jsonOutput {
+ var result base.ApiResponse[interface{}]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err == nil {
+ if resultBytes, err := json.MarshalIndent(result.Data, "", " "); err == nil {
+ fmt.Println(string(resultBytes))
+ }
+ }
+ return nil
+ }
+
+ output.Success("Environment connection test successful")
+ return nil
+ },
+}
+
+func init() {
+ EnvironmentsCmd.AddCommand(listCmd)
+ EnvironmentsCmd.AddCommand(getCmd)
+ EnvironmentsCmd.AddCommand(testCmd)
+ EnvironmentsCmd.AddCommand(deleteCmd)
+
+ // List command flags
+ listCmd.Flags().IntVarP(&limitFlag, "limit", "n", 20, "Number of environments to show")
+ listCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Get command flags
+ getCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Test command flags
+ testCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Delete command flags
+ deleteCmd.Flags().BoolVarP(&forceFlag, "force", "f", false, "Force deletion without confirmation")
+ deleteCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+}
diff --git a/cli/pkg/events/cmd.go b/cli/pkg/events/cmd.go
new file mode 100644
index 000000000..61ccccc43
--- /dev/null
+++ b/cli/pkg/events/cmd.go
@@ -0,0 +1,201 @@
+package events
+
+import (
+ "encoding/json"
+ "fmt"
+ "strings"
+
+ "github.com/spf13/cobra"
+ "go.getarcane.app/cli/internal/client"
+ "go.getarcane.app/cli/internal/output"
+ "go.getarcane.app/cli/internal/types"
+ "go.getarcane.app/types/base"
+ "go.getarcane.app/types/event"
+)
+
+var (
+ limitFlag int
+ forceFlag bool
+ jsonOutput bool
+)
+
+// EventsCmd is the parent command for event operations
+var EventsCmd = &cobra.Command{
+ Use: "events",
+ Aliases: []string{"event", "evt"},
+ Short: "Manage events",
+}
+
+var listCmd = &cobra.Command{
+ Use: "list",
+ Aliases: []string{"ls"},
+ Short: "List events",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ path := types.Endpoints.Events()
+ if limitFlag > 0 {
+ path = fmt.Sprintf("%s?limit=%d", path, limitFlag)
+ }
+
+ resp, err := c.Get(cmd.Context(), path)
+ if err != nil {
+ return fmt.Errorf("failed to list events: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.Paginated[event.Event]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ headers := []string{"ID", "TYPE", "RESOURCE", "USER", "TIMESTAMP"}
+ rows := make([][]string, len(result.Data))
+ for i, evt := range result.Data {
+ resource := ""
+ if evt.ResourceName != nil && evt.ResourceType != nil {
+ resource = fmt.Sprintf("%s (%s)", *evt.ResourceName, *evt.ResourceType)
+ }
+ username := ""
+ if evt.Username != nil {
+ username = *evt.Username
+ }
+ rows[i] = []string{
+ evt.ID,
+ evt.Type,
+ resource,
+ username,
+ evt.Timestamp.String(),
+ }
+ }
+
+ output.Table(headers, rows)
+ fmt.Printf("\nTotal: %d events\n", result.Pagination.TotalItems)
+ return nil
+ },
+}
+
+var listEnvCmd = &cobra.Command{
+ Use: "list-env",
+ Short: "List events for current environment",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ path := types.Endpoints.EventsEnvironment(c.EnvID())
+ if limitFlag > 0 {
+ path = fmt.Sprintf("%s?limit=%d", path, limitFlag)
+ }
+
+ resp, err := c.Get(cmd.Context(), path)
+ if err != nil {
+ return fmt.Errorf("failed to list environment events: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.Paginated[event.Event]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ headers := []string{"ID", "TYPE", "RESOURCE", "USER", "TIMESTAMP"}
+ rows := make([][]string, len(result.Data))
+ for i, evt := range result.Data {
+ resource := ""
+ if evt.ResourceName != nil && evt.ResourceType != nil {
+ resource = fmt.Sprintf("%s (%s)", *evt.ResourceName, *evt.ResourceType)
+ }
+ username := ""
+ if evt.Username != nil {
+ username = *evt.Username
+ }
+ rows[i] = []string{
+ evt.ID,
+ evt.Type,
+ resource,
+ username,
+ evt.Timestamp.String(),
+ }
+ }
+
+ output.Table(headers, rows)
+ fmt.Printf("\nTotal: %d events\n", result.Pagination.TotalItems)
+ return nil
+ },
+}
+
+var deleteCmd = &cobra.Command{
+ Use: "delete <event-id>",
+ Aliases: []string{"rm", "remove"},
+ Short: "Delete event",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if !forceFlag {
+ fmt.Printf("Are you sure you want to delete event %s? (y/N): ", args[0])
+ var response string
+ if _, err := fmt.Scanln(&response); err != nil {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ if strings.ToLower(response) != "y" && strings.ToLower(response) != "yes" {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ }
+
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Delete(cmd.Context(), types.Endpoints.Event(args[0]))
+ if err != nil {
+ return fmt.Errorf("failed to delete event: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ output.Success("Event deleted successfully")
+ return nil
+ },
+}
+
+func init() {
+ EventsCmd.AddCommand(listCmd)
+ EventsCmd.AddCommand(listEnvCmd)
+ EventsCmd.AddCommand(deleteCmd)
+
+ listCmd.Flags().IntVarP(&limitFlag, "limit", "n", 20, "Number of events to show")
+ listCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ listEnvCmd.Flags().IntVarP(&limitFlag, "limit", "n", 20, "Number of events to show")
+ listEnvCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ deleteCmd.Flags().BoolVarP(&forceFlag, "force", "f", false, "Force deletion without confirmation")
+ deleteCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+}
diff --git a/cli/pkg/images/cmd.go b/cli/pkg/images/cmd.go
index 1c9173b27..63a2fa7d2 100644
--- a/cli/pkg/images/cmd.go
+++ b/cli/pkg/images/cmd.go
@@ -49,7 +49,7 @@ import (
"go.getarcane.app/cli/internal/client"
"go.getarcane.app/cli/internal/logger"
"go.getarcane.app/cli/internal/output"
- clitypes "go.getarcane.app/cli/internal/types"
+ "go.getarcane.app/cli/internal/types"
"go.getarcane.app/types/image"
"go.withmatt.com/size"
)
@@ -81,7 +81,7 @@ var imagesListCmd = &cobra.Command{
return err
}
- path := clitypes.Endpoints.UseImageEndpoint(clitypes.ImageEndpointActionList, c.EnvID())
+ path := types.Endpoints.Images(c.EnvID())
// Parse the path to handle query params
u, err := url.Parse(path)
@@ -177,7 +177,7 @@ var imagesGetCmd = &cobra.Command{
}
imageID := args[0]
- path := fmt.Sprintf("%s/%s", clitypes.Endpoints.UseImageEndpoint(clitypes.ImageEndpointActionGet, c.EnvID()), imageID)
+ path := types.Endpoints.Image(c.EnvID(), imageID)
log.Debugf("Getting image details from: %s", path)
@@ -272,7 +272,7 @@ var imagesRemoveCmd = &cobra.Command{
}
imageID := args[0]
- path := fmt.Sprintf("%s/%s", clitypes.Endpoints.UseImageEndpoint(clitypes.ImageEndpointActionDelete, c.EnvID()), imageID)
+ path := types.Endpoints.Image(c.EnvID(), imageID)
if removeForce {
u, err := url.Parse(path)
@@ -335,7 +335,7 @@ var imagesPullCmd = &cobra.Command{
}
imageName := args[0]
- path := clitypes.Endpoints.UseImageEndpoint(clitypes.ImageEndpointActionPull, c.EnvID())
+ path := types.Endpoints.ImagesPull(c.EnvID())
log.Debugf("Pulling image from: %s", path)
@@ -459,7 +459,7 @@ var imagesPruneCmd = &cobra.Command{
return err
}
- path := clitypes.Endpoints.UseImageEndpoint(clitypes.ImageEndpointActionPrune, c.EnvID())
+ path := types.Endpoints.ImagesPrune(c.EnvID())
log.Debugf("Pruning images from: %s", path)
@@ -557,7 +557,7 @@ var imagesCountsCmd = &cobra.Command{
return err
}
- path := clitypes.Endpoints.UseImageEndpoint(clitypes.ImageEndpointActionCounts, c.EnvID())
+ path := types.Endpoints.ImagesCounts(c.EnvID())
log.Debugf("Getting image counts from: %s", path)
@@ -611,7 +611,7 @@ var imagesUploadCmd = &cobra.Command{
}
filePath := args[0]
- path := clitypes.Endpoints.UseImageEndpoint(clitypes.ImageEndpointActionUpload, c.EnvID())
+ path := types.Endpoints.ImagesUpload(c.EnvID())
log.Debugf("Uploading image from file: %s to %s", filePath, path)
diff --git a/cli/pkg/imageupdates/cmd.go b/cli/pkg/imageupdates/cmd.go
new file mode 100644
index 000000000..d8c12eefd
--- /dev/null
+++ b/cli/pkg/imageupdates/cmd.go
@@ -0,0 +1,205 @@
+package imageupdates
+
+import (
+ "encoding/json"
+ "fmt"
+
+ "github.com/spf13/cobra"
+ "go.getarcane.app/cli/internal/client"
+ "go.getarcane.app/cli/internal/output"
+ "go.getarcane.app/cli/internal/types"
+ "go.getarcane.app/types/base"
+ "go.getarcane.app/types/imageupdate"
+)
+
+var jsonOutput bool
+
+// ImageUpdatesCmd is the parent command for image update operations
+var ImageUpdatesCmd = &cobra.Command{
+ Use: "image-updates",
+ Aliases: []string{"imgup", "updates"},
+ Short: "Check for image updates",
+}
+
+var checkCmd = &cobra.Command{
+ Use: "check",
+ Short: "Check for image updates",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.ImageUpdatesCheck(c.EnvID()))
+ if err != nil {
+ return fmt.Errorf("failed to check updates: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[imageupdate.BatchResponse]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Image Update Check Results")
+ updatesAvailable := 0
+ for imageRef, update := range result.Data {
+ if update != nil && update.HasUpdate {
+ output.KeyValue(imageRef, fmt.Sprintf("%s → %s (%s)", update.CurrentVersion, update.LatestVersion, update.UpdateType))
+ updatesAvailable++
+ }
+ }
+
+ fmt.Printf("\nTotal: %d images checked, %d updates available\n", len(result.Data), updatesAvailable)
+ return nil
+ },
+}
+
+var checkAllCmd = &cobra.Command{
+ Use: "check-all",
+ Short: "Check all images for updates",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.ImageUpdatesCheckAll(c.EnvID()), nil)
+ if err != nil {
+ return fmt.Errorf("failed to check all updates: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[imageupdate.BatchResponse]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Check All Results")
+ updatesAvailable := 0
+ for imageRef, update := range result.Data {
+ if update != nil && update.HasUpdate {
+ output.KeyValue(imageRef, fmt.Sprintf("%s → %s (%s)", update.CurrentVersion, update.LatestVersion, update.UpdateType))
+ updatesAvailable++
+ }
+ }
+
+ fmt.Printf("\nTotal: %d images checked, %d updates available\n", len(result.Data), updatesAvailable)
+ return nil
+ },
+}
+
+var checkImageCmd = &cobra.Command{
+ Use: "check-image <image-id>",
+ Short: "Check specific image for updates",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.ImageUpdatesCheckById(c.EnvID(), args[0]))
+ if err != nil {
+ return fmt.Errorf("failed to check image update: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[imageupdate.Response]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Image Update Status")
+ output.KeyValue("Has Update", fmt.Sprintf("%t", result.Data.HasUpdate))
+ if result.Data.HasUpdate {
+ output.KeyValue("Update Type", result.Data.UpdateType)
+ output.KeyValue("Current Version", result.Data.CurrentVersion)
+ output.KeyValue("Latest Version", result.Data.LatestVersion)
+ }
+ output.KeyValue("Check Time", result.Data.CheckTime.String())
+ output.KeyValue("Response Time", fmt.Sprintf("%dms", result.Data.ResponseTimeMs))
+ return nil
+ },
+}
+
+var summaryCmd = &cobra.Command{
+ Use: "summary",
+ Short: "Get image updates summary",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.ImageUpdatesSummary(c.EnvID()))
+ if err != nil {
+ return fmt.Errorf("failed to get summary: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[imageupdate.Summary]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Image Updates Summary")
+ output.KeyValue("Total Images", fmt.Sprintf("%d", result.Data.TotalImages))
+ output.KeyValue("Images with Updates", fmt.Sprintf("%d", result.Data.ImagesWithUpdates))
+ output.KeyValue("Digest Updates", fmt.Sprintf("%d", result.Data.DigestUpdates))
+ output.KeyValue("Errors", fmt.Sprintf("%d", result.Data.ErrorsCount))
+ return nil
+ },
+}
+
+func init() {
+ ImageUpdatesCmd.AddCommand(checkCmd)
+ ImageUpdatesCmd.AddCommand(checkAllCmd)
+ ImageUpdatesCmd.AddCommand(checkImageCmd)
+ ImageUpdatesCmd.AddCommand(summaryCmd)
+
+ checkCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ checkAllCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ checkImageCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ summaryCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+}
diff --git a/cli/pkg/networks/cmd.go b/cli/pkg/networks/cmd.go
new file mode 100644
index 000000000..6bc6fbe10
--- /dev/null
+++ b/cli/pkg/networks/cmd.go
@@ -0,0 +1,243 @@
+package networks
+
+import (
+ "encoding/json"
+ "fmt"
+ "strings"
+
+ "github.com/spf13/cobra"
+ "go.getarcane.app/cli/internal/client"
+ "go.getarcane.app/cli/internal/output"
+ "go.getarcane.app/cli/internal/types"
+ "go.getarcane.app/types/base"
+ "go.getarcane.app/types/network"
+)
+
+var (
+ limitFlag int
+ forceFlag bool
+ jsonOutput bool
+)
+
+// NetworksCmd is the parent command for network operations
+var NetworksCmd = &cobra.Command{
+ Use: "networks",
+ Aliases: []string{"network", "net", "n"},
+ Short: "Manage networks",
+}
+
+var listCmd = &cobra.Command{
+ Use: "list",
+ Aliases: []string{"ls"},
+ Short: "List networks",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ path := types.Endpoints.Networks(c.EnvID())
+ if limitFlag > 0 {
+ path = fmt.Sprintf("%s?limit=%d", path, limitFlag)
+ }
+
+ resp, err := c.Get(cmd.Context(), path)
+ if err != nil {
+ return fmt.Errorf("failed to list networks: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.Paginated[network.Summary]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ headers := []string{"ID", "NAME", "DRIVER", "SCOPE", "CREATED"}
+ rows := make([][]string, len(result.Data))
+ for i, net := range result.Data {
+ rows[i] = []string{
+ shortID(net.ID),
+ net.Name,
+ net.Driver,
+ net.Scope,
+ net.Created.Format("2006-01-02 15:04"),
+ }
+ }
+
+ output.Table(headers, rows)
+ fmt.Printf("\nTotal: %d networks\n", result.Pagination.TotalItems)
+ return nil
+ },
+}
+
+var deleteCmd = &cobra.Command{
+ Use: "delete <network-id>",
+ Aliases: []string{"rm", "remove"},
+ Short: "Delete a network",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if !forceFlag {
+ fmt.Printf("Are you sure you want to delete network %s? (y/N): ", shortID(args[0]))
+ var response string
+ if _, err := fmt.Scanln(&response); err != nil {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ if strings.ToLower(response) != "y" && strings.ToLower(response) != "yes" {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ }
+
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Delete(cmd.Context(), types.Endpoints.Network(c.EnvID(), args[0]))
+ if err != nil {
+ return fmt.Errorf("failed to delete network: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ if jsonOutput {
+ var result base.ApiResponse[interface{}]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err == nil {
+ if resultBytes, err := json.MarshalIndent(result.Data, "", " "); err == nil {
+ fmt.Println(string(resultBytes))
+ }
+ }
+ return nil
+ }
+
+ output.Success("Network %s deleted successfully", shortID(args[0]))
+ return nil
+ },
+}
+
+var countsCmd = &cobra.Command{
+ Use: "counts",
+ Short: "Get network usage counts",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.NetworksCounts(c.EnvID()))
+ if err != nil {
+ return fmt.Errorf("failed to get network counts: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[network.UsageCounts]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Network Usage Counts")
+ output.KeyValue("Total networks", result.Data.Total)
+ output.KeyValue("In use", result.Data.Inuse)
+ output.KeyValue("Unused", result.Data.Unused)
+ return nil
+ },
+}
+
+var pruneCmd = &cobra.Command{
+ Use: "prune",
+ Short: "Remove unused networks",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if !forceFlag {
+ fmt.Print("Are you sure you want to prune unused networks? (y/N): ")
+ var response string
+ if _, err := fmt.Scanln(&response); err != nil {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ if strings.ToLower(response) != "y" && strings.ToLower(response) != "yes" {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ }
+
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.NetworksPrune(c.EnvID()), nil)
+ if err != nil {
+ return fmt.Errorf("failed to prune networks: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[network.PruneReport]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Success("Networks pruned successfully")
+ output.KeyValue("Deleted networks", len(result.Data.NetworksDeleted))
+ return nil
+ },
+}
+
+func init() {
+ NetworksCmd.AddCommand(listCmd)
+ NetworksCmd.AddCommand(deleteCmd)
+ NetworksCmd.AddCommand(countsCmd)
+ NetworksCmd.AddCommand(pruneCmd)
+
+ // List command flags
+ listCmd.Flags().IntVarP(&limitFlag, "limit", "n", 20, "Number of networks to show")
+ listCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Delete command flags
+ deleteCmd.Flags().BoolVarP(&forceFlag, "force", "f", false, "Force deletion without confirmation")
+ deleteCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Prune command flags
+ pruneCmd.Flags().BoolVarP(&forceFlag, "force", "f", false, "Force prune without confirmation")
+ pruneCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Counts command flags
+ countsCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+}
+
+func shortID(id string) string {
+ if len(id) > 12 {
+ return id[:12]
+ }
+ return id
+}
diff --git a/cli/pkg/notifications/cmd.go b/cli/pkg/notifications/cmd.go
new file mode 100644
index 000000000..d7f416f74
--- /dev/null
+++ b/cli/pkg/notifications/cmd.go
@@ -0,0 +1,116 @@
+package notifications
+
+import (
+ "encoding/json"
+ "fmt"
+
+ "github.com/spf13/cobra"
+ "go.getarcane.app/cli/internal/client"
+ "go.getarcane.app/cli/internal/output"
+ "go.getarcane.app/cli/internal/types"
+ "go.getarcane.app/types/base"
+ "go.getarcane.app/types/notification"
+)
+
+var jsonOutput bool
+
+// NotificationsCmd is the parent command for notification operations
+var NotificationsCmd = &cobra.Command{
+ Use: "notifications",
+ Aliases: []string{"notif", "notify"},
+ Short: "Manage notifications",
+}
+
+var appriseGetCmd = &cobra.Command{
+ Use: "apprise-get",
+ Short: "Get Apprise configuration",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.NotificationsApprise(c.EnvID()))
+ if err != nil {
+ return fmt.Errorf("failed to get apprise config: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[notification.AppriseResponse]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Apprise Configuration")
+ output.KeyValue("ID", fmt.Sprintf("%d", result.Data.ID))
+ output.KeyValue("API URL", result.Data.APIURL)
+ output.KeyValue("Enabled", fmt.Sprintf("%t", result.Data.Enabled))
+ output.KeyValue("Image Update Tag", result.Data.ImageUpdateTag)
+ output.KeyValue("Container Update Tag", result.Data.ContainerUpdateTag)
+ return nil
+ },
+}
+
+var settingsGetCmd = &cobra.Command{
+ Use: "settings-get",
+ Short: "Get notification settings",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.NotificationsSettings(c.EnvID()))
+ if err != nil {
+ return fmt.Errorf("failed to get settings: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[[]notification.Response]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ headers := []string{"ID", "PROVIDER", "ENABLED"}
+ rows := make([][]string, len(result.Data))
+ for i, setting := range result.Data {
+ rows[i] = []string{
+ fmt.Sprintf("%d", setting.ID),
+ string(setting.Provider),
+ fmt.Sprintf("%t", setting.Enabled),
+ }
+ }
+
+ output.Table(headers, rows)
+ fmt.Printf("\nTotal: %d notification settings\n", len(result.Data))
+ return nil
+ },
+}
+
+func init() {
+ NotificationsCmd.AddCommand(appriseGetCmd)
+ NotificationsCmd.AddCommand(settingsGetCmd)
+
+ appriseGetCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ settingsGetCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+}
diff --git a/cli/pkg/projects/cmd.go b/cli/pkg/projects/cmd.go
new file mode 100644
index 000000000..d33993688
--- /dev/null
+++ b/cli/pkg/projects/cmd.go
@@ -0,0 +1,333 @@
+package projects
+
+import (
+ "encoding/json"
+ "fmt"
+ "strings"
+
+ "github.com/spf13/cobra"
+ "go.getarcane.app/cli/internal/client"
+ "go.getarcane.app/cli/internal/output"
+ "go.getarcane.app/cli/internal/types"
+ "go.getarcane.app/types/base"
+ "go.getarcane.app/types/project"
+)
+
+var (
+ limitFlag int
+ forceFlag bool
+ jsonOutput bool
+)
+
+// ProjectsCmd is the parent command for project operations
+var ProjectsCmd = &cobra.Command{
+ Use: "projects",
+ Aliases: []string{"project", "proj", "p"},
+ Short: "Manage projects",
+}
+
+var listCmd = &cobra.Command{
+ Use: "list",
+ Aliases: []string{"ls"},
+ Short: "List projects",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ path := types.Endpoints.Projects(c.EnvID())
+ if limitFlag > 0 {
+ path = fmt.Sprintf("%s?limit=%d", path, limitFlag)
+ }
+
+ resp, err := c.Get(cmd.Context(), path)
+ if err != nil {
+ return fmt.Errorf("failed to list projects: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.Paginated[project.Details]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ headers := []string{"ID", "NAME", "STATUS", "SERVICES", "RUNNING", "CREATED"}
+ rows := make([][]string, len(result.Data))
+ for i, proj := range result.Data {
+ rows[i] = []string{
+ proj.ID,
+ proj.Name,
+ proj.Status,
+ fmt.Sprintf("%d", proj.ServiceCount),
+ fmt.Sprintf("%d", proj.RunningCount),
+ proj.CreatedAt,
+ }
+ }
+
+ output.Table(headers, rows)
+ fmt.Printf("\nTotal: %d projects\n", result.Pagination.TotalItems)
+ return nil
+ },
+}
+
+var destroyCmd = &cobra.Command{
+ Use: "destroy <project-id>",
+ Aliases: []string{"rm", "remove"},
+ Short: "Destroy project and remove all containers",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if !forceFlag {
+ fmt.Printf("Are you sure you want to destroy project %s? This will remove all containers! (y/N): ", args[0])
+ var response string
+ if _, err := fmt.Scanln(&response); err != nil {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ if strings.ToLower(response) != "y" && strings.ToLower(response) != "yes" {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ }
+
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Delete(cmd.Context(), types.Endpoints.ProjectDestroy(c.EnvID(), args[0]))
+ if err != nil {
+ return fmt.Errorf("failed to destroy project: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ output.Success("Project %s destroyed successfully", args[0])
+ return nil
+ },
+}
+
+var getCmd = &cobra.Command{
+ Use: "get <project-id>",
+ Short: "Get project details",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.Project(c.EnvID(), args[0]))
+ if err != nil {
+ return fmt.Errorf("failed to get project: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[project.Details]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Project Details")
+ output.KeyValue("ID", result.Data.ID)
+ output.KeyValue("Name", result.Data.Name)
+ output.KeyValue("Status", result.Data.Status)
+ output.KeyValue("Services", result.Data.ServiceCount)
+ output.KeyValue("Running", result.Data.RunningCount)
+ return nil
+ },
+}
+
+var upCmd = &cobra.Command{
+ Use: "up <project-id>",
+ Short: "Start project services",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.ProjectUp(c.EnvID(), args[0]), nil)
+ if err != nil {
+ return fmt.Errorf("failed to start project: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ output.Success("Project %s started successfully", args[0])
+ return nil
+ },
+}
+
+var downCmd = &cobra.Command{
+ Use: "down <project-id>",
+ Short: "Stop project services",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.ProjectDown(c.EnvID(), args[0]), nil)
+ if err != nil {
+ return fmt.Errorf("failed to stop project: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ output.Success("Project %s stopped successfully", args[0])
+ return nil
+ },
+}
+
+var restartCmd = &cobra.Command{
+ Use: "restart <project-id>",
+ Short: "Restart project services",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.ProjectRestart(c.EnvID(), args[0]), nil)
+ if err != nil {
+ return fmt.Errorf("failed to restart project: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ output.Success("Project %s restarted successfully", args[0])
+ return nil
+ },
+}
+
+var redeployCmd = &cobra.Command{
+ Use: "redeploy <project-id>",
+ Short: "Redeploy project (pull images and restart)",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.ProjectRedeploy(c.EnvID(), args[0]), nil)
+ if err != nil {
+ return fmt.Errorf("failed to redeploy project: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ output.Success("Project %s redeployed successfully", args[0])
+ return nil
+ },
+}
+
+var pullCmd = &cobra.Command{
+ Use: "pull <project-id>",
+ Short: "Pull latest images for project",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.ProjectPull(c.EnvID(), args[0]), nil)
+ if err != nil {
+ return fmt.Errorf("failed to pull images: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ output.Success("Images pulled successfully for project %s", args[0])
+ return nil
+ },
+}
+
+var countsCmd = &cobra.Command{
+ Use: "counts",
+ Short: "Get project counts",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.ProjectsCounts(c.EnvID()))
+ if err != nil {
+ return fmt.Errorf("failed to get project counts: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[map[string]interface{}]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Project Counts")
+ for k, v := range result.Data {
+ output.KeyValue(k, v)
+ }
+ return nil
+ },
+}
+
+func init() {
+ ProjectsCmd.AddCommand(listCmd)
+ ProjectsCmd.AddCommand(getCmd)
+ ProjectsCmd.AddCommand(upCmd)
+ ProjectsCmd.AddCommand(downCmd)
+ ProjectsCmd.AddCommand(restartCmd)
+ ProjectsCmd.AddCommand(redeployCmd)
+ ProjectsCmd.AddCommand(pullCmd)
+ ProjectsCmd.AddCommand(countsCmd)
+ ProjectsCmd.AddCommand(destroyCmd)
+
+ // List command flags
+ listCmd.Flags().IntVarP(&limitFlag, "limit", "n", 20, "Number of projects to show")
+ listCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Get command flags
+ getCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Counts command flags
+ countsCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Destroy command flags
+ destroyCmd.Flags().BoolVarP(&forceFlag, "force", "f", false, "Force destroy without confirmation")
+ destroyCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+}
diff --git a/cli/pkg/registries/cmd.go b/cli/pkg/registries/cmd.go
new file mode 100644
index 000000000..dd0eda093
--- /dev/null
+++ b/cli/pkg/registries/cmd.go
@@ -0,0 +1,203 @@
+package registries
+
+import (
+ "encoding/json"
+ "fmt"
+ "strings"
+
+ "github.com/spf13/cobra"
+ "go.getarcane.app/cli/internal/client"
+ "go.getarcane.app/cli/internal/output"
+ "go.getarcane.app/cli/internal/types"
+ "go.getarcane.app/types/base"
+ "go.getarcane.app/types/containerregistry"
+)
+
+var (
+ limitFlag int
+ forceFlag bool
+ jsonOutput bool
+)
+
+var RegistriesCmd = &cobra.Command{
+ Use: "registries",
+ Aliases: []string{"registry", "reg"},
+ Short: "Manage container registries",
+}
+
+var listCmd = &cobra.Command{
+ Use: "list",
+ Aliases: []string{"ls"},
+ Short: "List container registries",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ path := types.Endpoints.ContainerRegistries()
+ if limitFlag > 0 {
+ path = fmt.Sprintf("%s?limit=%d", path, limitFlag)
+ }
+
+ resp, err := c.Get(cmd.Context(), path)
+ if err != nil {
+ return fmt.Errorf("failed to list registries: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.Paginated[containerregistry.ContainerRegistry]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ headers := []string{"ID", "URL", "USERNAME", "ENABLED", "INSECURE"}
+ rows := make([][]string, len(result.Data))
+ for i, reg := range result.Data {
+ enabled := "false"
+ if reg.Enabled {
+ enabled = "true"
+ }
+ insecure := "false"
+ if reg.Insecure {
+ insecure = "true"
+ }
+ rows[i] = []string{
+ reg.ID,
+ reg.URL,
+ reg.Username,
+ enabled,
+ insecure,
+ }
+ }
+
+ output.Table(headers, rows)
+ fmt.Printf("\nTotal: %d registries\n", result.Pagination.TotalItems)
+ return nil
+ },
+}
+
+var syncCmd = &cobra.Command{
+ Use: "sync",
+ Short: "Sync container registries",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.ContainerRegistrySync(), nil)
+ if err != nil {
+ return fmt.Errorf("failed to sync registries: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ if jsonOutput {
+ var result base.ApiResponse[interface{}]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err == nil {
+ if resultBytes, err := json.MarshalIndent(result.Data, "", " "); err == nil {
+ fmt.Println(string(resultBytes))
+ }
+ }
+ return nil
+ }
+
+ output.Success("Registries synced successfully")
+ return nil
+ },
+}
+
+var testCmd = &cobra.Command{
+ Use: "test <registry-id>",
+ Short: "Test container registry connection",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.ContainerRegistryTest(args[0]), nil)
+ if err != nil {
+ return fmt.Errorf("failed to test registry: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ if jsonOutput {
+ var result base.ApiResponse[interface{}]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err == nil {
+ if resultBytes, err := json.MarshalIndent(result.Data, "", " "); err == nil {
+ fmt.Println(string(resultBytes))
+ }
+ }
+ return nil
+ }
+
+ output.Success("Registry connection test successful")
+ return nil
+ },
+}
+
+var deleteCmd = &cobra.Command{
+ Use: "delete <registry-id>",
+ Aliases: []string{"rm", "remove"},
+ Short: "Delete container registry",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if !forceFlag {
+ fmt.Printf("Are you sure you want to delete registry %s? (y/N): ", args[0])
+ var response string
+ if _, err := fmt.Scanln(&response); err != nil {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ if strings.ToLower(response) != "y" && strings.ToLower(response) != "yes" {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ }
+
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Delete(cmd.Context(), types.Endpoints.ContainerRegistry(args[0]))
+ if err != nil {
+ return fmt.Errorf("failed to delete registry: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ output.Success("Registry deleted successfully")
+ return nil
+ },
+}
+
+func init() {
+ RegistriesCmd.AddCommand(listCmd)
+ RegistriesCmd.AddCommand(syncCmd)
+ RegistriesCmd.AddCommand(testCmd)
+ RegistriesCmd.AddCommand(deleteCmd)
+
+ listCmd.Flags().IntVarP(&limitFlag, "limit", "n", 20, "Number of registries to show")
+ listCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ syncCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ testCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ deleteCmd.Flags().BoolVarP(&forceFlag, "force", "f", false, "Force deletion without confirmation")
+ deleteCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+}
diff --git a/cli/pkg/root.go b/cli/pkg/root.go
index 6cc54b5f3..dce99c26e 100644
--- a/cli/pkg/root.go
+++ b/cli/pkg/root.go
@@ -36,11 +36,26 @@ import (
"github.com/spf13/cobra"
"go.getarcane.app/cli/internal/config"
"go.getarcane.app/cli/internal/logger"
+ "go.getarcane.app/cli/pkg/apikeys"
+ "go.getarcane.app/cli/pkg/auth"
configClient "go.getarcane.app/cli/pkg/config"
"go.getarcane.app/cli/pkg/containers"
+ "go.getarcane.app/cli/pkg/environments"
+ "go.getarcane.app/cli/pkg/events"
"go.getarcane.app/cli/pkg/generate"
"go.getarcane.app/cli/pkg/images"
+ "go.getarcane.app/cli/pkg/imageupdates"
+ "go.getarcane.app/cli/pkg/networks"
+ "go.getarcane.app/cli/pkg/notifications"
+ "go.getarcane.app/cli/pkg/projects"
+ "go.getarcane.app/cli/pkg/registries"
+ "go.getarcane.app/cli/pkg/settings"
+ "go.getarcane.app/cli/pkg/system"
+ "go.getarcane.app/cli/pkg/templates"
+ "go.getarcane.app/cli/pkg/updater"
+ "go.getarcane.app/cli/pkg/users"
"go.getarcane.app/cli/pkg/version"
+ "go.getarcane.app/cli/pkg/volumes"
)
var (
@@ -91,6 +106,29 @@ func init() {
rootCmd.AddCommand(configClient.ConfigCmd)
rootCmd.AddCommand(generate.GenerateCmd)
rootCmd.AddCommand(version.VersionCmd)
+
+ // Authentication
+ rootCmd.AddCommand(auth.AuthCmd)
+
+ // Core resource management
rootCmd.AddCommand(containers.ContainersCmd)
rootCmd.AddCommand(images.ImagesCmd)
+ rootCmd.AddCommand(volumes.VolumesCmd)
+ rootCmd.AddCommand(networks.NetworksCmd)
+ rootCmd.AddCommand(projects.ProjectsCmd)
+
+ // Management
+ rootCmd.AddCommand(apikeys.ApiKeysCmd)
+ rootCmd.AddCommand(environments.EnvironmentsCmd)
+ rootCmd.AddCommand(users.UsersCmd)
+
+ // Advanced features
+ rootCmd.AddCommand(registries.RegistriesCmd)
+ rootCmd.AddCommand(templates.TemplatesCmd)
+ rootCmd.AddCommand(settings.SettingsCmd)
+ rootCmd.AddCommand(notifications.NotificationsCmd)
+ rootCmd.AddCommand(imageupdates.ImageUpdatesCmd)
+ rootCmd.AddCommand(system.SystemCmd)
+ rootCmd.AddCommand(updater.UpdaterCmd)
+ rootCmd.AddCommand(events.EventsCmd)
}
diff --git a/cli/pkg/settings/cmd.go b/cli/pkg/settings/cmd.go
new file mode 100644
index 000000000..b6a632c09
--- /dev/null
+++ b/cli/pkg/settings/cmd.go
@@ -0,0 +1,175 @@
+package settings
+
+import (
+ "encoding/json"
+ "fmt"
+
+ "github.com/spf13/cobra"
+ "go.getarcane.app/cli/internal/client"
+ "go.getarcane.app/cli/internal/output"
+ "go.getarcane.app/cli/internal/types"
+ "go.getarcane.app/types/base"
+ "go.getarcane.app/types/category"
+ "go.getarcane.app/types/search"
+ "go.getarcane.app/types/settings"
+)
+
+var jsonOutput bool
+
+// SettingsCmd is the parent command for settings operations
+var SettingsCmd = &cobra.Command{
+ Use: "settings",
+ Aliases: []string{"setting", "config"},
+ Short: "Manage settings",
+}
+
+var getCmd = &cobra.Command{
+ Use: "get",
+ Short: "Get environment settings",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.Settings(c.EnvID()))
+ if err != nil {
+ return fmt.Errorf("failed to get settings: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[[]settings.SettingDto]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ headers := []string{"KEY", "TYPE", "VALUE", "PUBLIC"}
+ rows := make([][]string, len(result.Data))
+ for i, s := range result.Data {
+ rows[i] = []string{
+ s.Key,
+ s.Type,
+ s.Value,
+ fmt.Sprintf("%t", s.IsPublic),
+ }
+ }
+
+ output.Table(headers, rows)
+ fmt.Printf("\nTotal: %d settings\n", len(result.Data))
+ return nil
+ },
+}
+
+var categoriesCmd = &cobra.Command{
+ Use: "categories",
+ Short: "List setting categories",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.SettingsCategories())
+ if err != nil {
+ return fmt.Errorf("failed to get categories: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[[]category.Category]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ headers := []string{"ID", "TITLE", "DESCRIPTION"}
+ rows := make([][]string, len(result.Data))
+ for i, cat := range result.Data {
+ rows[i] = []string{
+ cat.ID,
+ cat.Title,
+ cat.Description,
+ }
+ }
+
+ output.Table(headers, rows)
+ fmt.Printf("\nTotal: %d categories\n", len(result.Data))
+ return nil
+ },
+}
+
+var searchCmd = &cobra.Command{
+ Use: "search <query>",
+ Short: "Search settings",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ reqBody, err := json.Marshal(search.Request{Query: args[0]})
+ if err != nil {
+ return fmt.Errorf("failed to marshal request: %w", err)
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.SettingsSearch(), reqBody)
+ if err != nil {
+ return fmt.Errorf("failed to search settings: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[search.Response]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Search Results")
+ fmt.Printf("Query: %s\n", result.Data.Query)
+ fmt.Printf("Found: %d results\n\n", result.Data.Count)
+
+ for _, cat := range result.Data.Results {
+ output.KeyValue(cat.Title, cat.Description)
+ }
+
+ return nil
+ },
+}
+
+func init() {
+ SettingsCmd.AddCommand(getCmd)
+ SettingsCmd.AddCommand(categoriesCmd)
+ SettingsCmd.AddCommand(searchCmd)
+
+ getCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ categoriesCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ searchCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+}
diff --git a/cli/pkg/system/cmd.go b/cli/pkg/system/cmd.go
new file mode 100644
index 000000000..517c9741e
--- /dev/null
+++ b/cli/pkg/system/cmd.go
@@ -0,0 +1,152 @@
+package system
+
+import (
+ "encoding/json"
+ "fmt"
+
+ "github.com/spf13/cobra"
+ "go.getarcane.app/cli/internal/client"
+ "go.getarcane.app/cli/internal/output"
+ "go.getarcane.app/cli/internal/types"
+ "go.getarcane.app/types/base"
+ "go.getarcane.app/types/dockerinfo"
+ "go.getarcane.app/types/system"
+)
+
+var jsonOutput bool
+
+// SystemCmd is the parent command for system operations
+var SystemCmd = &cobra.Command{
+ Use: "system",
+ Aliases: []string{"sys"},
+ Short: "System operations",
+}
+
+var pruneCmd = &cobra.Command{
+ Use: "prune",
+ Short: "Prune all unused resources",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.SystemPrune(c.EnvID()), nil)
+ if err != nil {
+ return fmt.Errorf("failed to prune: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[system.PruneAllResult]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("System Prune Results")
+ output.KeyValue("Space Reclaimed", result.Data.SpaceReclaimed)
+ return nil
+ },
+}
+
+var dockerInfoCmd = &cobra.Command{
+ Use: "docker-info",
+ Short: "Get Docker daemon information",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.SystemDockerInfo(c.EnvID()))
+ if err != nil {
+ return fmt.Errorf("failed to get docker info: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[dockerinfo.Info]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Docker Info")
+ output.KeyValue("API Version", result.Data.APIVersion)
+ output.KeyValue("OS", result.Data.Os)
+ output.KeyValue("Architecture", result.Data.Arch)
+ output.KeyValue("Go Version", result.Data.GoVersion)
+ return nil
+ },
+}
+
+var containersStartAllCmd = &cobra.Command{
+ Use: "containers-start-all",
+ Short: "Start all containers",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.SystemContainersStartAll(c.EnvID()), nil)
+ if err != nil {
+ return fmt.Errorf("failed to start all containers: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ output.Success("Started all containers")
+ return nil
+ },
+}
+
+var containersStopAllCmd = &cobra.Command{
+ Use: "containers-stop-all",
+ Short: "Stop all containers",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.SystemContainersStopAll(c.EnvID()), nil)
+ if err != nil {
+ return fmt.Errorf("failed to stop all containers: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ output.Success("Stopped all containers")
+ return nil
+ },
+}
+
+func init() {
+ SystemCmd.AddCommand(pruneCmd)
+ SystemCmd.AddCommand(dockerInfoCmd)
+ SystemCmd.AddCommand(containersStartAllCmd)
+ SystemCmd.AddCommand(containersStopAllCmd)
+
+ pruneCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ dockerInfoCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ containersStartAllCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ containersStopAllCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+}
diff --git a/cli/pkg/templates/cmd.go b/cli/pkg/templates/cmd.go
new file mode 100644
index 000000000..316138f45
--- /dev/null
+++ b/cli/pkg/templates/cmd.go
@@ -0,0 +1,424 @@
+package templates
+
+import (
+ "encoding/json"
+ "fmt"
+ "strings"
+
+ "github.com/spf13/cobra"
+ "go.getarcane.app/cli/internal/client"
+ "go.getarcane.app/cli/internal/output"
+ "go.getarcane.app/cli/internal/types"
+ "go.getarcane.app/types/base"
+ "go.getarcane.app/types/env"
+ "go.getarcane.app/types/template"
+)
+
+var (
+ limitFlag int
+ forceFlag bool
+ jsonOutput bool
+)
+
+// TemplatesCmd is the parent command for template operations
+var TemplatesCmd = &cobra.Command{
+ Use: "templates",
+ Aliases: []string{"template", "tpl"},
+ Short: "Manage Docker Compose templates",
+}
+
+var listCmd = &cobra.Command{
+ Use: "list",
+ Aliases: []string{"ls"},
+ Short: "List templates",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ path := types.Endpoints.Templates()
+ if limitFlag > 0 {
+ path = fmt.Sprintf("%s?limit=%d", path, limitFlag)
+ }
+
+ resp, err := c.Get(cmd.Context(), path)
+ if err != nil {
+ return fmt.Errorf("failed to list templates: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[[]template.Template]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ headers := []string{"ID", "NAME", "DESCRIPTION", "CUSTOM", "REMOTE"}
+ rows := make([][]string, len(result.Data))
+ for i, tpl := range result.Data {
+ custom := "no"
+ if tpl.IsCustom {
+ custom = "yes"
+ }
+ remote := "no"
+ if tpl.IsRemote {
+ remote = "yes"
+ }
+ rows[i] = []string{
+ tpl.ID,
+ tpl.Name,
+ tpl.Description,
+ custom,
+ remote,
+ }
+ }
+
+ output.Table(headers, rows)
+ fmt.Printf("\nTotal: %d templates\n", len(result.Data))
+ return nil
+ },
+}
+
+var allCmd = &cobra.Command{
+ Use: "all",
+ Short: "List all templates (including remote)",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.TemplatesAll())
+ if err != nil {
+ return fmt.Errorf("failed to list all templates: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[[]template.Template]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ headers := []string{"ID", "NAME", "DESCRIPTION", "CUSTOM", "REMOTE"}
+ rows := make([][]string, len(result.Data))
+ for i, tpl := range result.Data {
+ custom := "no"
+ if tpl.IsCustom {
+ custom = "yes"
+ }
+ remote := "no"
+ if tpl.IsRemote {
+ remote = "yes"
+ }
+ rows[i] = []string{
+ tpl.ID,
+ tpl.Name,
+ tpl.Description,
+ custom,
+ remote,
+ }
+ }
+
+ output.Table(headers, rows)
+ fmt.Printf("\nTotal: %d templates\n", len(result.Data))
+ return nil
+ },
+}
+
+var defaultCmd = &cobra.Command{
+ Use: "default",
+ Short: "Get default templates",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.TemplatesDefault())
+ if err != nil {
+ return fmt.Errorf("failed to get default templates: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[template.DefaultTemplatesResponse]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Default Templates")
+ output.KeyValue("Compose Template", fmt.Sprintf("%d bytes", len(result.Data.ComposeTemplate)))
+ output.KeyValue("Env Template", fmt.Sprintf("%d bytes", len(result.Data.EnvTemplate)))
+ return nil
+ },
+}
+
+var contentCmd = &cobra.Command{
+ Use: "content <template-id>",
+ Short: "Get template content",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.TemplateContent(args[0]))
+ if err != nil {
+ return fmt.Errorf("failed to get template content: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[template.TemplateContent]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Template Content")
+ output.KeyValue("Name", result.Data.Template.Name)
+ output.KeyValue("Description", result.Data.Template.Description)
+ output.KeyValue("Services", fmt.Sprintf("%d", len(result.Data.Services)))
+ output.KeyValue("Env Variables", fmt.Sprintf("%d", len(result.Data.EnvVariables)))
+ fmt.Println("\n--- Compose Content ---")
+ fmt.Println(result.Data.Content)
+ if result.Data.EnvContent != "" {
+ fmt.Println("\n--- Environment Content ---")
+ fmt.Println(result.Data.EnvContent)
+ }
+ return nil
+ },
+}
+
+var registriesCmd = &cobra.Command{
+ Use: "registries",
+ Aliases: []string{"reg"},
+ Short: "List template registries",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.TemplatesRegistries())
+ if err != nil {
+ return fmt.Errorf("failed to list registries: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[[]template.TemplateRegistry]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ headers := []string{"ID", "NAME", "URL", "ENABLED"}
+ rows := make([][]string, len(result.Data))
+ for i, reg := range result.Data {
+ enabled := "no"
+ if reg.Enabled {
+ enabled = "yes"
+ }
+ rows[i] = []string{
+ reg.ID,
+ reg.Name,
+ reg.URL,
+ enabled,
+ }
+ }
+
+ output.Table(headers, rows)
+ fmt.Printf("\nTotal: %d registries\n", len(result.Data))
+ return nil
+ },
+}
+
+var variablesCmd = &cobra.Command{
+ Use: "variables",
+ Aliases: []string{"vars"},
+ Short: "List template variables",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.TemplatesVariables())
+ if err != nil {
+ return fmt.Errorf("failed to list variables: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[[]env.Variable]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ headers := []string{"KEY", "VALUE"}
+ rows := make([][]string, len(result.Data))
+ for i, v := range result.Data {
+ rows[i] = []string{
+ v.Key,
+ v.Value,
+ }
+ }
+
+ output.Table(headers, rows)
+ fmt.Printf("\nTotal: %d variables\n", len(result.Data))
+ return nil
+ },
+}
+
+var deleteCmd = &cobra.Command{
+ Use: "delete <template-id>",
+ Aliases: []string{"rm", "remove"},
+ Short: "Delete template",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if !forceFlag {
+ fmt.Printf("Are you sure you want to delete template %s? (y/N): ", args[0])
+ var response string
+ if _, err := fmt.Scanln(&response); err != nil {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ if strings.ToLower(response) != "y" && strings.ToLower(response) != "yes" {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ }
+
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Delete(cmd.Context(), types.Endpoints.Template(args[0]))
+ if err != nil {
+ return fmt.Errorf("failed to delete template: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ output.Success("Template deleted successfully")
+ return nil
+ },
+}
+
+var deleteRegistryCmd = &cobra.Command{
+ Use: "delete-registry <registry-id>",
+ Short: "Delete template registry",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if !forceFlag {
+ fmt.Printf("Are you sure you want to delete template registry %s? (y/N): ", args[0])
+ var response string
+ if _, err := fmt.Scanln(&response); err != nil {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ if strings.ToLower(response) != "y" && strings.ToLower(response) != "yes" {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ }
+
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Delete(cmd.Context(), types.Endpoints.TemplateRegistry(args[0]))
+ if err != nil {
+ return fmt.Errorf("failed to delete registry: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ output.Success("Template registry deleted successfully")
+ return nil
+ },
+}
+
+func init() {
+ TemplatesCmd.AddCommand(listCmd)
+ TemplatesCmd.AddCommand(allCmd)
+ TemplatesCmd.AddCommand(defaultCmd)
+ TemplatesCmd.AddCommand(contentCmd)
+ TemplatesCmd.AddCommand(registriesCmd)
+ TemplatesCmd.AddCommand(variablesCmd)
+ TemplatesCmd.AddCommand(deleteCmd)
+ TemplatesCmd.AddCommand(deleteRegistryCmd)
+
+ listCmd.Flags().IntVarP(&limitFlag, "limit", "n", 20, "Number of templates to show")
+ listCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ allCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ defaultCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ contentCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ registriesCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ variablesCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ deleteCmd.Flags().BoolVarP(&forceFlag, "force", "f", false, "Force deletion without confirmation")
+ deleteCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ deleteRegistryCmd.Flags().BoolVarP(&forceFlag, "force", "f", false, "Force deletion without confirmation")
+ deleteRegistryCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+}
diff --git a/cli/pkg/updater/cmd.go b/cli/pkg/updater/cmd.go
new file mode 100644
index 000000000..3bde66d8f
--- /dev/null
+++ b/cli/pkg/updater/cmd.go
@@ -0,0 +1,156 @@
+package updater
+
+import (
+ "encoding/json"
+ "fmt"
+
+ "github.com/spf13/cobra"
+ "go.getarcane.app/cli/internal/client"
+ "go.getarcane.app/cli/internal/output"
+ "go.getarcane.app/cli/internal/types"
+ "go.getarcane.app/types/base"
+ "go.getarcane.app/types/updater"
+)
+
+var jsonOutput bool
+
+// UpdaterCmd is the parent command for updater operations
+var UpdaterCmd = &cobra.Command{
+ Use: "updater",
+ Aliases: []string{"upd"},
+ Short: "Auto-updater operations",
+}
+
+var statusCmd = &cobra.Command{
+ Use: "status",
+ Short: "Get updater status",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.UpdaterStatus(c.EnvID()))
+ if err != nil {
+ return fmt.Errorf("failed to get updater status: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[updater.Status]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Updater Status")
+ output.KeyValue("Updating Containers", fmt.Sprintf("%d", result.Data.UpdatingContainers))
+ output.KeyValue("Updating Projects", fmt.Sprintf("%d", result.Data.UpdatingProjects))
+ return nil
+ },
+}
+
+var runCmd = &cobra.Command{
+ Use: "run",
+ Short: "Run updater",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.UpdaterRun(c.EnvID()), nil)
+ if err != nil {
+ return fmt.Errorf("failed to run updater: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[updater.Result]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Updater Results")
+ output.KeyValue("Checked", fmt.Sprintf("%d", result.Data.Checked))
+ output.KeyValue("Updated", fmt.Sprintf("%d", result.Data.Updated))
+ output.KeyValue("Skipped", fmt.Sprintf("%d", result.Data.Skipped))
+ output.KeyValue("Failed", fmt.Sprintf("%d", result.Data.Failed))
+ output.KeyValue("Duration", result.Data.Duration)
+ return nil
+ },
+}
+
+var historyCmd = &cobra.Command{
+ Use: "history",
+ Short: "Get updater history",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.UpdaterHistory(c.EnvID()))
+ if err != nil {
+ return fmt.Errorf("failed to get updater history: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[[]updater.Result]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ headers := []string{"CHECKED", "UPDATED", "FAILED", "DURATION"}
+ rows := make([][]string, len(result.Data))
+ for i, h := range result.Data {
+ rows[i] = []string{
+ fmt.Sprintf("%d", h.Checked),
+ fmt.Sprintf("%d", h.Updated),
+ fmt.Sprintf("%d", h.Failed),
+ h.Duration,
+ }
+ }
+
+ output.Table(headers, rows)
+ fmt.Printf("\nTotal: %d history entries\n", len(result.Data))
+ return nil
+ },
+}
+
+func init() {
+ UpdaterCmd.AddCommand(statusCmd)
+ UpdaterCmd.AddCommand(runCmd)
+ UpdaterCmd.AddCommand(historyCmd)
+
+ statusCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ runCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ historyCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+}
diff --git a/cli/pkg/users/cmd.go b/cli/pkg/users/cmd.go
new file mode 100644
index 000000000..507c99961
--- /dev/null
+++ b/cli/pkg/users/cmd.go
@@ -0,0 +1,137 @@
+package users
+
+import (
+ "encoding/json"
+ "fmt"
+ "strings"
+
+ "github.com/spf13/cobra"
+ "go.getarcane.app/cli/internal/client"
+ "go.getarcane.app/cli/internal/output"
+ "go.getarcane.app/cli/internal/types"
+ "go.getarcane.app/types/base"
+ "go.getarcane.app/types/user"
+)
+
+var (
+ limitFlag int
+ forceFlag bool
+ jsonOutput bool
+)
+
+// UsersCmd is the parent command for user operations
+var UsersCmd = &cobra.Command{
+ Use: "users",
+ Aliases: []string{"user", "usr"},
+ Short: "Manage users",
+}
+
+var listCmd = &cobra.Command{
+ Use: "list",
+ Aliases: []string{"ls"},
+ Short: "List users",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ path := types.Endpoints.Users()
+ if limitFlag > 0 {
+ path = fmt.Sprintf("%s?limit=%d", path, limitFlag)
+ }
+
+ resp, err := c.Get(cmd.Context(), path)
+ if err != nil {
+ return fmt.Errorf("failed to list users: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.Paginated[user.User]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ headers := []string{"ID", "USERNAME", "DISPLAY NAME", "EMAIL", "ROLES"}
+ rows := make([][]string, len(result.Data))
+ for i, usr := range result.Data {
+ displayName := ""
+ if usr.DisplayName != nil {
+ displayName = *usr.DisplayName
+ }
+ email := ""
+ if usr.Email != nil {
+ email = *usr.Email
+ }
+ roles := strings.Join(usr.Roles, ", ")
+ rows[i] = []string{
+ usr.ID,
+ usr.Username,
+ displayName,
+ email,
+ roles,
+ }
+ }
+
+ output.Table(headers, rows)
+ fmt.Printf("\nTotal: %d users\n", result.Pagination.TotalItems)
+ return nil
+ },
+}
+
+var deleteCmd = &cobra.Command{
+ Use: "delete <user-id>",
+ Aliases: []string{"rm", "remove"},
+ Short: "Delete user",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if !forceFlag {
+ fmt.Printf("Are you sure you want to delete user %s? (y/N): ", args[0])
+ var response string
+ if _, err := fmt.Scanln(&response); err != nil {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ if strings.ToLower(response) != "y" && strings.ToLower(response) != "yes" {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ }
+
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Delete(cmd.Context(), types.Endpoints.User(args[0]))
+ if err != nil {
+ return fmt.Errorf("failed to delete user: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ output.Success("User deleted successfully")
+ return nil
+ },
+}
+
+func init() {
+ UsersCmd.AddCommand(listCmd)
+ UsersCmd.AddCommand(deleteCmd)
+
+ listCmd.Flags().IntVarP(&limitFlag, "limit", "n", 20, "Number of users to show")
+ listCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ deleteCmd.Flags().BoolVarP(&forceFlag, "force", "f", false, "Force deletion without confirmation")
+ deleteCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+}
diff --git a/cli/pkg/volumes/cmd.go b/cli/pkg/volumes/cmd.go
new file mode 100644
index 000000000..b20d18ee1
--- /dev/null
+++ b/cli/pkg/volumes/cmd.go
@@ -0,0 +1,311 @@
+package volumes
+
+import (
+ "encoding/json"
+ "fmt"
+ "strings"
+
+ "github.com/spf13/cobra"
+ "go.getarcane.app/cli/internal/client"
+ "go.getarcane.app/cli/internal/output"
+ "go.getarcane.app/cli/internal/types"
+ "go.getarcane.app/types/base"
+ "go.getarcane.app/types/volume"
+)
+
+var (
+ limitFlag int
+ forceFlag bool
+ jsonOutput bool
+)
+
+// VolumesCmd is the parent command for volume operations
+var VolumesCmd = &cobra.Command{
+ Use: "volumes",
+ Aliases: []string{"volume", "vol", "v"},
+ Short: "Manage volumes",
+}
+
+var listCmd = &cobra.Command{
+ Use: "list",
+ Aliases: []string{"ls"},
+ Short: "List volumes",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ path := types.Endpoints.Volumes(c.EnvID())
+ if limitFlag > 0 {
+ path = fmt.Sprintf("%s?limit=%d", path, limitFlag)
+ }
+
+ resp, err := c.Get(cmd.Context(), path)
+ if err != nil {
+ return fmt.Errorf("failed to list volumes: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.Paginated[volume.Volume]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ headers := []string{"NAME", "DRIVER", "MOUNTPOINT", "CREATED"}
+ rows := make([][]string, len(result.Data))
+ for i, vol := range result.Data {
+ rows[i] = []string{
+ vol.Name,
+ vol.Driver,
+ vol.Mountpoint,
+ vol.CreatedAt,
+ }
+ }
+
+ output.Table(headers, rows)
+ fmt.Printf("\nTotal: %d volumes\n", result.Pagination.TotalItems)
+ return nil
+ },
+}
+
+var deleteCmd = &cobra.Command{
+ Use: "delete <volume-name>",
+ Aliases: []string{"rm", "remove"},
+ Short: "Delete a volume",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if !forceFlag {
+ fmt.Printf("Are you sure you want to delete volume %s? (y/N): ", args[0])
+ var response string
+ if _, err := fmt.Scanln(&response); err != nil {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ if strings.ToLower(response) != "y" && strings.ToLower(response) != "yes" {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ }
+
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Delete(cmd.Context(), types.Endpoints.Volume(c.EnvID(), args[0]))
+ if err != nil {
+ return fmt.Errorf("failed to delete volume: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ output.Success("Volume %s deleted successfully", args[0])
+ return nil
+ },
+}
+
+var countsCmd = &cobra.Command{
+ Use: "counts",
+ Short: "Get volume usage counts",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.VolumesCounts(c.EnvID()))
+ if err != nil {
+ return fmt.Errorf("failed to get volume counts: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[interface{}]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Volume Usage Counts")
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal volume counts: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ },
+}
+
+var pruneCmd = &cobra.Command{
+ Use: "prune",
+ Short: "Remove unused volumes",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if !forceFlag {
+ fmt.Print("Are you sure you want to prune unused volumes? (y/N): ")
+ var response string
+ if _, err := fmt.Scanln(&response); err != nil {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ if strings.ToLower(response) != "y" && strings.ToLower(response) != "yes" {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ }
+
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Endpoints.VolumesPrune(c.EnvID()), nil)
+ if err != nil {
+ return fmt.Errorf("failed to prune volumes: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[interface{}]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Success("Volumes pruned successfully")
+ return nil
+ },
+}
+
+var sizesCmd = &cobra.Command{
+ Use: "sizes",
+ Short: "Get volume sizes",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.VolumesSizes(c.EnvID()))
+ if err != nil {
+ return fmt.Errorf("failed to get volume sizes: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[interface{}]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Volume Sizes")
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal volume sizes: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ },
+}
+
+var usageCmd = &cobra.Command{
+ Use: "usage <volume-name>",
+ Short: "Get specific volume usage",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := client.NewFromConfig()
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Endpoints.VolumeUsage(c.EnvID(), args[0]))
+ if err != nil {
+ return fmt.Errorf("failed to get volume usage: %w", err)
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[interface{}]
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return fmt.Errorf("failed to parse response: %w", err)
+ }
+
+ if jsonOutput {
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ }
+
+ output.Header("Volume Usage: %s", args[0])
+ resultBytes, err := json.MarshalIndent(result.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal volume usage: %w", err)
+ }
+ fmt.Println(string(resultBytes))
+ return nil
+ },
+}
+
+func init() {
+ VolumesCmd.AddCommand(listCmd)
+ VolumesCmd.AddCommand(deleteCmd)
+ VolumesCmd.AddCommand(countsCmd)
+ VolumesCmd.AddCommand(pruneCmd)
+ VolumesCmd.AddCommand(sizesCmd)
+ VolumesCmd.AddCommand(usageCmd)
+
+ // List command flags
+ listCmd.Flags().IntVarP(&limitFlag, "limit", "n", 20, "Number of volumes to show")
+ listCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Delete command flags
+ deleteCmd.Flags().BoolVarP(&forceFlag, "force", "f", false, "Force deletion without confirmation")
+ deleteCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Prune command flags
+ pruneCmd.Flags().BoolVarP(&forceFlag, "force", "f", false, "Force prune without confirmation")
+ pruneCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Other command flags
+ countsCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ sizesCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ usageCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+}
diff --git a/cliff.toml b/cliff.toml
index 9298ad829..9054b806c 100644
--- a/cliff.toml
+++ b/cliff.toml
@@ -1,6 +1,5 @@
# git-cliff ~ configuration file
# https://git-cliff.org/docs/configuration
-# originally from pocket-id
[remote.github]
owner = "getarcaneapp"
@@ -12,15 +11,27 @@ filter_unconventional = true
tag_pattern = "v[0-9]*"
commit_preprocessors = [{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" }]
commit_parsers = [
- { message = "^feat", group = "<!-- 0 --> New features" },
- { message = "^fix", group = "<!-- 1 --> Bug fixes" },
- { message = "^perf", group = "<!-- 2 --> Performance Improvements" },
- { message = "^docs", group = "<!-- 3 --> Documentation", default_scope = "other" },
- { message = "^chore\\(deps\\)", group = "<!-- 4 --> Dependencies" },
+ { message = "^feat\\(cli\\)", group = "<!-- 01 --> CLI - New features" },
+ { message = "^feat\\(types\\)", group = "<!-- 02 --> Types - New features" },
+ { message = "^feat", group = "<!-- 00 --> Backend - New features" },
+
+ { message = "^fix\\(cli\\)", group = "<!-- 11 --> CLI - Bug fixes" },
+ { message = "^fix\\(types\\)", group = "<!-- 12 --> Types - Bug fixes" },
+ { message = "^fix", group = "<!-- 10 --> Backend - Bug fixes" },
+
+ { message = "^perf\\(cli\\)", group = "<!-- 21 --> CLI - Performance improvements" },
+ { message = "^perf\\(types\\)", group = "<!-- 22 --> Types - Performance improvements" },
+ { message = "^perf", group = "<!-- 20 --> Backend - Performance improvements" },
+
+ { message = "^docs\\(cli\\)", group = "<!-- 31 --> CLI - Documentation", default_scope = "other" },
+ { message = "^docs\\(types\\)", group = "<!-- 32 --> Types - Documentation", default_scope = "other" },
+ { message = "^docs", group = "<!-- 30 --> Backend - Documentation", default_scope = "other" },
+
+ { message = "^chore\\(deps\\)", group = "<!-- 40 --> Dependencies" },
{ message = "^chore", skip = true },
{ message = "^release", skip = true },
{ message = "update translations via Crowdin", skip = true },
- { message = ".*", group = "<!-- 5 --> Other", default_scope = "other"},
+ { message = ".*", group = "<!-- 50 --> Other", default_scope = "other"},
]
filter_commits = false