cmd

package
v0.104.2 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 51 Imported by: 0 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 cmd implements the teanode subcommands.

Index

Constants

View Source
const (
	ExitFailure      = 1
	ExitUsage        = 2
	ExitReadOnly     = 3
	ExitNotFound     = 4
	ExitUnauthorized = 5
	ExitUnreachable  = 6
)

Exit codes, so that a script can tell what kind of thing went wrong without parsing the message. The numbering is shared with a sibling tool whose users drive both, which is why 3 to 6 are what they are.

View Source
const CommandLinePagePath = "/cli"

CommandLinePagePath is where the dashboard's authorization page lives. Named in both the client and the server, so the two cannot drift.

View Source
const LocalProfileName = "local"

LocalProfileName is the reserved name for the server this environment points at, reached over loopback with a token minted from the stored secret rather than with a saved one. It is never written to the file.

Variables

This section is empty.

Functions

func Describe

func Describe(command *cli.Command, err error) error

Describe is describeError for the root command, which is what main has when a command's error reaches it. Every path that resolves the target reads the root's flags, so the root is enough.

func ExitCode

func ExitCode(err error) int

ExitCode says which code a failed command should exit with.

func ForceFlag

func ForceFlag() cli.Flag

ForceFlag is offered by every command that would otherwise ask before doing something that cannot be undone. TEANODE_FORCE sets it for every command in a shell, for a script that has already decided.

func JSONFlag

func JSONFlag() cli.Flag

JSONFlag is offered by every command that prints a table, so that a script or a language model driving the tool gets structured output from the same command a person reads.

func JSONRequested

func JSONRequested() bool

JSONRequested says whether the command that ran wanted JSON.

func LoadLocalConfiguration

func LoadLocalConfiguration() (*config.Configuration, error)

LoadLocalConfiguration reads the stored configuration for a command that only looks at it.

func LoadLocalDomains

func LoadLocalDomains() ([]*models.Domain, error)

LoadLocalDomains reads every domain from the database the environment names, for a command that runs where the server does but without it.

func NewAPICommand

func NewAPICommand() *cli.Command

NewAPICommand builds "teanode api", which reaches every operation the server offers rather than only the ones with a command of their own.

It works off the schema the server reports, so an operation added to the API is callable the moment the server supports it, with no second place to update and nothing to drift. Output is JSON, which is also what makes it usable from a script or by a language model driving the tool.

func NewAgentCommand

func NewAgentCommand() *cli.Command

NewAgentCommand builds "teanode agent": a person's own agent — turning it on, what it knows about them, which mailboxes it may reach — and, for an operator, everybody's agents by their tokens.

Every value here goes through the API, so a change made from a shell is the change the Agent page would have made.

func NewAliasCommand

func NewAliasCommand() *cli.Command

NewAliasCommand builds "teanode alias": where mail for a domain goes. An alias matches the part of the address before the @ with a regular expression and sends the message to an address, a webhook, or another mail server; an empty pattern is a catch-all. Aliases are named by identifier, which "alias list" prints, because a pattern is not something to type twice.

func NewAppCommand added in v0.53.0

func NewAppCommand() *cli.Command

NewAppCommand builds "teanode app", the programs authorized to act as somebody. Each holds a token it renews by itself, so it is the app that is named and disconnected, not the token of the moment.

func NewAuditCommand

func NewAuditCommand() *cli.Command

NewAuditCommand builds "teanode audit": the log of administrative changes, who made them, and what the row looked like before and after.

func NewAuthCommand

func NewAuthCommand() *cli.Command

NewAuthCommand builds "teanode auth": signing in to a server and keeping the profiles that result.

func NewCalendarCommand

func NewCalendarCommand() *cli.Command

func NewComputerCommand

func NewComputerCommand() *cli.Command

NewComputerCommand builds "teanode computer": the program that attaches this computer to the person's agent, so that the agent's shell and filesystem tools reach it while they talk. It signs in with the active profile's token — the person's, from "teanode auth login" — never the server's own.

func NewContactCommand

func NewContactCommand() *cli.Command

func NewCredentialCommand

func NewCredentialCommand() *cli.Command

NewCredentialCommand builds "teanode credential", which manages the username and password an application uses to send mail through this server.

func NewDKIMCommand

func NewDKIMCommand() *cli.Command

NewDKIMCommand builds "teanode dkim", which manages the keys that sign outgoing mail. Keys live in the domain table, one per domain, and are created automatically when a domain is added — so these commands exist for rotation and for looking up a record, not for first-time setup.

func NewDeliveryCommand

func NewDeliveryCommand() *cli.Command

NewDeliveryCommand builds "teanode delivery": what happened to each message on its way out, and the queue of what has not gone yet.

func NewDomainCommand

func NewDomainCommand() *cli.Command

NewDomainCommand builds "teanode domain", the domains this server accepts mail for. Domains are named by name on the command line; the API's identifier for a domain is its name, so the two are the same thing.

func NewFinanceCommand added in v0.87.0

