commands

package
v1.12.2-0...-eb60e09 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 70 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppCmd

func AppCmd() *cobra.Command

AppCmd returns the `vip app` parent command. Subcommands and the wildcard dispatcher are wired in main.go (so the wildcard sees the final subcommand list).

--format is registered on the parent because `vip app <name>` dispatches via WithWildcardCommand — cobra parses flags against the matched command (appCmd), so the parent must own --format for RunAppGet to read it.

func AppDeployCmd

func AppDeployCmd() *cobra.Command

AppDeployCmd returns `vip app deploy <file>`.

Node parity: src/bin/vip-app-deploy.ts. Custom Deployment authenticates with WPVIP_DEPLOY_TOKEN — never the keychain token — for both the access-validation and start-deploy mutations (custom-deploy.ts:56, vip-app-deploy.ts:216). No appctx resolution: --app/--env raw values go straight into ValidateCustomDeployAccess.

func AppDeployValidateCmd

func AppDeployValidateCmd() *cobra.Command

AppDeployValidateCmd returns `vip app deploy validate <file>`.

Node parity: src/bin/vip-app-deploy-validate.ts. Local-only: file gates + archive-structure validation, no network and no deploy token.

func AppGetCmd

func AppGetCmd() *cobra.Command

AppGetCmd is a non-registered cobra command that exists to document the `vip app <name>` form. Its execution path runs through appctx.WithWildcardCommand on the `vip app` parent (wired in root.go), not through the cobra dispatch tree. We keep this factory so help text + the --format flag are bound somewhere accessible for unit tests; production `--format` lives on the appCmd parent (see AppCmd).

func AppListCmd

func AppListCmd() *cobra.Command

AppListCmd returns the `vip app list` command.

Wraps the genqlient AppList query. Empty results and fetch errors both print to stdout and exit 0 to match Node's vip-app-list.js behavior (see Automattic/vip-cli src/bin/vip-app-list.js).

func BackupCmd

func BackupCmd() *cobra.Command

BackupCmd returns the `vip backup` parent. Children attach in root.go; the parent itself just prints help (Node: src/bin/vip-backup.ts).

func BackupDBCmd

func BackupDBCmd() *cobra.Command

BackupDBCmd returns `vip backup db`.

Node parity: src/bin/vip-backup-db.ts + src/commands/backup-db.ts. Triggers a database backup (unless one is already running) and polls the db_backup job until its in-progress lock clears.

func CacheCmd

func CacheCmd() *cobra.Command

CacheCmd returns the `vip cache` parent. Subcommands are attached in root.go; the parent itself just prints help.

func CachePurgeURLCmd

func CachePurgeURLCmd() *cobra.Command

CachePurgeURLCmd returns `vip cache purge-url [URLs...]`.

Node parity: src/bin/vip-cache-purge-url.js. Variadic positional URLs OR --from-file=<path>; --from-file fully REPLACES positional args when set (after readFromFile().trim(), Node does `urls = value.split('\n').map(...)`, overwriting whatever positional `urls` came in). No prompt — cache purge is a benign no-op when targeting URLs that aren't currently cached.

func ConfigCmd

func ConfigCmd() *cobra.Command

ConfigCmd returns the `vip config` parent. Subcommands (currently just `envvar`) are attached in root.go so the test harness can opt into the subtree it needs without dragging the others.

func ConfigEnvvarCmd

func ConfigEnvvarCmd() *cobra.Command

ConfigEnvvarCmd returns the `vip config envvar` parent. Leaf commands list / get / get-all attach in root.go.

func ConfigEnvvarDeleteCmd

func ConfigEnvvarDeleteCmd() *cobra.Command

ConfigEnvvarDeleteCmd returns `vip config envvar delete <VARIABLE_NAME>`.

Mutation wrapper around deleteEnvironmentVariable. Interactive flow when --skip-confirmation is absent (Node parity, src/bin/vip-config-envvar-delete.js):

  1. Production prod-gate: confirms against env name + app name (only on prod).
  2. ValidateName: rejects malformed names with the Node-parity error text.
  3. Text input: user must type the variable name exactly ("Type FOO to confirm deletion:").
  4. Yes/no: "Are you sure? Deletion is permanent" (red+bold).
  5. promptForReloadManifest: "Apply this environment variable update now?".

All interactive gates short-circuit to no-op under --skip-confirmation OR VIP_NON_INTERACTIVE=1 (parity scenarios use one or the other). Decline at any gate prints a Node-parity cancel line to stdout + exits 0; the mutation does not fire.

func ConfigEnvvarGetAllCmd

func ConfigEnvvarGetAllCmd() *cobra.Command

