cli

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cli provides the connection settings a takt client resolves from flags, the environment and the config file, in that order.

The file is the human path: `takt auth login` writes the token it minted here, because a child process cannot set an environment variable in its parent shell. The environment is the machine path: CI injects TAKT_TOKEN in one line. Flags are the most specific and win over both. Exported so that anyone writing their own takt client can honour the same settings.

Index

Constants

View Source
const DefaultAddress = "http://localhost:7373"

DefaultAddress is where a client connects when nothing names a server.

Variables

This section is empty.

Functions

func NewContext added in v0.6.0

func NewContext(ctx context.Context, config Config) context.Context

NewContext returns a context that carries the resolved settings.

This is how the CLI hands the settings it resolved once, at the root command, to a subcommand that needs more than the client built from them. The login command is the reason: it connects without the stored credential and writes the settings back beside the token it mints, neither of which the shared client can do for it.

func Path

func Path(flag string) (string, error)

Path returns where the config file lives: the given --config flag value, what TAKT_CONFIG names, or .takt/config under the home directory. Pointing either at another file is the multi-server and multi-identity answer.

func Write

func Write(path string, config Config) error

Write stores the config file at the given path, creating its directory readable only by the owner and the file the same way, because the file holds a credential.

Types

type Config

type Config struct {
	// The address of the takt server, as a URL.
	Address string `toml:"address"`
	// The token presented as a bearer credential. Empty sends no credential.
	Token string `toml:"token"`
	// The path of a PEM certificate authority file to check the server's
	// certificate against instead of the system roots.
	CACert string `toml:"ca_cert"`
	// The file the settings were read from, and where Save writes them
	// back. Not a setting itself: Load records it, and it never appears
	// in the file.
	File string `toml:"-"`
}

The Config type contains the settings a client connects with.

There is no flag for the token, deliberately: a token passed as a flag lands in shell history and process listings for no benefit the other sources lack.

func FromContext added in v0.6.0

func FromContext(ctx context.Context) Config

FromContext returns the settings the context carries, or the zero Config when it carries none.

func Load

func Load(path string) (Config, error)

Load reads the config file at the given path, reporting an absent file as a Config with no settings: a client that never logged in simply has no file yet. Either way the result records the path, so Save knows where the settings belong.

func Resolve

func Resolve(sources Sources) (Config, error)

Resolve returns the settings a client should connect with, taking each field from the most specific source that supplies it: the flag values in sources, then the TAKT_ADDRESS, TAKT_TOKEN and TAKT_CA_CERT environment variables, then the config file the sources name.

The address falls back to DefaultAddress when nothing supplies one, so a client on the same host as its server needs no configuration at all.

func (Config) Save added in v0.6.0

func (c Config) Save() error

Save writes the settings back to the file they were read from, creating it for a client that has never logged in. It refuses settings that record no file, which is what a Config built by hand rather than by Load or Resolve carries.

type Sources added in v0.6.0

type Sources struct {
	// The --config flag value, naming the config file. Empty resolves
	// the file the way Path does.
	ConfigPath string
	// The --address flag value.
	Address string
	// The --ca-cert flag value.
	CACert string
}

The Sources type names the flag values Resolve folds in. An empty field means the flag was not given, so the environment and the file stay visible behind it.

Jump to

Keyboard shortcuts

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