Merged all 'set-X' commands into a single 'set-attr' command

This commit is contained in:
Leon Mika 2022-07-16 10:05:48 +10:00
parent 716adbdce5
commit 9fee17a6a6
9 changed files with 317 additions and 43 deletions

View file

@ -37,14 +37,12 @@ func (c *CommandController) Prompt() tea.Cmd {
}
func (c *CommandController) Execute(commandInput string) tea.Cmd {
log.Println("Received input: ", commandInput)
input := strings.TrimSpace(commandInput)
if input == "" {
return nil
}
tokens := shellwords.Split(input)
log.Println("Tokens: ", tokens)
command := c.lookupCommand(tokens[0])
if command == nil {
log.Println("No such command: ", tokens)
@ -54,6 +52,18 @@ func (c *CommandController) Execute(commandInput string) tea.Cmd {
return command(tokens[1:])
}
func (c *CommandController) Alias(commandName string) Command {
return func(args []string) tea.Cmd {
command := c.lookupCommand(commandName)
if command == nil {
log.Println("No such command: ", commandName)
return events.SetError(errors.New("no such command: " + commandName))
}
return command(args[1:])
}
}
func (c *CommandController) lookupCommand(name string) Command {
for ctx := c.commandList; ctx != nil; ctx = ctx.parent {
log.Printf("Looking in command list: %v", c.commandList)
@ -62,4 +72,4 @@ func (c *CommandController) lookupCommand(name string) Command {
}
}
return nil
}
}