cli

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package cli is the complete command surface shared by every store CLI built on vtexkit. A store binary is a descriptor plus a call to Main.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main(app App)

Main parses arguments, runs the selected command, and exits with a stable code. It never returns.

Types

type AgentCmd

type AgentCmd struct {
	ExitCodes ExitCodesCmd `cmd:"" name:"exit-codes" help:"Print the exit code reference."`
}

Deprecated alias kept so `zonasul agent exit-codes` from v0.5.0 keeps working.

type App

type App struct {
	Store       store.Store
	Version     string
	Description string
}

App is what a store binary supplies.

type AuthCmd

type AuthCmd struct {
	Login  AuthLoginCmd  `cmd:"" help:"Log in with email and password, or a raw JWT."`
	Code   AuthCodeCmd   `cmd:"" help:"Log in with an emailed access code."`
	Status AuthStatusCmd `cmd:"" default:"withargs" help:"Show authentication state."`
	Logout AuthLogoutCmd `cmd:"" help:"Clear stored credentials."`
}

type AuthCodeCmd

type AuthCodeCmd struct {
	Send   AuthCodeSendCmd   `cmd:"" help:"Email a one-time access code."`
	Verify AuthCodeVerifyCmd `cmd:"" help:"Exchange the emailed code for a session."`
}

type AuthCodeSendCmd

type AuthCodeSendCmd struct {
	Email string `help:"Account email." required:""`
}

func (*AuthCodeSendCmd) Run

func (c *AuthCodeSendCmd) Run(g *Globals) error

type AuthCodeVerifyCmd

type AuthCodeVerifyCmd struct {
	Code  string `help:"The code from the email." required:""`
	Email string `help:"Override the email the code was sent to."`
}

func (*AuthCodeVerifyCmd) Run

func (c *AuthCodeVerifyCmd) Run(g *Globals) error

type AuthLoginCmd

type AuthLoginCmd struct {
	Email    string `help:"Account email."`
	Password string `help:"Account password."`
	Token    string `help:"Paste a JWT directly instead of logging in."`
}

func (*AuthLoginCmd) Run

func (c *AuthLoginCmd) Run(g *Globals) error

type AuthLogoutCmd

type AuthLogoutCmd struct{}

func (*AuthLogoutCmd) Run

func (c *AuthLogoutCmd) Run(g *Globals) error

type AuthStatusCmd

type AuthStatusCmd struct{}

func (*AuthStatusCmd) Run

func (c *AuthStatusCmd) Run(g *Globals) error

type CLI

type CLI struct {
	JSON        bool             `short:"j" help:"Output JSON for agent consumption."`
	Plain       bool             `short:"p" help:"Output tab-separated values for piping."`
	Quiet       bool             `short:"q" help:"Output bare values only."`
	ResultsOnly bool             `help:"Strip the metadata envelope, output just the data."`
	Select      string           `help:"Comma-separated fields to keep, e.g. sku,name,price. Dot paths supported." placeholder:"FIELDS"`
	Fields      string           `help:"Alias for --select." hidden:""`
	NoInput     bool             `help:"Never prompt; fail instead."`
	Version     kong.VersionFlag `help:"Print version and exit."`

	Auth      AuthCmd      `cmd:"" help:"Authentication."`
	Search    SearchCmd    `cmd:"" help:"Search products."`
	Product   ProductCmd   `cmd:"" help:"Look up a product by SKU."`
	Cart      CartCmd      `cmd:"" help:"Manage the shopping cart."`
	List      ListCmd      `cmd:"" help:"Manage local SKU lists you can order wholesale."`
	Fav       FavCmd       `cmd:"" help:"Manage the store's wishlist."`
	Delivery  DeliveryCmd  `cmd:"" help:"Delivery windows and simulation."`
	Checkout  CheckoutCmd  `cmd:"" help:"Preview or place an order."`
	Orders    OrdersCmd    `cmd:"" help:"List recent orders."`
	Store     StoreCmd     `cmd:"" help:"Store descriptor and live capabilities."`
	Doctor    DoctorCmd    `cmd:"" help:"Check whether ordering will work, and what to fix."`
	Schema    SchemaCmd    `cmd:"" help:"Dump the command tree as JSON."`
	ExitCodes ExitCodesCmd `cmd:"" name:"exit-codes" help:"Print the exit code reference."`
	Agent     AgentCmd     `cmd:"" hidden:"" help:"Deprecated alias for exit-codes."`
}