func NewFinanceCommand() *cli.Command

func NewGroupCommand

func NewGroupCommand() *cli.Command

NewGroupCommand builds "teanode group": who may do what, and where. A group holds people, the roles that say what they may do, and the domains the domain-kind permissions apply to. An account with no group may read its own mailbox and nothing else.

func NewLayoutCommand

func NewLayoutCommand() *cli.Command

NewLayoutCommand builds "teanode layout": the frames templates are rendered inside. Layouts have no name of their own, so they are named by identifier, which "layout list" prints.

func NewMailCommand

func NewMailCommand() *cli.Command

NewMailCommand builds "teanode mail": the messages this server has handled, and sending one.

func NewMailboxCommand

func NewMailboxCommand() *cli.Command

NewMailboxCommand builds "teanode mailbox": a person's own mail, as the dashboard shows it. The folders it is filed into, the rules that file it, the contacts it has learned, the app passwords a mail program signs in with, and the out-of-office reply.

Every subcommand acts on one mailbox. Most people have one, so --mailbox is needed only when there are several; it takes the name or the identifier.

func NewNoteCommand added in v0.78.0

func NewNoteCommand() *cli.Command

func NewPasskeyCommand

func NewPasskeyCommand() *cli.Command

NewPasskeyCommand builds "teanode passkey": the authenticators registered to the account this command acts as. Registering one needs a browser with an authenticator to talk to, so that happens in the dashboard; the rest is here.

func NewReminderCommand added in v0.77.0

func NewReminderCommand() *cli.Command

func NewReportCommand

func NewReportCommand() *cli.Command

NewReportCommand builds "teanode report": the DMARC aggregate reports other people send about mail claiming to be from these domains, which is how an operator finds out somebody is forging one.

func NewRoleCommand

func NewRoleCommand() *cli.Command

NewRoleCommand builds "teanode role": the named sets of permissions a group holds.

func NewServerCommand

func NewServerCommand() *cli.Command

NewServerCommand builds "teanode server": the running instance, as opposed to its configuration.

func NewSessionCommand

func NewSessionCommand() *cli.Command

NewSessionCommand builds "teanode session": the browsers an account is signed in on.

func NewSettingsCommand

func NewSettingsCommand() *cli.Command

NewSettingsCommand builds "teanode settings": the optional integrations.

"set" is generic on purpose. Each section's keys and their types come from the server's own schema — the <Section>ParametersInput object — so a setting added to the API is settable the day it appears, and a value is converted to the type the schema declares the way "teanode api call" converts an argument. Eight sections of five to eight fields each would otherwise be forty flags to write and keep in step.

func NewTemplateCommand

func NewTemplateCommand() *cli.Command

NewTemplateCommand builds "teanode template": the messages a domain sends with variables filled in. A template is named by its domain and its name, which is how the API looks one up.

func NewTerminalCommand

func NewTerminalCommand() *cli.Command

NewTerminalCommand is `teanode terminal`.

func NewTokenCommand

func NewTokenCommand() *cli.Command

NewTokenCommand builds "teanode token", which issues the tokens that let this tool administer a server from somewhere else.

On the server itself no token is needed: the tool authenticates with one it mints from the server secret in the configuration file. Tokens are for running "teanode --url https://mail.example.com ..." from a laptop, or from a deployment script.

func NewUpgradeCommand

func NewUpgradeCommand() *cli.Command

NewUpgradeCommand builds "teanode upgrade": what the server is running, what has been released since, and installing a release from here.

func NewUserCommand

func NewUserCommand() *cli.Command

NewUserCommand builds "teanode user", for the accounts that administer this server. Normally the first account is created in the browser on first run; these exist for when a browser is not an option.

Everything here goes through the running server. A server that will not start, or that nobody can log into, is what "teanode-server user" is for: it edits the stored configuration directly.

func NewVersionCommand

func NewVersionCommand(program string) *cli.Command

NewVersionCommand builds the "version" command of either program. Both are built from the same tree, so they report the same version; the name says which one answered.

func NoteUsageError

func NoteUsageError(failed *cli.Command, arguments []string)

NoteUsageError records whether JSON was asked for when the library refused the arguments before any flag action or Before could run: --json is looked for in the arguments as they were typed, and a command that always prints JSON is known by its metadata.

func OpenBootstrapDatabase

func OpenBootstrapDatabase(bootstrapped *bootstrap.Bootstrap) (db.Database, func(), error)

OpenBootstrapDatabase connects to the database the environment names, without migrating it. The caller calls the returned function to close it.

func OpenLocalDatabase

func OpenLocalDatabase() (db.Database, func(), error)

OpenLocalDatabase connects to the database the environment names, for the commands that read and write tables rather than the configuration.

Deliberately not migrating, for the same reason OpenLocalStore does not: a command line tool that silently changes the schema of a database a server is running against is a way to be surprised.

func OpenLocalStore

func OpenLocalStore() (config.Store, func(), error)

OpenLocalStore opens the configuration where the server keeps it: the database named by the environment.

