commands

package
v1.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ProductionAuthURL is the production SpecLedger authentication URL
	ProductionAuthURL = "https://app.specledger.io/cli/auth"
	// DevAuthURL is the development authentication URL
	DevAuthURL = "http://localhost:3000/cli/auth"
	// AuthTimeout is the maximum time to wait for browser authentication
	AuthTimeout = 5 * time.Minute
)

Variables

View Source
var VarAddCmd = &cobra.Command{
	Use:   "add <repo-url> [branch] --alias <name> [--artifact-path <path>]",
	Short: "Add a dependency",
	Long: `Add an external specification dependency to your project. The dependency will be tracked in specledger.yaml and cached locally for offline use.

The --alias flag is required and will be used as the reference path when accessing artifacts from this dependency.

For SpecLedger repositories, the artifact_path will be auto-detected from the dependency's specledger.yaml. For non-SpecLedger repositories, use --artifact-path to manually specify where artifacts are located.`,
	Example: `  sl deps add git@github.com:org/api-spec --alias api
  sl deps add git@github.com:org/api-spec develop --alias api
  sl deps add https://github.com/org/api-docs --alias docs --artifact-path docs/openapi/`,
	Args: cobra.MinimumNArgs(1),
	RunE: runAddDependency,
}

VarAddCmd represents the add command

View Source
var VarAuthCmd = &cobra.Command{
	Use:   "auth",
	Short: "Manage authentication",
	Long: `Manage authentication for SpecLedger CLI.

Authentication is required for accessing protected features like
private specifications and remote synchronization.

Examples:
  sl auth login   # Sign in via browser
  sl auth logout  # Sign out and clear tokens
  sl auth status  # Check authentication status`,
}

VarAuthCmd represents the auth command group

View Source
var VarAuthLoginCmd = &cobra.Command{
	Use:   "login",
	Short: "Sign in via browser",
	Long: `Open your browser to sign in to SpecLedger.

This command will:
1. Start a temporary local server to receive authentication
2. Open your default browser to the SpecLedger sign-in page
3. Wait for you to complete authentication
4. Store your credentials securely

If the browser doesn't open automatically, you can manually navigate
to the URL shown in the terminal.`,
	RunE: runLogin,
}

VarAuthLoginCmd represents the login command

View Source
var VarAuthLogoutCmd = &cobra.Command{
	Use:   "logout",
	Short: "Sign out and clear tokens",
	Long:  `Sign out of SpecLedger and remove stored credentials.`,
	RunE:  runLogout,
}

VarAuthLogoutCmd represents the logout command

View Source
var VarAuthRefreshCmd = &cobra.Command{
	Use:   "refresh",
	Short: "Refresh access token",
	Long:  `Manually refresh the access token using the stored refresh token.`,
	RunE:  runRefresh,
}

VarAuthRefreshCmd represents the refresh command

View Source
var VarAuthStatusCmd = &cobra.Command{
	Use:   "status",
	Short: "Check authentication status",
	Long:  `Display the current authentication status and user information.`,
	RunE:  runStatus,
}

VarAuthStatusCmd represents the status command

View Source
var VarAuthSupabaseCmd = &cobra.Command{
	Use:   "supabase",
	Short: "Show Supabase configuration",
	Long:  `Display Supabase URL and anon key for API access.`,
	RunE:  runSupabase,
}

VarAuthSupabaseCmd represents the supabase config command

View Source
var VarAuthTokenCmd = &cobra.Command{
	Use:   "token",
	Short: "Print access token (for scripts)",
	Long: `Print the current access token to stdout.

This command is designed for use in scripts and automation.
It outputs only the token with no other text, making it easy
to capture in a variable:

  ACCESS_TOKEN=$(sl auth token)

The token is automatically refreshed if expired.`,
	RunE: runToken,
}

VarAuthTokenCmd represents the token command (for scripts)

