$ show scaleway/scaleway-cli
This repository is the official Scaleway CLI (`scw`), a command-line tool for managing Scaleway cloud infrastructure. It provides comprehensive access to over 60 cloud services including compute (instances, baremetal, Apple Silicon), storage (block, object, file), networking (VPC, load balancers, DNS, VPN), databases (RDB, Redis, MongoDB, serverless SQL), container orchestration (Kubernetes, Container Registry, serverless functions), IAM, billing, monitoring (Cockpit/Grafana), and edge services. The tool is written in Go and built on a custom command framework (`core.Command`) that supports declarative argument specifications (`ArgSpecs`), output formatting (human-readable, JSON, YAML, Go templates), command interceptors for request/response transformation, and asynchronous wait functions for long-running operations. The CLI is deployed as a single binary, with a WebAssembly build for browser-based use and a Model Context Protocol (MCP) server that exposes commands as AI-accessible tools. Architecturally, the codebase is organized into `internal/namespaces/` where each Scaleway service has auto-generated command files (`*_cli.go`) produced from the `scaleway-sdk-go` API definitions, plus hand-written custom override files (`custom_*.go`) that augment generated commands with richer argument handling, interactive prompts, editor integration, custom marshaling, and workflow orchestration (e.g., server creation with volume/IP setup, Kubernetes kubeconfig management, container deployment with BuildKit). The core framework in `internal/core/` provides the glue: bootstrap, command tree building using Cobra, argument parsing/validation, autocomplete, config management, and testing utilities. Tests use golden files and HTTP cassette recording for deterministic integration testing. Key data flows: the CLI reads configuration from `~/.config/scw/cli.yaml` (or equivalent), authenticates via API keys or OAuth, and makes REST API calls through the Scaleway SDK. Output is formatted by the `human` package which uses Elastic Tabstops for column alignment and custom marshalers for colored status indicators. The tool supports shell mode, autocomplete, aliases, and plugin dispatching. The MCP server runs the same command definitions over stdio, converting CLI arguments to JSON-RPC parameters for AI agents. External dependencies include the Scaleway SDK, AWS SDK (for MinIO S3), Docker/BuildKit, Kubernetes client libraries, and several Go packages for terminal interaction (bubbletea, tview). The project uses GitHub Actions for CI/CD, `goreleaser` for releases, and `mise` for tool version management.
The LLM identified 3 files worth highlighting for reuse:
Provides a generic `Fetcher[L]` interface for listing cloud resources across localities (zones/regions). Includes concrete implementations like `ZoneFetcher` and `RegionFetcher`, plus a `WrapFetcher` adapter that converts a list function into a fetcher. This abstraction is used by the `scw account list-resources` command and can be reused in any project that needs to aggregate resources from multiple API endpoints with locality context. It is well-isolated (no internal imports beyond types) and demonstrates clean generics usage.
A reflection-based argument unmarshaling engine that converts CLI string arguments into Go structs. Supports scalar types, slices, maps, nested structs, and custom unmarshaler functions (e.g., `scw.Size`, `scw.IPNet`). Handles positional arguments, default values, and file loading via `@` prefix. This is a non-trivial, self-contained component that can be extracted for any Go CLI that needs advanced argument parsing beyond standard flag libraries.
Implements a custom autocomplete system that builds a tree (trie) from the command hierarchy, arguments, and their specifications. Supports completion of flags, positional arguments, enum values, file paths, and dynamic completions for resource names (e.g., server IDs) via custom functions. Handles partial flag names (`-o=jso` → `-o=json`) and argument index completion. This is a standalone, reusable engine for adding shell-style autocomplete to any CLI application built on a tree of commands.