cli

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package cli is the application entry point.

Index

Constants

View Source
const AppName = "tmpl"

AppName is the name of the CLI application.

Variables

View Source
var (
	ErrHelp    = errors.New("help requested")
	ErrVersion = errors.New("version requested")
)
View Source
var ErrInvalidConfig = fmt.Errorf("invalid configuration")

ErrInvalidConfig is returned when a configuration is invalid.

Functions

func BuildCommit

func BuildCommit() string

BuildCommit returns the git commit hash tmpl was built from.

Returns `HEAD` if no build commit is set.

func BuildGoVersion

func BuildGoVersion() string

BuildGoVersion returns the go version tmpl was built with.

Returns version from runtime.Version if not set.

func BuildTime

func BuildTime() string

BuildTime returns the UTC time tmpl was built.

Returns current time in UTC if not set.

func Version

func Version() string

Version of tmpl.

Returns `0.0.0-dev` if no version is set.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App is the main command-line application.

The application orchestrates the loading of options and configuration, and applying the configuration to a new tmux session.

The application can be configured with options to facilitate testing, such as providing a writer for output instead of os.Stdout, or providing a pre-loaded configuration instead of loading it from a configuration file.

func NewApp

func NewApp(opts ...AppOption) (*App, error)

NewApp creates a new command-line application.

func (*App) Run

func (a *App) Run(ctx context.Context, args ...string) error

Run runs the command-line application.

Different logic is performed dependening on the sub-command provided as the first command-line argument.

type AppOption

type AppOption func(*App) error

AppOptions configures an App.

func WithConfig

func WithConfig(cfg *config.Config) AppOption

WithConfig configures the App to use provided configuration instead of loading it from a configuration file.

This option is intended for testing purposes only.

func WithOptions

func WithOptions(opts *options) AppOption

WithOptions configures the App to use provided options instead of parsing command-line flags.

This option is intended for testing purposes only.

func WithOutputWriter

func WithOutputWriter(w io.Writer) AppOption

WithOutputWriter configures the App to use provided writer for output instead of os.Stdout.

This option is intended for testing purposes only.

func WithSlogAttrReplacer

func WithSlogAttrReplacer(f func([]string, slog.Attr) slog.Attr) AppOption

WithSlogAttrReplacer configures the App to use provided function for replacing slog attributes.

This option is intended for testing purposes only.

func WithTmux

func WithTmux(tm tmux.Runner) AppOption

WithTmux configures the App to use provided tmux runner instead of the constructing a new one from configuration.

This option is intended for testing purposes only.

Jump to

Keyboard shortcuts

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