View Source
var VarBootstrapCmd = &cobra.Command{
	Use:   "new",
	Short: "Create a new SpecLedger project",
	Long: `Create a new SpecLedger project with all necessary infrastructure:

Interactive mode:
  sl new

Non-interactive mode (for CI/CD):
  sl new --ci --project-name <name> --short-code <code> --project-dir <path>

The bootstrap creates:
- .claude/ directory with skills and commands
- .beads/ directory for issue tracking
- github.com/specledger/specledger/ directory for specifications
- github.com/specledger/specledger/specledger.yaml file for project metadata`,

	RunE: func(cmd *cobra.Command, args []string) error {

		cfg, err := config.Load()
		if err != nil {
			return fmt.Errorf("failed to load config: %w", err)
		}

		l := logger.New(logger.Debug)

		modeDetector := tui.NewModeDetector()
		if modeDetector.IsNonInteractive() || ciFlag {
			return runBootstrapNonInteractive(cmd, l, cfg)
		}

		return runBootstrapInteractive(l, cfg)
	},
}

VarBootstrapCmd is the bootstrap command

View Source
var VarCheckCmd = &cobra.Command{
	Use:   "check",
	Short: "Check for conflicts in the dependency graph",
	RunE:  runCheckConflicts,
}

VarCheckCmd represents the check command

View Source
var VarCleanCmd = &cobra.Command{
	Use:   "clean",
	Short: "Remove vendored dependencies",
	RunE:  runVendorClean,
}

VarCleanCmd represents the clean command

View Source
var VarConflictCmd = &cobra.Command{
	Use:   "conflict",
	Short: "Check for dependency conflicts",
	Long:  `Check the dependency graph for potential conflicts and circular dependencies.`,
}

VarConflictCmd represents the conflict command

View Source
var VarDepsCmd = &cobra.Command{
	Use:   "deps",
	Short: "Manage specification dependencies",
	Long: `Manage external specification dependencies for your project.

Dependencies are stored in github.com/specledger/specledger/specledger.yaml and cached locally for offline use.

Examples:
  sl deps list                           # List all dependencies
  sl deps add git@github.com:org/spec    # Add a dependency
  sl deps remove git@github.com:org/spec # Remove a dependency`,
}

VarDepsCmd represents the deps command

View Source
var VarDepsListCmd = &cobra.Command{
	Use:     "list",
	Short:   "List all dependencies",
	Long:    `List all declared dependencies from specledger.yaml, showing their repository, version, and resolved status.`,
	Example: `  sl deps list`,
	RunE:    runListDependencies,
}

VarDepsListCmd represents the list command

View Source
var VarDepsUpdateCmd = &cobra.Command{
	Use:   "update [repo-url]",
	Short: "Update dependencies to latest versions",
	Long:  `Update dependencies to their latest versions. If no URL is given, updates all dependencies.`,
	Example: `  sl deps update                    # Update all
  sl deps update git@github.com:org/spec # Update one`,
	RunE: runUpdateDependencies,
}

VarDepsUpdateCmd represents the update command

View Source
var VarDetectCmd = &cobra.Command{
	Use:   "detect",
	Short: "Detect potential conflicts",
	RunE:  runDetectConflicts,
}

VarDetectCmd represents the detect command

View Source
var VarDoctorCmd = &cobra.Command{
	Use:   "doctor",
	Short: "Check installation status of required and optional tools",
	Long: `Check the installation status of all tools required by SpecLedger.

This command verifies that:
- Core tools (mise, bd, perles) are installed and accessible
- Framework tools (specify, openspec) are installed (optional)

Use --json flag for machine-readable output suitable for CI/CD pipelines.`,
	Example: `  sl doctor           # Human-readable output
  sl doctor --json    # JSON output for CI/CD`,
	RunE:          runDoctor,
	SilenceUsage:  true,
	SilenceErrors: true,
}

VarDoctorCmd represents the doctor command

View Source
var VarExportCmd = &cobra.Command{
	Use:   "export --format <format> --output <file>",
	Short: "Export graph to file (coming soon)",
	Long: `Export the dependency graph to a file for visualization.

Supported formats will include: JSON, SVG, DOT (Graphviz)`,
	Example: "  sl graph export --format svg --output deps.svg",
	RunE:    runExportGraph,
}

VarExportCmd represents the export command

View Source
var VarGraphCmd = &cobra.Command{
	Use:   "graph",
	Short: "Display dependency graphs",
	Long: `Visualize dependencies and their relationships.

NOTE: This feature is coming soon. For now, use 'sl deps list' to see dependencies.`,
}

VarGraphCmd represents the graph command

