Help us shape the future of Go! Take the 2026 Go Developer Survey

autoconfigcmd

package
v1.3.100 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package autoconfigcmd pkg/skywireconfig/autoconfigcmd/autoconfigcmd.go c3-vis-core autoconfig` as a freestanding factory. The CLI binary in cmd/skywire/commands wires the returned command into the root hierarchy and attaches its RunE; external consumers — TinyGo/Go WASM, doc generators, the apt-repo install-page form — call New() to introspect the flag set and render help text without dragging in the visor's transitive package graph.

Why a factory: cobra.Command and its flag bindings hold mutable state (flag values, parse results, Changed bits). A fresh command per call means multiple consumers can coexist without trampling each other's state. The flag *values* are returned alongside the command so the caller can both register a custom Run (for the CLI binary) and read the parsed values (for the .conf edit computation).

Why expose env-var metadata: each autoconfig flag corresponds to a SKYENV variable in /etc/skywire.conf. Encoding that mapping in the same place as the flag definition keeps the two from drifting apart, and lets WASM consumers render a form that shows operators exactly which line they're toggling.

Parity with `skywire cli config gen`: the autoconfig surface is designed to be a strict superset over the SKYENV-reading subset of `cli config gen` flags. Every variable config gen looks up via scriptExec*("${VAR…}") in cmd/skywire-cli/commands/config/gen.go has an autoconfig flag whose effect on skywire.conf produces the same downstream behavior. The non-SKYENV flags (--stdout, --regen, the per-service generators --sn/--dmsgdisc/etc., the OS selector --os) are intentionally NOT exposed — they have no persistence surface so autoconfig has nothing to do with them.

Package autoconfigcmd pkg/skywireconfig/autoconfigcmd/describe.go c3-vis-core

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EditFor

func EditFor(flag, value string) (skyenvfile.Edit, error)

EditFor returns the .conf edit that `skywire autoconfig --<flag>=<value>` makes. value is the flag's text: "true"/"false" for a bool, a number for an int, a comma-separated list for an array.

func EnvMap

func EnvMap() map[string]EnvMapping

EnvMap returns the flag → SKYENV-var mapping. Keys are CLI flag long names (without leading "--"). Flags absent from the map (--verbose and --no-restart) have no .conf-file effect — they only affect this run's behavior, not the persisted configuration.

A fresh map is returned each call so callers can mutate it without affecting the package-level data.

func KeyFor

func KeyFor(flag string) (string, bool)

KeyFor returns the .conf variable a flag writes.

func New

func New(v *Values) *cobra.Command

New returns a freshly-constructed autoconfig cobra command with flag bindings pointed at v's fields. The command has no RunE / Run — callers (the CLI binary) attach their own; WASM consumers only need cmd.UsageString() and cmd.Flags() and don't run it at all.

v must outlive the returned command. Passing nil triggers a panic at flag-registration time (cobra's BoolVar et al. require a non-nil destination).

Types

type EnvFormat

type EnvFormat string

EnvFormat describes how a flag's runtime value is rendered into its /etc/skywire.conf line.

const (
	// EnvFormatBool emits `KEY=true` or `KEY=false`.
	EnvFormatBool EnvFormat = "bool"
	// EnvFormatString emits `KEY='value'` with single-quote wrap.
	EnvFormatString EnvFormat = "string"
	// EnvFormatInt emits `KEY=N`. Zero values are skipped at the
	// edit-collection layer (matches the "0 = leave unchanged"
	// semantic in the autoconfig --help text for port flags).
	EnvFormatInt EnvFormat = "int"
	// EnvFormatBashArray emits `KEY=('a' 'b' …)` from a
	// comma-separated input — the shape HYPERVISORPKS,
	// DMSGPTYPKS, and similar array-typed env vars use.
	EnvFormatBashArray EnvFormat = "bashArray"
)

type EnvMapping

type EnvMapping struct {
	// Key is the SKYENV variable name (e.g. "ISHYPERVISOR").
	Key string
	// Format is the wire encoding for KEY=… in /etc/skywire.conf.
	Format EnvFormat
	// Negate inverts the emit for bool flags. A negation flag like
	// --no-ishv has Negate=true so passing it (which sets the
	// bool to true) writes ISHYPERVISOR=false to the .conf file.
	Negate bool
	// Default is the effective default the visor's `cli config gen`
	// uses when the SKYENV variable is unset/commented. Empty when
	// the underlying default is "" (no useful hint to show). This
	// field exists so the WASM install-page can display the actual
	// default as a placeholder hint — operators see "default:
	// 127.0.0.1:8001" rather than the misleading "(unset)" the
	// flag's own DefValue reports (which is "" because autoconfig
	// itself defaults every flag to empty, deferring to skywire.conf
	// / config-gen for the real default).
	//
	// Source of truth: the `:-` fallbacks in
	// cmd/skywire-cli/commands/config/gen.go's scriptExec* calls,
	// plus the skyenv constants those calls reference for the
	// string-typed defaults. Keep in sync — if config-gen's
	// defaults change, update this table too.
	Default string
	// Note is operator-facing guidance that does not fit the flag's
	// own one-line description because it is about how this variable
	// interacts with ANOTHER one: a dependency ("pin TRANSPORTPORT
	// when you turn this on") or a conflict ("this and DMSGSERVERCONF
	// are mutually exclusive"). The install-page form renders it
	// beside the field; the CLI does not print it, since --help
	// already shows every flag at once and the cross-references read
	// as noise there.
	//
	// Empty for the vast majority of variables, which stand alone.
	Note string
}

EnvMapping ties a CLI flag to the SKYENV variable it writes when the operator passes the flag.

type Flag

type Flag struct {
	Name        string `json:"name"`
	Short       string `json:"short,omitempty"`
	Type        string `json:"type"` // "bool" | "string" | "int"
	DefaultVal  string `json:"default,omitempty"`
	Description string `json:"description"`

	// EnvKey is the variable this flag writes; empty for flags that only
	// affect one autoconfig run (--verbose, --no-restart).
	EnvKey string `json:"env_key,omitempty"`
	// EnvFormat is the .conf encoding: "bool", "string", "int", "bashArray".
	EnvFormat string `json:"env_format,omitempty"`
	// EnvNegate marks a --no-X flag, which writes KEY=false.
	EnvNegate bool `json:"env_negate,omitempty"`
	// EnvDefault is what config gen uses while the variable is unset.
	EnvDefault string `json:"env_default,omitempty"`
	// EnvNote is guidance about how this variable interacts with another.
	EnvNote string `json:"env_note,omitempty"`
}

Flag is one autoconfig flag as a settings form renders it: the flag itself plus the /etc/skywire.conf variable it writes. The install-command generator and the visor's settings page read this same shape, so a flag added to New shows up in both without either being edited.

func Describe

func Describe() []Flag

Describe returns every autoconfig flag in registration order, the order operators see in --help.

type Values

type Values struct {
	// --- Display-only ---
	Verbose bool

	// --- Hypervisor / identity ---
	Hvpks        string
	WSPeers      string // WSPEERS: <pk>@<ws(s)://…> peers held as WebSocket transports
	Ishv         bool
	NoIshv       bool
	HvDeskAddr   string // HVDESKADDR
	PkEndpoint   bool   // ENABLEPKENDPOINT
	NoPkEndpoint bool
	HvAuth       bool // HVAUTH
	NoHvAuth     bool
	HvAddr       string // HVHTTPADDR
	SecretKey    string // SK — security-sensitive; see flag description
	Version      string // VERSION — testing override

	// --- Visor public/private + autoconnect ---
	RewardAddr     string
	Public         bool
	NoPublic       bool
	PublicIP       bool // DISPLAYNODEIP
	DisablePubAuto bool

	// --- Service discovery / deployment ---
	TestEnv     bool   // TESTENV
	URL         string // SVCCONFADDR (services conf URL — accepts comma-list)
	SvcConf     string // SVCCONF (fallback service-configuration file)
	MinSess     int    // MINDMSGSESS
	StunServers string // STUNSERVERS (comma-separated)

	// --- Public-visor transport limit ---
	MaxTransports int // MAXTRANSPORTS (pause service-discovery registration at this DISTINCT-PEER count)

	// --- Transport ports ---
	StcprPort      int
	SudphPort      int
	TransportPort  int
	LanDmsgPort    int
	LanDmsgPublic  string
	DmsgServerConf string
	// DmsgServer runs a dmsg server inside the visor on the visor's OWN key,
	// sharing its transport port — writes DMSGSERVER. NoDmsgServer turns it
	// back off, the way every other boolean here is unset.
	DmsgServer   bool
	NoDmsgServer bool
	// DmsgServerPublic is the address that server advertises — writes
	// DMSGSERVERPUBLIC.
	DmsgServerPublic string

	// DmsgServerWSTLS is where that server self-terminates TLS for its wss
	// front (":443") instead of leaving it to a reverse proxy on the host —
	// writes DMSGSERVERWSTLS. Which is right differs per host: some already
	// run Caddy on :443, and on the rest the standalone dmsg server WAS the
	// terminator, so folding it left the advertised wss front with nothing
	// listening behind it.
	DmsgServerWSTLS string

	// DmsgRelayAddr is a loopback host:port for the local dmsg relay acceptor —
	// writes DMSGRELAYADDR. The unix socket is served by default and needs no
	// config, but it carries the VISOR's uid at 0600, so a service running as a
	// different user cannot open it. A loopback acceptor has no such problem;
	// its gate is DmsgRelayKeys instead of file permissions.
	DmsgRelayAddr string
	// DmsgRelayKeys are the public keys allowed to attach, comma-separated —
	// writes DMSGRELAYKEYS. Required with DmsgRelayAddr.
	DmsgRelayKeys string
	// NoDmsgRelay turns the acceptor off entirely — writes NODMSGRELAY.
	NoDmsgRelay bool

	// --- Privacy / routing knobs ---
	MinHops            int  // MINHOPS (>=2 forces multihop for sender privacy)
	ARTransportLimit   int  // ARTRANSPORTLIMIT (address-resolver registration policy)
	NoDirectTransports bool // NODIRECTTRANSPORTS (never create direct p2p transports)
	PtyRPCExec         bool // PTYRPCEXEC (allow visor-RPC-initiated dmsgpty exec)

	// --- Whitelists ---
	DmsgptyPks     string
	SurveyPks      string // SURVEYPKS
	RouteSetupPKs  string // ROUTESETUPPKS
	TransportSetup string // TPSETUPPKS

	// --- Route calculation ---
	CalculateRoutes bool // CALCULATEROUTES

	// --- VPN server feature ---
	VpnServer           bool
	NoVpnServer         bool
	VpnRouter           bool   // VPNROUTER
	VpnRouterLanIfc     string // VPNROUTERLANIFC
	VpnRouterSubnet     string // VPNROUTERSUBNET
	VpnRouterWifi       bool   // VPNROUTERWIFI
	VpnRouterSSID       string // VPNROUTERSSID
	VpnRouterPassphrase string // VPNROUTERPASSPHRASE
	VpnRouterBand       string // VPNROUTERBAND
	VpnRouterChannel    int    // VPNROUTERCHANNEL
	VpnRouterCountry    string // VPNROUTERCOUNTRY
	VpnRouterOpenWiFi   bool   // VPNROUTEROPEN
	VpnRouterMeshGW     bool   // VPNROUTERMESHGW
	VpnRouterMeshGWCIDR string // VPNROUTERMESHGWCIDR
	VpnRouterMeshTLS    bool   // VPNROUTERMESHTLS
	VpnKillSw           string // VPNKS
	AddVpn              string // ADDVPNPK
	VpnWl               string // VPNSERVERWL (comma-separated)
	VpnSecure           string // VPNSEVERSECURE (sic — typo retained for compat with config gen's env-var name)
	VpnNetIfc           string // VPNSEVERNETIFC (sic — same)

	// --- Proxy feature ---
	ProxyServer   bool
	NoProxyServer bool
	ProxyClientPK string // PROXYCLIENTPK
	StartProxyCli bool   // STARTPROXYCLIENT
	ProxyWl       string // PROXYSERVERWL (comma-separated)

	// --- SOCKS5 web bridges ---
	Dmsgweb           bool
	NoDmsgweb         bool
	Skynetweb         bool
	NoSkynetweb       bool
	DmsgwebUpstream   string // DMSGWEBUPSTREAM
	SkynetwebUpstream string // SKYNETWEBUPSTREAM
	DmsgwebAddr       string // DMSGWEBADDR
	// DmsgwebSK runs the embedded resolver under this secret key instead of the
	// visor's — writes DMSGWEBSK. For a key the deployment already knows and
	// cannot rotate, such as a survey whitelist.
	DmsgwebSK     string // DMSGWEBSK
	SkynetwebAddr string // SKYNETWEBADDR
	// Resolvers (RESOLVERS) declares ADDITIONAL resolving proxies beyond
	// the DMSGWEB/SKYNETWEB pair, one comma-separated spec each. See the
	// flag's help text for the spec grammar.
	Resolvers string

	// --- Embedded Wisp server ---
	//
	// The backend a browser-side Linux guest asks to open its connections.
	// Every browser-tab visor runs it and no native one does, so there is
	// nothing to turn on; only its egress is a setting. It lives in the conf
	// because a wasm visor regenerates its config on every load, so a
	// hand-edited wisp section does not survive.
	WispSOCKS string // WISPSOCKS

	// --- Skychat ---
	Skychat         bool
	NoSkychat       bool
	ChatAddr        string // SKYCHATADDR
	ChatPortless    bool   // SKYCHATPORTLESS — no TCP port, hypervisor-only
	NoChatPortless  bool
	ServeChatPair   bool // SKYCHATPAIR — default true in config gen
	NoServeChatPair bool

	// --- Skymail bridge (SMTP↔skywire) ---
	SkymailBridge   bool // SKYMAILBRIDGE
	NoSkymailBridge bool

	// --- Skycoin daemon (legacy + multi-instance) ---
	Skycoind          bool
	NoSkycoind        bool
	SkycoindFiber     string // SKYCOIND_FIBER_TOML
	SkycoindAPI       string // SKYCOIND_API_SETS
	SkycoindUser      string // SKYCOIND_USER
	SkycoindInstances string // SKYCOIND_INSTANCES (comma-separated)
	SkycoindFlags     string // SKYCOIND_FLAGS

	// --- Skycoin web wallet ---
	Skycoinweb         bool
	NoSkycoinweb       bool
	SkycoinwebAddr     string // SKYCOINWEBADDR
	SkycoinwebNodes    string // SKYCOINWEBNODES (comma-separated)
	SkycoinwebWallet   string // SKYCOINWEBWALLET
	SkycoinwebElectrum string // SKYCOINWEBELECTRUM
	SkycoinwebUser     string // SKYCOINWEBUSER

	// --- Visor runtime ---
	BinPath         string // BINPATH
	LogLevel        string // LOGLVL
	ShutdownTimeout string // SHUTDOWNTIMEOUT
	RegTimeout      string // REGTIMEOUT

	// --- Runtime behavior (NOT written to skywire.conf) ---
	// NoRestart generates/writes the config but skips the
	// systemctl restart of skywire.service at the end. This is the
	// pty-safe update path: when the operator is connected over the
	// visor's own dmsgpty, restarting skywire.service kills that pty
	// session (and any in-flight apt/autoconfig process with it). With
	// --no-restart the config is applied without the restart; the
	// operator then triggers the restart out-of-band as the LAST step
	// via `systemctl start --no-block skywire-autoconfig.service`,
	// which runs decoupled from the session.
	NoRestart bool
}

Values holds the destination addresses for every flag binding installed by New. Callers pass a Values they own (typically a package-level var in cmd/skywire/commands/autoconfig.go) so that post-parse reads stay simple field access — no double-indirection.

Field groupings mirror the help-output sections in the `skywire cli config gen --all` output so that operators familiar with config gen find each autoconfig flag in roughly the same neighborhood.

Jump to

Keyboard shortcuts

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