cli

package
v0.0.0-...-08046e1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2018 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Registrar = map[CmdName](func() Command){}

Registrar is used to register command generators within the module.

Functions

func CredentialsPath

func CredentialsPath(
	ctx context.Context,
) (*string, error)

CredentialsPath returns the crendentials path for the current environment.

func Login

func Login(
	ctx context.Context,
	address string,
	password string,
) error

Login logs the user in by storing its credentials after valdation in CredentialsPath.

func Logout

func Logout(
	ctx context.Context,
) error

Logout logs the user out by destoying its credentials at CredentialsPath.

func WithCredentials

func WithCredentials(
	ctx context.Context,
	credentials *Credentials,
) context.Context

WithCredentials stores the credentials in the provided context.

Types

type Cli

type Cli struct {
	Ctx   context.Context
	Flags map[string]string
	Args  []string
}

Cli represents a cli instance.

func New

func New(
	argv []string,
) (*Cli, error)

New initializes a new Cli by parsing the passed arguments.

func (*Cli) Run

func (c *Cli) Run() error

Run the cli.

type CmdName

type CmdName string

CmdName represents a command name.

type Command

type Command interface {
	// Name returns the command name.
	Name() CmdName

	// Help prints out the help message for the command.
	Help(context.Context)

	// Parse the arguments passed to the command.
	Parse(context.Context, []string) error

	// Execute the command or return a human-friendly error.
	Execute(context.Context) error
}

Command is the interface for a cli command.

type ContextKey

type ContextKey string

ContextKey is the type of the key used with context to contextual data.

type Credentials

type Credentials struct {
	Username string `json:"username"`
	Host     string `json:"mint"`
	Password string `json:"password"`
}

Credentials rerpesents the credentials of the currently logged in user.

func CurrentUser

func CurrentUser(
	ctx context.Context,
) (*Credentials, error)

CurrentUser retrieves the current user by reading CredentialsPath.

func GetCredentials

func GetCredentials(
	ctx context.Context,
) *Credentials

GetCredentials returns the credentials currently stored in the context.

type Mint

type Mint struct {
	Host        string
	Credentials *Credentials
}

Mint represents a mint

func MintFromContextCredentials

func MintFromContextCredentials(
	ctx context.Context,
) (*Mint, error)

MintFromContextCredentials returns a mint object from the credentials stored in the current context.

func (*Mint) Get

func (m *Mint) Get(
	ctx context.Context,
	path string,
	query url.Values,
) (*int, *svc.Resp, error)

Get performs a GET request to the mint.

func (*Mint) Post

func (m *Mint) Post(
	ctx context.Context,
	path string,
	query url.Values,
	params url.Values,
) (*int, *svc.Resp, error)

Post performs a POST request to the mint.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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