View Source
var VarInitCmd = &cobra.Command{
	Use:   "init",
	Short: "Initialize SpecLedger in an existing repository",
	Long: `Initialize SpecLedger in the current repository directory.

This adds SpecLedger to an existing project without creating a new directory.

Usage:
  sl init
  sl init --short-code abc
  sl init --playbook specledger

The init creates:
- .claude/ directory with skills
- .beads/ directory for issue tracking
- github.com/specledger/specledger/ directory for specifications
- github.com/specledger/specledger/specledger.yaml file for project metadata`,
	RunE: func(cmd *cobra.Command, args []string) error {
		l := logger.New(logger.Debug)
		return runInit(l)
	},
}

VarInitCmd is the init command

View Source
var VarLinkCmd = &cobra.Command{
	Use:   "link",
	Short: "Create symlinks from cached dependencies to project artifacts directory",
	Long: `Create symlinks from cached dependencies to the project's artifacts directory, making them available for Claude Code and other tools.

This command creates symlinks from ~/.specledger/cache/<alias>/ to <project.artifact_path>/deps/<alias>/, allowing reference paths like "alias:artifact.md" to resolve to actual files.

Example:  sl deps link`,
	RunE: runLinkDependencies,
}

VarLinkCmd represents the link command

View Source
var VarListCmd = &cobra.Command{
	Use:   "list [--spec-path <path>]",
	Short: "List all external references",
	RunE:  runListReferences,
}

VarListCmd represents the list command

View Source
var VarPlaybookCmd = &cobra.Command{
	Use:   "playbook",
	Short: "Manage SDD playbooks",
	Long: `Manage embedded SDD playbooks for SpecLedger.

Playbooks contain Claude Code commands, skills, scripts, and templates
for SpecLedger projects.

Examples:
  sl playbook list              List all available playbooks
  sl playbook list --json       List playbooks in JSON format`,
}

VarPlaybookCmd represents the playbook command

View Source
var VarPlaybookListCmd = &cobra.Command{
	Use:     "list",
	Short:   "List available SDD playbooks",
	Long:    `List all available embedded SDD playbooks with their names, descriptions, frameworks, and versions.`,
	Example: `  sl playbook list`,
	RunE:    runListPlaybooks,
}

VarPlaybookListCmd represents the list command

View Source
var VarRefsCmd = &cobra.Command{
	Use:   "refs",
	Short: "Validate external specification references",
}

VarRefsCmd represents the refs command

View Source
var VarRemoveCmd = &cobra.Command{
	Use:     "remove <repo-url>",
	Short:   "Remove a dependency",
	Long:    `Remove a dependency from specledger.yaml. The local cache will be kept for future use.`,
	Example: `  sl deps remove git@github.com:org/api-spec`,
	Args:    cobra.ExactArgs(1),
	RunE:    runRemoveDependency,
}

VarRemoveCmd represents the remove command

View Source
var VarResolveCmd = &cobra.Command{
	Use:     "resolve",
	Short:   "Download and cache dependencies",
	Long:    `Download all dependencies from specledger.yaml and cache them locally at ~/.github.com/specledger/specledger/cache/.`,
	Example: `  sl deps resolve`,
	RunE:    runResolveDependencies,
}

VarResolveCmd represents the resolve command

View Source
var VarShowCmd = &cobra.Command{
	Use:   "show",
	Short: "Show dependency graph (coming soon)",
	Long: `Display the complete dependency graph with all nodes and edges.

This will show how specifications depend on each other.`,
	Example: "  sl graph show",
	RunE:    runShowGraph,
}

VarShowCmd represents the show command

View Source
var VarTransitiveCmd = &cobra.Command{
	Use:   "transitive",
	Short: "Show transitive dependencies (coming soon)",
	Long: `Show all transitive dependencies up to a specified depth.

This helps understand the full dependency tree.`,
	Example: "  sl graph transitive --depth 3",
	RunE:    runTransitiveDependencies,
}

VarTransitiveCmd represents the transitive command

View Source
var VarUnlinkCmd = &cobra.Command{
	Use:   "unlink [alias]",
	Short: "Remove symlinks for dependencies",
	Long: `Remove symlinks for dependencies from the project's artifacts directory.

If no alias is specified, removes all dependency symlinks. If an alias is specified, only removes that dependency's symlink.

Example:  sl deps unlink      # Unlink all
  sl deps unlink api    # Unlink specific dependency`,
	Args: cobra.MaximumNArgs(1),
	RunE: runUnlinkDependencies,
}

