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

cliutil

package
v1.3.104-alpha1 Latest Latest
Warning

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

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

Documentation

Overview

Package cliutil cmd/skywire-cli/cliutil/cliutil.go c4-vis-cli

Package cliutil cmd/skywire-cli/cliutil/transport.go c4-vis-cli Shared transport vocabulary for the remote-access commands (pty exec/start, pty shell, dmsg scp, pty fs mount). Each command supports a ragged subset of these transports — see each command's help for its own matrix. This file only defines the vocabulary and the flag-vs-target-scheme precedence; it does not itself dial.

Index

Constants

View Source
const (
	TransportAuto   = "auto"
	TransportDmsg   = "dmsg"
	TransportSkynet = "skynet"
	TransportTCP    = "tcp"
)

Canonical transport names shared across the remote-access commands.

auto   each command's current default behavior.
dmsg   via-visor dmsg.
skynet via-visor skynet.
tcp    direct noise-TCP to a host:port (needs a host:port target).

Variables

View Source
var JSONString = "json"

JSONString is the name of the json flag

View Source
var LoopbackDialer loopbackDialer

LoopbackDialer is the forward dialer for reaching a local SOCKS5 proxy. It dials through vnet, so inside a browser tab 127.0.0.1:<port> reaches the in-tab visor's listener (proxy.Direct would use the host network and be refused); on native builds it is net.DialTimeout.

Functions

func Catch

func Catch(cmdFlags *pflag.FlagSet, err error)

Catch handles errors for skywire-cli commands packages

func CheckDirectViaScheme

func CheckDirectViaScheme(cmdFlags *pflag.FlagSet, value, want string)

CheckDirectViaScheme rejects a remote-visor target passed to a subcommand whose own --via means a direct dial instead.

The root command has a persistent --via that proxies the RPC to a remote visor (dmsg://<pk> or skynet://<pk>). Four subcommands define a local --via with an incompatible meaning — skychat send, dmsg probe, dmsg pty start and dmsg pty exec dial tcp://<pk>@host:port directly, and proxy test takes a bare PK to route a 2-hop test through. A local flag shadows the persistent one, so on those commands the remote-visor form is not merely wrong, it is unreachable. Without this the value is parsed as a host and the failure surfaces much later as an opaque dial error.

func ParsePK

func ParsePK(cmdFlags *pflag.FlagSet, name, v string) cipher.PubKey

ParsePK parses a public key

func ParseUUID

func ParseUUID(cmdFlags *pflag.FlagSet, name, v string) uuid.UUID

ParseUUID parses a uuid

func PrintError

func PrintError(cmdFlags *pflag.FlagSet, err error)

PrintError prints errors for skywire-cli commands packages. JSON mode writes to stderr; non-JSON path uses the package logger.

func PrintFatalError

func PrintFatalError(cmdFlags *pflag.FlagSet, err error)

PrintFatalError prints errors for skywire-cli commands packages. In --json mode the JSON error is written to stderr (so success output on stdout stays parseable), then the process exits 1.

func PrintFatalRPCError

func PrintFatalRPCError(cmdFlags *pflag.FlagSet, err error)

PrintFatalRPCError prints fatal RPC errors for skywire-cli commands packages

func PrintOutput

func PrintOutput(cmdFlags *pflag.FlagSet, outputJSON, output interface{})

PrintOutput prints the value as raw JSON (no `{"output": ...}` envelope) in --json mode, or the human text otherwise.

Migrated from the legacy CLIOutput envelope: previously the JSON path emitted `{"output": <value>}`, which forced every consumer through `jq '.output...'`. Now consumers pipe `jq '...'` directly against the value — matching gh, kubectl, and stripe.

Errors continue to go through PrintFatalError / PrintError, which emit `{"error": "..."}` to stderr — so a successful pipe sees only values, and an interrupted pipe sees only errors.

func PrintPipe

func PrintPipe(cmdFlags *pflag.FlagSet, p *script.Pipe)

PrintPipe renders a bitfield/script pipeline through PrintOutput so the global --json / --jq / --shape flags apply to it.

Commands that build their output with a script pipeline used to end it in .Stdout(), writing straight past the printer. The flags were then accepted and silently ignored: `cli pv --jq length` printed the list of keys, and --shape printed the list too. Nothing in --help distinguished those commands from the ones that honor the contract, so the only way to find out was to pipe the result somewhere and notice it was not JSON.

The JSON form is the pipeline's non-empty output lines as an array of strings, which is what a caller filtering a list command actually wants (`--jq length` counts them). The human form is the text exactly as the pipeline produced it, so default output is unchanged.

func PrintRPCError

func PrintRPCError(cmdFlags *pflag.FlagSet, err error)

PrintRPCError prints nonfatal RPC errors for skywire-cli commands packages

func PrintRawJSON

func PrintRawJSON(cmdFlags *pflag.FlagSet, raw, human string)

PrintRawJSON renders an already-serialized JSON document through PrintOutput so --jq / --shape can address its real structure rather than its text.

Used by the --raw branches of the discovery commands, which previously colorized the document and wrote it straight to stdout.

func ResolveTransport

func ResolveTransport(flagVal string, flagChanged bool, targetScheme string) (string, error)

ResolveTransport reconciles an explicit --transport / --scheme flag with a scheme carried on the positional target, returning the effective transport.

flagVal      the --transport value; "" is treated as auto.
flagChanged  whether the user explicitly set the flag.
targetScheme the scheme parsed from the target ("" if the target
             is bare).

Precedence:

  • target bare -> flagVal (default auto).
  • only the target scheme'd -> the target scheme.
  • both, and they agree -> that transport.
  • both, and they conflict -> error (an explicit non-auto flag that disagrees with the target scheme is ambiguous — the caller must drop one).

An explicit --transport auto never conflicts: an operator asking for auto alongside a scheme'd target is read as "let the target decide".

func SplitTargetScheme

func SplitTargetScheme(target string) (scheme, rest string)

SplitTargetScheme detects a leading dmsg:// / skynet:// / tcp:// scheme on a positional target. On a recognized prefix it returns the scheme name (without "://") and the remainder after "://"; otherwise ("", target) with target unchanged. Bare targets — a plain PK, <pk>:path, <pk>@host:port — therefore pass through byte-identical, so every pre-existing target form keeps working.

Types

type CLIOutput

type CLIOutput struct {
	Output interface{} `json:"output,omitempty"`
	Err    string      `json:"error,omitempty"`
}

CLIOutput is the legacy success-envelope shape kept around so external callers that imported the type don't break. New code should not construct it; PrintOutput emits raw JSON values directly.

Directories

Path Synopsis
Package livetui cmd/skywire-cli/cliutil/livetui/livetui.go c4-vis-cli helper.
Package livetui cmd/skywire-cli/cliutil/livetui/livetui.go c4-vis-cli helper.
Package pterm cmd/skywire-cli/cliutil/pterm/pterm.go c5-cli-util
Package pterm cmd/skywire-cli/cliutil/pterm/pterm.go c5-cli-util
Package putils cmd/skywire-cli/cliutil/putils/putils.go c5-cli-util
Package putils cmd/skywire-cli/cliutil/putils/putils.go c5-cli-util

Jump to

Keyboard shortcuts

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