ConfigEnvvarGetAllCmd returns `vip config envvar get-all`. Wraps the GetEnvironmentVariablesWithValues genqlient query. Empty results print the Node-parity yellow stdout message + exit 0. Column order matches Node's formatData output: <key>, value.

func ConfigEnvvarGetCmd

func ConfigEnvvarGetCmd() *cobra.Command

ConfigEnvvarGetCmd returns `vip config envvar get <VARIABLE_NAME>`.

Single-name fetch is implemented client-side (envvar.Get filters the get-all result) because the schema exposes no per-name query — see envvar/envvar.go. Node parity: src/bin/vip-config-envvar-get.js uppercases the argument and prints a yellow not-found stdout message + exit 0 when the variable is missing.

func ConfigEnvvarListCmd

func ConfigEnvvarListCmd() *cobra.Command

ConfigEnvvarListCmd returns `vip config envvar list`. Wraps the GetEnvironmentVariables genqlient query. Empty results print Node's "There are no environment variables" yellow message and exit 0; the key column varies by format (name | key | id) to match Node parity.

func ConfigEnvvarSetCmd

func ConfigEnvvarSetCmd() *cobra.Command

ConfigEnvvarSetCmd returns `vip config envvar set <VARIABLE_NAME>`.

Mutation wrapper around addEnvironmentVariable (server-side upsert). Production confirms inline because the prompt message interpolates the variable name + app name dynamically.

Deferred (interactive-only) behavior — see commit message:

  • promptForReloadManifest after the mutation succeeds.
  • Value-echo confirmation when --from-file is used.

Both are bypassed when --skip-confirmation is set or VIP_NON_INTERACTIVE=1, which covers the parity scenarios in M6.

func ConfigSoftwareCmd

func ConfigSoftwareCmd() *cobra.Command

ConfigSoftwareCmd returns the `vip config software` parent. Subcommands (`get` now, `update` in Task 7) are attached here.

func ConfigSoftwareGetCmd

func ConfigSoftwareGetCmd() *cobra.Command

ConfigSoftwareGetCmd returns the `vip config software get` leaf command.

func ConfigSoftwareUpdateCmd

func ConfigSoftwareUpdateCmd() *cobra.Command

ConfigSoftwareUpdateCmd returns the `vip config software update` leaf command.

func DBCmd

func DBCmd() *cobra.Command

DBCmd returns the `vip db` parent. Leaf subcommands attach in root.go; the parent itself does nothing on its own (cobra prints help by default).

func DBPhpmyadminCmd

func DBPhpmyadminCmd() *cobra.Command

DBPhpmyadminCmd returns `vip db phpmyadmin`. Node parity: src/bin/vip-db-phpmyadmin.ts + src/commands/phpmyadmin.ts. The actual three-op enable+poll+generate flow lives in internal/phpmyadmin; this command just resolves --print / --silent and dispatches.

func DevEnvCmd

func DevEnvCmd() *cobra.Command

DevEnvCmd returns the real `vip dev-env` command tree (23 leaves). dev-env is auth-bypassed EXCEPT `sync` (which calls the VIP platform — see internal/auth/bypass.go).

func ExportCmd

func ExportCmd() *cobra.Command

ExportCmd returns the `vip export` parent. Children attach in root.go; the parent itself just prints help (Node: src/bin/vip-export.js).

func ExportSQLCmd

func ExportSQLCmd() *cobra.Command

ExportSQLCmd returns `vip export sql`.

Node parity: src/bin/vip-export-sql.js + src/commands/export-sql.ts. Full exports ride the latest db_backup (optionally regenerating it); the --table/--site-id/--wpcli-command/--config-file options switch to the live-backup-copy (partial export) flow.

func ImportCmd

func ImportCmd() *cobra.Command

ImportCmd returns the `vip import` parent. Children attach in root.go; the parent itself just prints help.

M6b adds validate-sql; later milestones will add sql + media + the file validators.

func ImportMediaAbortCmd

func ImportMediaAbortCmd() *cobra.Command

ImportMediaAbortCmd returns `vip import media abort`.

Node parity: src/bin/vip-import-media-abort.js. requireConfirm gates the mutation; GraphQL errors print and exit 0 (js:103-108).

func ImportMediaCmd

func ImportMediaCmd() *cobra.Command

ImportMediaCmd returns `vip import media <file|url>`.

Node parity: src/bin/vip-import-media.js. URL or local archive (.tar.gz/.tgz/.zip); local archives upload via internal/upload and the platform fetches the resulting presigned GetObject URL. Invalid input prints a red error block and exits 0 (js:158-176).

func ImportMediaStatusCmd

func ImportMediaStatusCmd() *cobra.Command

ImportMediaStatusCmd returns `vip import media status`.