This is what "on the server itself, nothing has to be set up first" means now. The command reads the same variables the server reads, so running it in the same container, or with the same env file, reaches the same configuration. From anywhere else, use --url and a token.

The caller closes the returned store and then calls the returned function, which closes the database under it.

func PrintError

func PrintError(err error)

PrintError writes a failed command's error the way its output would have been written: as JSON when JSON was asked for, so a script parses failure the same way it parses success, and as text otherwise. Always to standard error, so that a failure is never mistaken for a result.

func PrintJSON

func PrintJSON(value any) error

PrintJSON writes a value to standard output as indented JSON, which is what every command prints with --json and what "teanode api" prints always.

func ProfilesPath

func ProfilesPath() (string, error)

ProfilesPath is where the file lives: $XDG_CONFIG_HOME/teanode/profiles.json, or ~/.config/teanode/profiles.json.

func ReadPassword

func ReadPassword(fromStdin bool) (string, error)

ReadPassword prompts twice without echoing, so that a typo does not lock the operator out of their own dashboard. With fromStdin it reads one line, for scripts.

func ReadSecret

func ReadSecret(prompt string) (string, error)

ReadSecret reads one secret without echoing it, for a token pasted at a prompt. Unlike a new password it is asked for once: a mistyped token is refused by the server rather than locking anybody out. When standard input is not a terminal the secret is read from it, which is how a script passes one in.

func SetLogLevel

func SetLogLevel(level string)

SetLogLevel applies a log level by name, ignoring an empty or unparseable value so that a typo does not silence the server.

func SetupLogging

func SetupLogging(level string)

SetupLogging installs the log format used by every subcommand. The level given on the command line wins; when it is empty the level from the configuration file is applied later by the run command.

func UpdateLocalConfiguration

func UpdateLocalConfiguration(mutate func(*config.Configuration) error) error

UpdateLocalConfiguration changes the stored configuration directly, for the commands that have to work when the server will not start or nobody can log in.

Writing straight to the database while a server is running used to be the thing that lost a change, back when the server held the whole configuration in memory and rewrote a file from it. It is safe now: the write is checked against the version it was based on, and every running instance notices the new version within seconds and reloads. That is the same path the dashboard takes, one layer lower down.

func Usage

func Usage(message string) error

Usage is usage for the program's main, which reports what the library refused to parse.

Types

type Profile

type Profile struct {
	// Name is how --profile names it; the server's host name by default.
	Name string `json:"name"`

	// URL of the server, normalized the way the client normalizes it.
	URL string `json:"url"`

	// Token sent as "Authorization: Bearer".
	Token string `json:"token,omitempty"`

	// TokenID is the identifier of that token on the server, so that logging
	// out can revoke it. Empty for a token pasted in by hand, whose id the
	// client was never told.
	TokenID string `json:"tokenId,omitempty"`

	// Username the token acts as, for display. The token is the credential.
	Username string `json:"username,omitempty"`

	// Insecure skips verifying the server's certificate. Off unless
	// "auth login --insecure" said so.
	Insecure bool `json:"insecure,omitempty"`

	// ReadOnly refuses every mutation through this profile before it is
	// sent. For a profile handed to a script or an agent that should be able
	// to look but not change. Off unless "auth login --read-only" or "auth
	// set-read-only" said so.
	ReadOnly bool `json:"readOnly,omitempty"`
}

Profile is one saved server.

type Profiles

type Profiles struct {
	Active   string              `json:"active,omitempty"`
	Profiles map[string]*Profile `json:"profiles"`
}

Profiles is the file.

func LoadProfiles

func LoadProfiles() (*Profiles, error)

LoadProfiles reads the file. A missing file is an empty set of profiles, which is the state before the first "auth login".

func (*Profiles) Find

func (self *Profiles) Find(name string) *Profile

Find returns the profile with this name, or nil.

func (*Profiles) FindByURL

func (self *Profiles) FindByURL(url string) *Profile

FindByURL returns the profile for this server, or nil. Compared after normalizing, so that "mail.example.com" finds "https://mail.example.com".

func (*Profiles) Names

func (self *Profiles) Names() []string

Names lists the profiles in a stable order.

func (*Profiles) Remove

func (self *Profiles) Remove(name string)

Remove forgets a profile. When it was the active one, the alphabetically first of the rest becomes active, so that a client with one profile left does not need to be told to switch to it.

func (*Profiles) Save

func (self *Profiles) Save() error

Save writes the file, readable by its owner only, atomically: an interrupted write leaves the previous file rather than half of a new one.

func (*Profiles) Set

func (self *Profiles) Set(profile *Profile)

Set stores a profile under its name and makes it the active one. A login is an act of choosing a server, so the one just signed in to is the one the next command should talk to.

Directories

Path Synopsis
Package server implements the subcommands of teanode-server: running the mail server, and the few operations that write the database directly rather than going through a running server.
Package server implements the subcommands of teanode-server: running the mail server, and the few operations that write the database directly rather than going through a running server.

Jump to

Keyboard shortcuts

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