commander

package
v0.0.0-...-b0fec18 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CmdStrOpen     = "open '{{ .Repo.HTMLURL }}'"
	CmdStrGitClone = "git clone '{{ .Repo.CloneSSHURL }}' '{{ .CloneDir }}'"
	CmdStrExit     = ":Exit '{{ .CloneDir }}'"
)

Variables

This section is empty.

Functions

func MatchesActionSyntax

func MatchesActionSyntax(s string) bool

MatchesActionSyntax checks if a string matches the syntax for an app action. this is a colon followed by a command.

Types

type Action

type Action struct {
	Mode Mode
	// contains filtered or unexported fields
}

func (*Action) ExitMessage

func (a *Action) ExitMessage() string

ExitMessage returns the message to display when the action is an exit action.

func (*Action) GoRun

func (a *Action) GoRun() <-chan error

GoRun runs the action within a go-routine and returns an err-channel that will be closed when the action is finished with the resulting error if any.

func (*Action) IsExec

func (a *Action) IsExec() (*exec.Cmd, bool)

IsExec returns true if the action is an exec action. It will also return the underlying exec.Cmd object.

func (*Action) IsExit

func (a *Action) IsExit() bool

IsExit returns true if the action is an exit action. If true, the ExitMessage will contain the message to display.

func (*Action) OnFinished

func (s *Action) OnFinished(fn func()) *Action

func (*Action) SetWriter

func (a *Action) SetWriter(w io.Writer) *Action

type ActionCommand

type ActionCommand interface {
	Run() error
	SetWriter(w io.Writer)
}

type ActionCommandBuilder

type ActionCommandBuilder interface {
	Build(cmd string, args ...string) ActionCommand
}

type AppAction

type AppAction string
const (
	AppActionFork AppAction = ":GitFork"
	AppActionExit AppAction = ":Exit"
)

func ParseAppAction

func ParseAppAction(s string) (a AppAction, rest string, ok bool)

func (AppAction) IsValid

func (c AppAction) IsValid() bool

func (AppAction) String

func (c AppAction) String() string

type Commander

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

func New

func New(bindings KeyBindings, rfs *repofs.RepoFS, bldr ActionCommandBuilder) *Commander

func (*Commander) Bindings

func (c *Commander) Bindings() KeyBindings

func (*Commander) GetAction

func (c *Commander) GetAction(key string, repo repos.Repository) (action *Action, ok bool)

GetAction returns an action for a given key binding. If the key binding is not found, it will attempt to render the command template and return an action with the rendered command.

Special Cases

  • ":Exit" - If the command starts with ":Exit", we return an exit action with the message that follows the command.

type KeyBindings

type KeyBindings map[string]KeyCommand

func NewDefaultKeyBindings

func NewDefaultKeyBindings() KeyBindings

func (KeyBindings) Validate

func (k KeyBindings) Validate() error

type KeyCommand

type KeyCommand struct {
	Cmd  string `toml:"cmd"`
	Desc string `toml:"desc"`
	Mode Mode   `toml:"mode"`
}

KeyCommand defines a key binding command that can be executed by the Commander

func (KeyCommand) IsValid

func (k KeyCommand) IsValid() error

func (KeyCommand) String

func (k KeyCommand) String() string

type Mode

type Mode string
const (
	ModeBackground  Mode = "background"
	ModeReadOnly    Mode = "readonly"
	ModeInteractive Mode = "interactive"
)

type ShellCommandBuilder

type ShellCommandBuilder struct {
	Shell        string
	ShellCmdFlag string
}

ShellCommandBulder implements the ActionCommandBuilder interface for shell commands. It returns a new ActionCommand that will execute the given command with the given arguments in a shell using the exec package.

func (*ShellCommandBuilder) Build

func (s *ShellCommandBuilder) Build(cmd string, args ...string) ActionCommand

Build implements ActionCommandBuilder.

Jump to

Keyboard shortcuts

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