CLI is the Kong command tree. Env var names are bound per store at parse time, so the same struct yields FRESCATTO_JSON and ZONASUL_JSON.

func (*CLI) SelectFields

func (c *CLI) SelectFields() []string

SelectFields returns the projection list, accepting --fields as an alias because agents reach for both names.

type CartAddCmd

type CartAddCmd struct {
	SKU    string `arg:"" help:"SKU to add."`
	Qty    int    `help:"Quantity." default:"1"`
	Seller string `help:"Seller id. Discovered from the catalog when omitted."`
	DryRun bool   `short:"n" help:"Show what would be added without changing the cart."`
}

func (*CartAddCmd) Run

func (c *CartAddCmd) Run(g *Globals) error

type CartClearCmd

type CartClearCmd struct {
	DryRun bool `short:"n" help:"Show what would be removed."`
}

func (*CartClearCmd) Run

func (c *CartClearCmd) Run(g *Globals) error

type CartCmd

type CartCmd struct {
	Show    CartShowCmd    `cmd:"" default:"withargs" help:"Show the current cart."`
	Add     CartAddCmd     `cmd:"" help:"Add a SKU to the cart."`
	Update  CartUpdateCmd  `cmd:"" help:"Set an item's quantity by index."`
	Remove  CartRemoveCmd  `cmd:"" help:"Remove an item by index."`
	Clear   CartClearCmd   `cmd:"" help:"Remove everything from the cart."`
	Reorder CartReorderCmd `cmd:"" help:"Re-add the items from a previous order."`
}

type CartRemoveCmd

type CartRemoveCmd struct {
	Index  int  `arg:"" help:"Item index from 'cart show'."`
	DryRun bool `short:"n" help:"Show the change without applying it."`
}

func (*CartRemoveCmd) Run

func (c *CartRemoveCmd) Run(g *Globals) error

type CartReorderCmd

type CartReorderCmd struct {
	OrderID string `arg:"" optional:"" help:"Order to copy. Defaults to the most recent."`
	DryRun  bool   `short:"n" help:"Show what would be added."`
}

func (*CartReorderCmd) Run

func (c *CartReorderCmd) Run(g *Globals) error

type CartShowCmd

type CartShowCmd struct{}

func (*CartShowCmd) Run

func (c *CartShowCmd) Run(g *Globals) error

type CartUpdateCmd

type CartUpdateCmd struct {
	Index  int  `arg:"" help:"Item index from 'cart show'."`
	Qty    int  `help:"New absolute quantity. 0 removes the item." required:""`
	DryRun bool `short:"n" help:"Show the change without applying it."`
}

func (*CartUpdateCmd) Run

func (c *CartUpdateCmd) Run(g *Globals) error

type CheckoutCmd

type CheckoutCmd struct {
	Payments CheckoutPaymentsCmd `cmd:"" help:"List the payment methods this store accepts."`
	Run      CheckoutRunCmd      `cmd:"" default:"withargs" help:"Preview or place an order."`
}

type CheckoutPaymentsCmd

type CheckoutPaymentsCmd struct {
	CEP string `help:"Postal code for the fallback simulation. Defaults to the configured address."`
	SKU string `help:"SKU for the fallback simulation."`
}

func (*CheckoutPaymentsCmd) Run

func (c *CheckoutPaymentsCmd) Run(g *Globals) error

Run lists the payment methods the store accepts and any cards saved on the account.

VTEX only populates paymentSystems once a cart has items, so an empty cart falls back to a shipping simulation, which returns the same list without mutating anything.

type CheckoutRunCmd

type CheckoutRunCmd struct {
	Window  int    `help:"Delivery window index from 'delivery windows'." default:"-1"`
	Payment string `help:"Payment method name, e.g. pix. Run 'checkout payments' to list." default:"pix"`
	CVV     string `help:"Card security code, for saved-card payment."`
	DryRun  bool   `short:"n" help:"Print the priced order as JSON and stop."`
	Confirm bool   `help:"Actually place the order. Required safety gate."`
}

func (*CheckoutRunCmd) Run

func (c *CheckoutRunCmd) Run(g *Globals) error

type DeliveryCmd

type DeliveryCmd struct {
	Windows  DeliveryWindowsCmd  `cmd:"" default:"withargs" help:"List delivery windows for the current cart."`
	Simulate DeliverySimulateCmd `cmd:"" help:"Check delivery for a CEP without logging in."`
}

type DeliverySimulateCmd

