cli

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package cli implements datavase's command-line surface.

App takes its dependencies as fields so every command can be exercised in tests without a terminal, a keychain or a database.

Index

Constants

View Source
const CheckTimeout = 15 * time.Second

CheckTimeout bounds how long `dv check` waits before giving up.

Variables

This section is empty.

Functions

func HandleVersion

func HandleVersion(w io.Writer, args []string) bool

HandleVersion answers a request for the version, reporting whether it did.

It is a free function rather than a command on App because it has to run before the configuration is read: someone checking which build they have should not first be told to write a config file. That also means the flag spellings never reach flag.Parse, which would reject them as undefined.

Types

type App

type App struct {
	Config  *config.Config
	Secrets secret.Store
	Out     io.Writer
	Err     io.Writer

	// ReadPassword prompts for a password without echoing it. It is a field
	// so tests can supply input without a terminal.
	ReadPassword func(prompt string) (string, error)

	// Probe opens a connection and returns the server version. It is a field
	// so the command can be tested without a database.
	Probe func(ctx context.Context, ds *config.DataSource, password string) (string, error)

	// OpenUI connects and runs the terminal interface. It is a field so the
	// dispatch logic can be tested without starting a terminal.
	OpenUI func(ctx context.Context, ds *config.DataSource, password string, cfg *config.Config, opt UIOptions) error
}

App holds everything the commands need.

func (*App) Run

func (a *App) Run(args []string) int

Run dispatches args (excluding the program name) and returns an exit code.

type UIOptions added in v0.3.0

type UIOptions struct {
	// WorkDir is the directory of SQL work to attach, from --dir. Empty means
	// the session starts unattached.
	WorkDir string
}

UIOptions are the choices that belong to one invocation rather than to the configuration file.

It is a struct rather than more parameters so that the next such choice does not change the signature every caller and every test has to spell out.

Jump to

Keyboard shortcuts

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