Node parity: src/bin/vip-import-media-status.js. saveErrorLog defaults to "prompt" here (js:55) — unlike the main import command where it defaults empty.

func ImportSQLCmd

func ImportSQLCmd() *cobra.Command

ImportSQLCmd returns `vip import sql <file|url>`.

Node parity: src/bin/vip-import-sql.js (852 LOC). Flow: gates → (local) SQL validation → playbook → type-the-domain confirm → optional skip-backup double confirm → optional in-place confirm → progress phase (search-replace, upload / URL passthrough, StartImport mutation) → status polling (internal/siteimport).

func ImportSQLStatusCmd

func ImportSQLStatusCmd() *cobra.Command

ImportSQLStatusCmd returns `vip import sql status`.

Node parity: src/bin/vip-import-sql-status.js (73 LOC). Re-enters the shared status poller with ReturnMissingJobImmediately=true so a quiet environment reports "No import job found" instead of polling forever.

func ImportValidateFilesCmd

func ImportValidateFilesCmd() *cobra.Command

ImportValidateFilesCmd returns `vip import validate-files <folder>`.

Node parity: src/bin/vip-import-validate-files.js. Always exits 0 — findings are informational. Needs GraphQL only for the validation config (mediaImportConfig); no app/env context.

func ImportValidateSQLCmd

func ImportValidateSQLCmd() *cobra.Command

ImportValidateSQLCmd returns `vip import validate-sql <FILE>`.

Node parity: src/bin/vip-import-validate-sql.js (24 lines) → src/lib/validations/sql.ts validate(). Local-only: no GraphQL, no appctx middleware. validate() runs with isImport=false and skipChecks=DEV_ENV_SPECIFIC_CHECKS (useStatement + siteHomeUrlLando), matching what we register in internal/sqlvalidation.

func LoginCmd

func LoginCmd() *cobra.Command

LoginCmd returns `vip login`. Node parity: src/bin/vip.js runLoginFlow (the flow lives in internal/auth/login.go and is already tested). login is on the auth-bypass list, so it builds its own Store + tracker.

func LogoutCmd

func LogoutCmd() *cobra.Command

LogoutCmd returns `vip logout`. logout is on the auth-bypass list, so it loads and purges vip-next's token itself. Server-side invalidation is best-effort and never uses the read-only Node-token fallback; local purge and elevated-cache clear always run.

func LogsCmd

func LogsCmd() *cobra.Command