type DeliverySimulateCmd struct {
	CEP     string `help:"Postal code. Falls back to the configured address."`
	SKU     string `help:"SKU to simulate with. Required unless the cart has items."`
	Qty     int    `help:"Quantity." default:"1"`
	Seller  string `help:"Seller id. Discovered from the catalog when omitted."`
	Windows int    `help:"Maximum windows to show." default:"10"`
}

DeliverySimulateCmd checks delivery without authentication, which is how windows and payment methods can be inspected before anyone logs in.

func (*DeliverySimulateCmd) Run

func (c *DeliverySimulateCmd) Run(g *Globals) error

type DeliveryWindowsCmd

type DeliveryWindowsCmd struct {
	Limit int `help:"Maximum windows to show. 0 shows all." default:"0"`
}

func (*DeliveryWindowsCmd) Run

func (c *DeliveryWindowsCmd) Run(g *Globals) error

type DoctorCmd

type DoctorCmd struct{}

DoctorCmd answers one question: can this CLI place an order right now, and if not, what exactly does the user need to do?

It exists because the failure modes are not guessable. A cart that cannot check out, an account with no CPF, a card that VTEX will not expose until after a first order — each produces a different downstream error, and an agent should not have to reason from those errors back to a cause.

func (*DoctorCmd) Run

func (c *DoctorCmd) Run(g *Globals) error

type ExitCodesCmd

type ExitCodesCmd struct{}

func (*ExitCodesCmd) Run

func (c *ExitCodesCmd) Run(g *Globals) error

type FavAddCmd

type FavAddCmd struct {
	SKU    string `arg:"" help:"SKU to save."`
	DryRun bool   `short:"n" help:"Show what would be saved."`
}

func (*FavAddCmd) Run

func (c *FavAddCmd) Run(g *Globals) error

type FavCmd

type FavCmd struct {
	Show   FavShowCmd   `cmd:"" default:"withargs" help:"Show favorites."`
	Add    FavAddCmd    `cmd:"" help:"Save a product to favorites."`
	Remove FavRemoveCmd `cmd:"" help:"Remove a product from favorites."`
	Order  FavOrderCmd  `cmd:"" help:"Add every favorite to the cart (local lists only)."`
}

FavCmd manages the store's own wishlist — what the heart icons on the website save.

There is deliberately no bulk-order subcommand. A wishlist is things the shopper likes, not things they intend to buy now; "add all of it to the cart" is never what anyone means. Curated lists meant to be ordered wholesale live under `list`.

type FavOrderCmd

type FavOrderCmd struct {
	Qty    int  `help:"Quantity for each item." default:"1"`
	DryRun bool `short:"n" help:"Show what would be added."`
}

FavOrderCmd adds every favorite to the cart.

This is allowed only when favorites are a local list the shopper curated, which is the same thing `list order` does. It is refused for a store's own wishlist: that is a list of things the shopper likes, not a shopping list, and turning ten saved products into a cart is never what anyone means.

func (*FavOrderCmd) Run

func (c *FavOrderCmd) Run(g *Globals) error

type FavRemoveCmd

type FavRemoveCmd struct {
	SKU    string `arg:"" help:"SKU to remove."`
	DryRun bool   `short:"n" help:"Show what would be removed."`
}

func (*FavRemoveCmd) Run

func (c *FavRemoveCmd) Run(g *Globals) error

type FavShowCmd

type FavShowCmd struct{}

func (*FavShowCmd) Run

func (c *FavShowCmd) Run(g *Globals) error

type Globals

type Globals struct {
	CLI     *CLI
	Store   store.Store
	Version string
}

Globals is the context every command receives. It holds the store descriptor, which is what makes the whole command set store-agnostic — and, unlike the pre-extraction zonasul, it makes the command layer testable by letting a test point the store at an httptest server.

func (*Globals) ClearSecrets

func (g *Globals) ClearSecrets()

func (*Globals) Client

func (g *Globals) Client() *vtex.Client

Client returns a client carrying whatever token is stored, without checking it. Commands that work unauthenticated use this.

func (*Globals) Config

func (g *Globals) Config() config.Store

func (*Globals) Formatter

func (g *Globals) Formatter() *outfmt.Formatter

func (*Globals) OrderFormID

func (g *Globals) OrderFormID(client *vtex.Client) string

OrderFormID resolves the active cart, preferring the live session and falling back to the persisted value so a cart survives across invocations.

func (*Globals) PersistOrderFormID

func (g *Globals) PersistOrderFormID(id string)

func (*Globals) Prompt

func (g *Globals) Prompt(label string) (string, error)

