app

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2018 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package app contains functionality related to creating an interactive command-line interface environment with all the necessary dependencies.

The goal of the app package is to provide a single, reusable base for building client-only MOTKI CLI applications.

This package imports every other motki/cli package. As such, it cannot be imported from the "library" portion of the project. It is intended to be used from external packages only. For a real example of this, check the motki command source code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CLIConfig

type CLIConfig struct {
	*app.Config
	// contains filtered or unexported fields
}

CLIConfig wraps an app.Config and contains optional credentials.

func NewCLIConfig

func NewCLIConfig(base *Config) CLIConfig

NewCLIConfig creates a CLI-specific configuration using the given conf.

func (CLIConfig) WithCredentials

func (c CLIConfig) WithCredentials(username, password string) CLIConfig

WithCredentials returns a copy of the CLIConfig with the given credentials embedded.

type CLIEnv

type CLIEnv struct {
	*app.ClientEnv
	CLI      *cli.Server
	Prompter *cli.Prompter
	// contains filtered or unexported fields
}

A CLIEnv wraps a ClientEnv, providing CLI specific facilities.

func NewCLIEnv

func NewCLIEnv(conf CLIConfig, historyPath string) (*CLIEnv, error)

NewCLIEnv initializes a new CLI environment.

If the given CLIConfig contains a username or password, authentication will be attempted. If authentication fails, an error is returned.

func (*CLIEnv) BlockUntilSignal

func (env *CLIEnv) BlockUntilSignal(s chan os.Signal)

BlockUntilSignal will block until it receives the signals signal.

This function attempts to perform a graceful shutdown, shutting down all related services and doing whatever clean up processes are necessary.

func (*CLIEnv) LoopCLI

func (env *CLIEnv) LoopCLI()

LoopCLI starts an endless loop to perform commands read from stdin.

This function is intended to be started in a goroutine. The loop will end when the application exits or when the associated Env receives an abort signal. Use this method in combination with env.BlockUntilSignal() for clean exits.

env, err := app.NewCLIEnv(conf, "")
// handle err...

go env.LoopCLI()

env.BlockUntilSignal()

type Config

type Config = app.Config

Config represents the configuration of a MOTKI Env.

This exists as a type alias so that packages depending on this package do not need to import both "github.com/motki/core/app" and "github.com/motki/cli/app".

Jump to

Keyboard shortcuts

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