LogsCmd returns `vip logs`. Wraps logsapi.RecentLogs for one-shot fetches and threads --follow through internal/polling.Loop (server-hinted backoff with min/max clamping). Node parity:

  • "Invalid type/limit/format" error wording matches src/bin/vip-logs.js.
  • Empty result prints "No logs found" to stderr + exit 0.
  • Tab characters in messages are replaced with 4 spaces for table format output (Node's printLogs: message.replace(/\t/g, ' ')).

func NewDefensiveModeCmd

func NewDefensiveModeCmd() *cobra.Command

NewDefensiveModeCmd returns the `defensive-mode` parent with all three subcommands attached. M4: root's --app/--env flags (alias-aware) replace the M3 numeric ID placeholders; WithAppContext + WithEnvContext middleware resolve them into the cmd.Context() AppEnv via GraphQL.

func NewEdgeWorkersCmd

func NewEdgeWorkersCmd() *cobra.Command

func NewUpdateCmd

func NewUpdateCmd(runner UpdateRunner) *cobra.Command

func NewWhoamiCmd

func NewWhoamiCmd() *cobra.Command

NewWhoamiCmd returns a cobra.Command that wraps RunWhoami.

func ResolveLocalSlug

func ResolveLocalSlug(cmd *cobra.Command) (string, error)

ResolveLocalSlug is ResolveSlug without the @app.env guard, for the one dev-env leaf where an alias is meaningful: `dev-env sync sql` uses @app.env to name the PLATFORM environment it exports from, and resolves the LOCAL target separately. Node models this by destructuring app/env out of the options before calling getEnvironmentName (vip-dev-env-sync-sql.js:98).

func ResolveSlug

func ResolveSlug(cmd *cobra.Command) (string, error)

ResolveSlug determines which EXISTING environment a command targets, matching the Node getEnvironmentName resolution order (dev-environment-cli.ts:146-192):

  1. --slug, if set (lowercased by Node's processSlug — dev-environment-cli.ts:979 — which every dev-env bin registers as the option's parse function).
  2. An @app.env alias: REJECTED with Node's message. allowAppEnv is set by `dev-env create` alone (vip-dev-env-create.js:95); every other dev-env command refuses it rather than guessing a local environment — this is a guard on destructive commands, so it must fire before anything else.
  3. The slug from a discovered .wpvip/vip-dev-env.yml, announced with Node's "Using environment X from Y" line.
  4. The sole environment, when exactly one exists.
  5. Interactive: prompt to select from the existing environments.
  6. Otherwise: a clear "specify --slug" error (wrapping ErrNonInteractive).

Steps 5 and 6 are vip-next's replacement for Node's "More than one environment found" error / DEFAULT_SLUG fallback.

func RunAppGet

func RunAppGet(cmd *cobra.Command, args []string) error

RunAppGet is the wildcard dispatcher target. Wired by root.go via appctx.WithWildcardCommand(appCmd, commands.RunAppGet).

Behaviorally mirrors Node's vip-app.js: not-found and fetch-error paths print to stdout and exit 0; numeric arg → app(id:); non-numeric → apps(name:).

func RunWhoami

func RunWhoami(deps WhoamiDeps) error

func SearchReplaceCmd

func SearchReplaceCmd() *cobra.Command

SearchReplaceCmd returns `vip search-replace <file>`. Node parity: src/bin/vip-search-replace.js. Reuses internal/searchreplace.Run (built for import sql). Unlike the import path, standalone defaults output to STDOUT.

func SetConfig

func SetConfig(c Config)

SetConfig stores runtime config (called by main.go after token validation, or by tests). See the pkgConfig comment re: t.Parallel().

func SetWPYes

func SetWPYes(v bool)

SetWPYes records the extracted --yes flag. Called by main.go.

func SlowlogsCmd

func SlowlogsCmd() *cobra.Command

SlowlogsCmd returns `vip slowlogs`. Mirrors LogsCmd's shape — same 1..5000 limit ceiling — with the slowlog row schema (timestamp, rowsSent, rowsExamined, queryTime, requestUri, query), and no `text` format (Node parity — vip-slowlogs.ts uses formatData only).

Note: Node's vip-slowlogs.ts declares `followLogs` but does not expose a `--follow` flag. We add it as a Go-side extension because the polling primitive is the same as `vip logs` and there's no downside to surfacing it — `getRecentSlowlogs` already accepts an `after` cursor in the Node lib.

func SyncCmd

func SyncCmd() *cobra.Command

SyncCmd returns `vip sync`.

Node parity: src/bin/vip-sync.js. Production targets are rejected by WithChildEnvContext; --skip-confirmation (or a "yes" at the "Are you sure..." prompt) is required before the mutation fires.

Rendering split:

  • TTY stderr: in-place frame rendering via internal/tui.MultiLineRenderer with a Node-parity braille spinner advanced on a background ticker. See sync_render.go for the renderer + spinner glue.
  • Non-TTY (CI, pipes, parity scenarios): one per-transition stdout line, unchanged from the pre-spinner behavior so the M6 parity scenarios keep passing without modification.

VIP_SYNC_INTERVAL_MS overrides the 5s default poll interval. Used by the parity scenarios to keep the test wall-clock under a second.

func WPCmd

func WPCmd() *cobra.Command

WPCmd returns `vip wp [args...]`.

Node parity: src/bin/vip-wp.js. DisableFlagParsing so WP-CLI flags pass through; main.go's normalizeWPArgs handles the `--`/`--yes` reshaping.

Types

type Config

type Config struct {
	APIHost string
	Token   string
	// Middleware is the ordered (outermost first) gql.Middleware stack that
	// handlers should attach to gql.Client instances. Wired by main.go.
	// Per the M3 contract: error → rechallenge → retry → transport.
	Middleware []gql.Middleware

	// M4 additions:
	// GQLClient is the genqlient client wrapped around the same middleware
	// chain (via gql.HTTPClientWithMiddleware). Handlers and appctx
	// middleware share this single client.
	GQLClient graphql.Client
	// Tracker emits telemetry events. Never nil in production — main.go
	// constructs telemetry.NewDefault(), which returns a disabled tracker
	// rather than nil when DO_NOT_TRACK / test env signals opt-out.
	Tracker *telemetry.Tracker
	// AppCtxConfig is consumed by appctx.WithAppContext to resolve --app
	// against the GraphQL API.
	AppCtxConfig appctx.AppContextConfig
}

Config holds runtime values that main.go injects before cobra dispatches.

func GetConfig

func GetConfig() Config

GetConfig returns the currently stored runtime config.

type UpdateRunner

type UpdateRunner interface {
	Run(context.Context, update.Request, func(update.Step)) (update.Outcome, error)
}

type WhoamiDeps

type WhoamiDeps struct {
	// Context carries invocation-scoped diagnostics and cancellation. Nil uses
	// context.Background for callers predating command context propagation.
	Context context.Context
	APIHost string
	Token   string
	Client  *gql.Client
	Stdout  io.Writer
}

Jump to

Keyboard shortcuts

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