Prompt reads a line from stdin, refusing when input is disabled so a headless run fails fast instead of hanging on a closed stdin.

func (*Globals) RequireAuth

func (g *Globals) RequireAuth() (*vtex.Client, error)

RequireAuth returns an authenticated client, refreshing an expired token when stored credentials allow it.

func (*Globals) SavePassword

func (g *Globals) SavePassword(password string) error

func (*Globals) SaveToken

func (g *Globals) SaveToken(jwt string) error

type ListAddCmd

type ListAddCmd struct {
	Name string `arg:"" help:"List name."`
	SKU  string `arg:"" help:"SKU to add."`
}

func (*ListAddCmd) Run

func (c *ListAddCmd) Run(g *Globals) error

type ListCmd

type ListCmd struct {
	Show   ListShowCmd   `cmd:"" default:"withargs" help:"Show a list, or all lists."`
	Add    ListAddCmd    `cmd:"" help:"Add a SKU to a list."`
	Remove ListRemoveCmd `cmd:"" help:"Remove a SKU from a list."`
	Order  ListOrderCmd  `cmd:"" help:"Add every SKU in a list to the cart."`
	Delete ListDeleteCmd `cmd:"" help:"Delete a list."`
}

type ListDeleteCmd

type ListDeleteCmd struct {
	Name string `arg:"" help:"List name."`
}

func (*ListDeleteCmd) Run

func (c *ListDeleteCmd) Run(g *Globals) error

type ListOrderCmd

type ListOrderCmd struct {
	Name   string `arg:"" help:"List name."`
	Qty    int    `help:"Quantity for each SKU." default:"1"`
	DryRun bool   `short:"n" help:"Show what would be added."`
}

func (*ListOrderCmd) Run

func (c *ListOrderCmd) Run(g *Globals) error

type ListRemoveCmd

type ListRemoveCmd struct {
	Name string `arg:"" help:"List name."`
	SKU  string `arg:"" help:"SKU to remove."`
}

func (*ListRemoveCmd) Run

func (c *ListRemoveCmd) Run(g *Globals) error

type ListShowCmd

type ListShowCmd struct {
	Name string `arg:"" optional:"" help:"List name. Omit to show all lists."`
}

func (*ListShowCmd) Run

func (c *ListShowCmd) Run(g *Globals) error

type OrdersCmd

type OrdersCmd struct {
	OrderID string `arg:"" optional:"" help:"Show one order's items instead of the list."`
}

func (*OrdersCmd) Run

func (c *OrdersCmd) Run(g *Globals) error

type ProductCmd

type ProductCmd struct {
	SKU string `arg:"" help:"SKU to look up."`
}

func (*ProductCmd) Run

func (c *ProductCmd) Run(g *Globals) error

Run finds a SKU by searching for it. VTEX has no public single-SKU endpoint that returns pricing, so this filters a search instead.

type SchemaCmd

type SchemaCmd struct {
	Command string `arg:"" optional:"" help:"Limit output to one command."`
}

SchemaCmd dumps the command tree so an agent can discover the surface without scraping --help. Generated from the live Kong model, so it can never drift from the actual commands the way a hand-written table does.

func (*SchemaCmd) Run

func (c *SchemaCmd) Run(g *Globals, kctx *kong.Context) error

type SearchCmd

type SearchCmd struct {
	Query string `arg:"" help:"Search terms, in Portuguese."`
	Limit int    `help:"Maximum results (max 50)." default:"20"`
}

func (*SearchCmd) Run

func (c *SearchCmd) Run(g *Globals) error

type StoreCmd

type StoreCmd struct {
	Info StoreInfoCmd `cmd:"" default:"withargs" help:"Show the descriptor and probe live capabilities."`
}

type StoreInfoCmd

type StoreInfoCmd struct{}

func (*StoreInfoCmd) Run

func (c *StoreInfoCmd) Run(g *Globals) error

Run reports what the CLI believes about the store and what the store says about itself. This is the first command to reach for when something breaks.

Directories

Path Synopsis
Package config stores per-store CLI state under ~/.config/<store>/.
Package config stores per-store CLI state under ~/.config/<store>/.
Package errfmt defines the stable exit codes and typed errors shared by every store CLI built on vtexkit.
Package errfmt defines the stable exit codes and typed errors shared by every store CLI built on vtexkit.
Package outfmt renders command output in the modes agents and humans need.
Package outfmt renders command output in the modes agents and humans need.

Jump to

Keyboard shortcuts

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