Documentation ¶
Index ¶
- Constants
- Variables
- func CreateDirIfNotExists(dpath string) error
- func CreateHandler(cmdMap map[string]Command) (map[string]Command, error)
- func DeleteHandler(cmdMap map[string]Command) (map[string]Command, error)
- func ImportHandler(fpath string, isMerge bool, cmdMap map[string]Command, fileOps CmdFileOperater) (map[string]Command, error)
- func LoadCommands(fileOps CmdFileOperater) (map[string]Command, error)
- func ProcessAction(cmdMap map[string]Command, action Action, fileOps CmdFileOperater) (map[string]Command, error)
- func UpdateHandler(cmdMap map[string]Command) (map[string]Command, error)
- func ViewHandler(cmdMap map[string]Command) error
- type Action
- type CmdFileOperater
- type CmdFileOps
- type Command
Constants ¶
const CmdDirName = "cmdref"
CmdDirName is the name of the command directory for config storage.
const CmdFileName = "cmdref.json"
CmdFileName is the name of the file for command storage.
Variables ¶
var Actions = []string{"Create", "Update", "Remove", "View", "Import", "Exit"}
Actions is a list of strings representing all actions.
Functions ¶
func CreateDirIfNotExists ¶
CreateDirIfNotExists creates the given directory if it doesn't exist.
func CreateHandler ¶
CreateHandler handles the creation of a new command.
func DeleteHandler ¶
DeleteHandler handles the delete action.
func ImportHandler ¶
func ImportHandler(fpath string, isMerge bool, cmdMap map[string]Command, fileOps CmdFileOperater) (map[string]Command, error)
ImportHandler loads the commands from the given path, and either merges or replaces the command map with new commands.
func LoadCommands ¶
func LoadCommands(fileOps CmdFileOperater) (map[string]Command, error)
LoadCommands reads existing commands from the commands file.
func ProcessAction ¶
func ProcessAction(cmdMap map[string]Command, action Action, fileOps CmdFileOperater) (map[string]Command, error)
ProcessAction takes the command file path, command map and an action to invoke the action.
func UpdateHandler ¶
UpdateHandler handles the update action.
func ViewHandler ¶
ViewHandler handles viewing commands.
Types ¶
type Action ¶
type Action int
Action represents any action supported by the app.
const ( // Create action for creating a command Create Action = iota // Update action for updating an existing command Update // Remove action for removing a command Remove // View action for viewing a command View // Import action for importing commands from another file Import // Exit action for quitting the app Exit )
func GetSelectedAction ¶
GetSelectedAction returns the action the user chose from the prompt.
type CmdFileOperater ¶
type CmdFileOperater interface { Load() ([]Command, error) LoadExternal(filepath string) ([]Command, error) Save(commands []Command) error GetFilePath() string }
CmdFileOperater defines an interface for saving/loading commands from the commands file. This is needed to create mock operations for unit tests, along with a live implementation for the actual file.
type CmdFileOps ¶
type CmdFileOps struct{}
CmdFileOps implements the CommandsFileOperator for live/side-effectful operations on the commands file.
func NewCmdFileOps ¶
func NewCmdFileOps() CmdFileOps
NewCmdFileOps creates and returns a new file operations struct.
func (*CmdFileOps) GetFilePath ¶
func (f *CmdFileOps) GetFilePath() string
GetFilePath returns the absolute path to the commands file.
func (*CmdFileOps) Load ¶
func (f *CmdFileOps) Load() ([]Command, error)
Load parses the commands file and returns the list of commands.
func (*CmdFileOps) LoadExternal ¶
func (f *CmdFileOps) LoadExternal(filepath string) ([]Command, error)
LoadExternal parses the commands file and returns the list of commands.
func (*CmdFileOps) Save ¶
func (f *CmdFileOps) Save(commands []Command) error
Save writes the list of commands to the commands file.