VarUnlinkCmd represents the unlink command

View Source
var VarUpdateCmd = &cobra.Command{
	Use:   "update",
	Short: "Update the SpecLedger CLI to the latest version",
	Long:  `Check for updates and upgrade the SpecLedger CLI to the latest version.`,
	RunE:  runUpdateSelf,
}

VarUpdateCmd represents the update command TODO: Implement self-update functionality

View Source
var VarValidateCmd = &cobra.Command{
	Use:   "validate [--strict] [--spec-path <path>]",
	Short: "Validate all external references in a specification",
	Long:  `Validate all external references in spec.md files against resolved dependencies.`,
	Args:  cobra.MaximumNArgs(1),
	RunE:  runValidateReferences,
}

VarValidateCmd represents the validate command

View Source
var VarVendorAllCmd = &cobra.Command{
	Use:   "vendor --output <path>",
	Short: "Copy all dependencies to vendor directory",
	Long:  `Copy all external dependencies to the local vendor directory for offline use.`,
	Args:  cobra.MaximumNArgs(1),
	RunE:  runVendorAll,
}

VarVendorAllCmd represents the vendor all command

View Source
var VarVendorCmd = &cobra.Command{
	Use:   "vendor",
	Short: "Vendor dependencies for offline use",
}

VarVendorCmd represents the vendor command

View Source
var VarVendorUpdateCmd = &cobra.Command{
	Use:   "update [--vendor-path <path>] [--force]",
	Short: "Update vendored dependencies",
	RunE:  runVendorUpdate,
}

VarVendorUpdateCmd represents the vendor update command

Functions

func ExitWithCode

func ExitWithCode(code int, err error)

ExitWithCode prints error message and exits with specific code

func ExitWithError

func ExitWithError(err error)

ExitWithError prints error message and exits

func ListVendorSpecs

func ListVendorSpecs(vendorPath string) ([]string, error)

ListVendorSpecs lists all vendored specs

func PrintSuccess

func PrintSuccess(title string, details ...string)

PrintSuccess prints success message

Types

type CLIError

type CLIError struct {
	Title       string
	Description string
	Suggestions []string
	ExitCode    int
}

CLIError represents a CLI error with actionable suggestions

func ErrCIRequired

func ErrCIRequired() *CLIError

ErrCIRequired indicates TUI is required in non-interactive environment

func ErrCommandNotFound

func ErrCommandNotFound(command string) *CLIError

ErrCommandNotFound indicates an invalid command

func ErrInvalidInput

func ErrInvalidInput(message string) *CLIError

ErrInvalidInput indicates invalid input

func ErrMissingDependency

func ErrMissingDependency(name string, installCmd string) *CLIError

ErrMissingDependency indicates a required dependency is not installed

func ErrNotAProject

func ErrNotAProject() *CLIError

ErrNotAProject indicates the current directory is not a SpecLedger project

func ErrPermissionDenied

func ErrPermissionDenied(path string) *CLIError

ErrPermissionDenied indicates permission error

func ErrProjectExists

func ErrProjectExists(projectName string) *CLIError

ErrProjectExists indicates the project directory already exists

func NewCLIError

func NewCLIError(title, description string, suggestions []string, exitCode int) *CLIError

NewCLIError creates a new CLI error with suggestions

func (*CLIError) Error

func (e *CLIError) Error() string

Error returns the error message

type DoctorOutput

type DoctorOutput struct {
	Status              string             `json:"status"`
	Tools               []DoctorToolStatus `json:"tools"`
	Missing             []string           `json:"missing,omitempty"`
	InstallInstructions string             `json:"install_instructions,omitempty"`
}

DoctorOutput represents the JSON output structure for doctor command

type DoctorToolStatus

type DoctorToolStatus struct {
	Name      string `json:"name"`
	Installed bool   `json:"installed"`
	Version   string `json:"version,omitempty"`
	Path      string `json:"path,omitempty"`
	Category  string `json:"category"`
}

DoctorToolStatus represents a tool's status in JSON output

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL