commands

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 96 Imported by: 0

Documentation

Overview

S9.T03 — `nself backup drill` cobra wiring.

This file adds a single subcommand under the existing `backupCmd` parent (defined in backup_ops.go). The command is intentionally thin — all orchestration lives in internal/backup.Drill so the same logic powers the scripts/dr-drill.sh weekly cron + future Admin UI buttons.

Package commands: controller + project subcommands for B46 multi-tenant master controller.

CLI surface:

nself controller start | stop | status | init
nself project create --slug <slug> --domain <domain>
nself project delete --slug <slug> [--force]
nself project list
nself project status --slug <slug>
nself project migrate --slug <slug>
nself project shell --slug <slug>
nself project rotate-credentials --slug <slug>

Feature flag: NSELF_FLAG_MULTI_TENANT_CONTROLLER must be true. When OFF, all commands print 503 Multi-tenant controller not enabled.

Package commands implements CLI commands for the nSelf binary. This file adds 'nself deploy web' which builds Vercel/web apps locally and deploys the prebuilt output — eliminating Vercel Build CPU charges (~$43/mo).

Why prebuilt: 'vercel deploy --prebuilt' skips remote build compute entirely; Vercel just serves the already-built .vercel/output directory. Local or ops-box builds are free; Vercel Build CPU is not.

Usage:

nself deploy web [app…]          # build+deploy all apps (or listed subset)
nself deploy web --prod          # promote to production
nself deploy web nchat org       # subset by name
nself deploy web --dry-run       # print commands without running
nself deploy web --token=<tok>   # explicit Vercel token (else VERCEL_TOKEN)

P88 Sprint 05: `nself doctor --ai` first-run wizard. Tickets: T-05-01 (wizard), T-05-02 (headless), T-05-03 (idempotency).

Package commands — security.go

`nself security` provides server-level security operations: audit, setup, and status. These commands inspect the host environment (firewall, fail2ban, SSH config) and the running stack for common hardening gaps. They are intentionally non-destructive by default — `setup` requires `--apply` to make changes, otherwise it prints what would be done.

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "nself",
	Short: "nSelf CLI - Serverless hosting, anywhere",
	Long: `nSelf CLI empowers you to deploy a fully-featured, production-ready
backend to any hosting provider with absolute simplicity.

The Golden Path:
  nself init    # Generate your pristine .env configuration
  nself build   # Compose your infrastructure
  nself start   # Boot your stack`,

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

	SilenceUsage:  true,
	SilenceErrors: true,
}

RootCmd represents the base command when called without any subcommands

Functions

func ApplyCommandGroups added in v1.3.0

func ApplyCommandGroups()

ApplyCommandGroups registers the groups and assigns each command to one. Called from Execute() rather than init(): every command's own init() must have run and registered it on RootCmd before assignments can be applied, and init() ordering within a package is by filename, which is not something to depend on.

Exported so the doc generators in tools/ produce the same grouping the binary shows; they walk RootCmd directly and never call Execute. Idempotent — safe to call more than once.

func Execute

func Execute() error

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main().

func RegisterControllerCommands added in v1.0.12

func RegisterControllerCommands(root *cobra.Command)

RegisterControllerCommands attaches controller + project commands to the root command.

func ResolveLegacyDeployHost added in v1.2.1

func ResolveLegacyDeployHost(target string) (string, bool)

ResolveLegacyDeployHost returns the NSELF_DEPLOY_HOST_<TARGET> (or legacy <TARGET>_DEPLOY_HOST) value for target, mirroring the lookup already used by runDeploy's remote push path.

Types

type AdminConnection added in v1.0.6

type AdminConnection struct {
	Name       string `json:"name"`
	Host       string `json:"host"`
	User       string `json:"user"`
	Port       int    `json:"port"`
	LocalPort  int    `json:"local_port"`
	RemotePort int    `json:"remote_port"`
}

AdminConnection represents a saved remote admin connection.

type AdminProject added in v1.0.6

type AdminProject struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	Path    string `json:"path"`
	Host    string `json:"host"`
	SSHUser string `json:"ssh_user"`
	URL     string `json:"url"`
}

AdminProject represents a project in the multi-project config.

type BackupListResult added in v1.3.0

type BackupListResult struct {
	Backups []backup.BackupEntry `json:"backups"`
}

BackupListResult wraps backup.List's slice.

type Bundle added in v1.1.0

type Bundle struct {
	Name        string
	Price       string
	Description string
	Plugins     []string
}

Bundle describes a canonical nSelf plugin bundle.

type ConfigGetResult added in v1.3.0

type ConfigGetResult struct {
	Key      string `json:"key"`
	Value    string `json:"value"`
	Redacted bool   `json:"redacted"`
}

ConfigGetResult is the structured output of the nself_config_get tool.

type ConfigSetResult added in v1.3.0

type ConfigSetResult struct {
	Key     string `json:"key"`
	File    string `json:"file"`
	Created bool   `json:"created"`
}

ConfigSetResult is the structured output of the nself_config_set tool.

type ConfigShowResult added in v1.3.0

type ConfigShowResult struct {
	EnvFile string            `json:"env_file"`
	Values  map[string]string `json:"values"`
}

ConfigShowResult is the structured output of the nself_config_show tool.

type DeployServerInfo added in v1.3.0

type DeployServerInfo struct {
	Env    string `json:"env"`
	Server string `json:"server"`
	Role   string `json:"role"`
	Host   string `json:"host,omitempty"`
}

DeployServerInfo is one entry from the control-plane inventory.

type DeployStatusResult added in v1.3.0

type DeployStatusResult struct {
	LocalState string             `json:"local_state"`
	Servers    []DeployServerInfo `json:"servers,omitempty"`
	Note       string             `json:"note"`
}

DeployStatusResult is the structured output of the nself_deploy_status tool.

type DoctorResult added in v1.3.0

type DoctorResult struct {
	Checks []doctor.CheckResult `json:"checks"`
}

DoctorResult wraps doctor.DeepChecks' slice in a top-level object, since the MCP output-schema contract requires an object at the root.

type EnvListResult added in v1.3.0

type EnvListResult struct {
	Envs []env.EnvInfo `json:"envs"`
}

EnvListResult wraps env.List's slice. Only names + active flag + file path are exposed — no values, so there is nothing here that needs redaction.

type ExecResult added in v1.3.0

type ExecResult struct {
	Command string `json:"command"`
	Output  string `json:"output"`
	Success bool   `json:"success"`
}

ExecResult is the structured output of every re-exec'd lifecycle tool (build/start/stop/restart).

type FunctionInfo added in v1.0.11

type FunctionInfo struct {
	Name   string `json:"name"`
	Status string `json:"status"`
	URL    string `json:"url"`
	Dir    string `json:"dir"`
}

FunctionInfo describes a deployed function.

type LogSummary

type LogSummary struct {
	Service    string
	TotalLines int
	ErrorCount int
	WarnCount  int
	TopErrors  []string // up to 5 most frequent error messages (deduped)
	LastLine   string
}

LogSummary holds per-service log analysis results.

func CollectLogSummary

func CollectLogSummary(ctx context.Context, workdir string, service string, maxLines int) (*LogSummary, error)

CollectLogSummary fetches and analyses recent logs for a single service.

type LogVolume

type LogVolume struct {
	Service     string
	LinesPerMin float64
	BytesPerMin float64
	ErrorRate   float64 // errors / total lines in sample window
}

LogVolume holds per-service log volume sample data.

func SampleLogVolume

func SampleLogVolume(ctx context.Context, workdir string, service string, sampleDuration time.Duration) (*LogVolume, error)

SampleLogVolume samples docker logs for a service over sampleDuration and computes volume metrics.

type LogsOptions

type LogsOptions struct {
	Search  string
	Grep    string // regex pattern for --grep
	Errors  bool
	Level   string // debug|info|warn|error
	Compact bool
	Quiet   bool
	Tail    int
	Follow  bool
	Since   string // relative (1h, 30m) or absolute RFC3339
	Until   string // relative or absolute RFC3339
	JSON    bool   // structured JSON output per line
	NoColor bool
	Plain   bool // disable highlighting for piping
	Service []string
}

LogsOptions holds parsed flag values for log filtering and formatting.

type LogsResult added in v1.3.0

type LogsResult struct {
	Service string `json:"service,omitempty"`
	Lines   int    `json:"lines"`
	Output  string `json:"output"`
}

LogsResult is the structured output of the nself_logs tool.

type MigrateStatusResult added in v1.3.0

type MigrateStatusResult struct {
	Migrations []MigrationStatusEntry `json:"migrations"`
}

MigrateStatusResult wraps the migration status slice.

type MigrationStatusEntry added in v1.3.0

type MigrationStatusEntry struct {
	Name      string    `json:"name"`
	Applied   bool      `json:"applied"`
	AppliedAt time.Time `json:"applied_at,omitempty"`
}

MigrationStatusEntry mirrors database.MigrationStatus with JSON tags — that type has none, since it's only ever printed as a table today.

type PluginInstallResult added in v1.3.0

type PluginInstallResult struct {
	Name      string `json:"name"`
	Installed bool   `json:"installed"`
	Message   string `json:"message,omitempty"`
}

PluginInstallResult is the structured output of the nself_plugin_install tool.

type PluginListEntry added in v1.3.0

type PluginListEntry struct {
	Name          string `json:"name"`
	Version       string `json:"version,omitempty"`
	Category      string `json:"category,omitempty"`
	Installed     bool   `json:"installed"`
	Running       bool   `json:"running"`
	PublishStatus string `json:"publish_status,omitempty"`
}

PluginListEntry mirrors plugin.PluginInfo with JSON tags.

type PluginListResult added in v1.3.0

type PluginListResult struct {
	Plugins []PluginListEntry `json:"plugins"`
}

PluginListResult wraps the plugin list slice.

type ServiceListResult added in v1.3.0

type ServiceListResult struct {
	Services []service.PSEntry `json:"services"`
}

ServiceListResult wraps service.PS's slice in a top-level object.

Source Files

Jump to

Keyboard shortcuts

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