Ejemplo n.º 1
0
func handleShellCommand(c *api.Context) (err error) {
	shell := c.Cursh
	cmdname := api.SplitArgN(c.Line, " ", 2)[0]
	defer func() {
		if r := recover(); r != nil {
			fmt.Fprintf(c.W, "Recovered from %q: %v\n", cmdname, r)
			fmt.Println(string(debug.Stack()))
		}
	}()
	if !api.IsCommand(cmdname, c.ShellCommands(shell.Name())) {
		return fmt.Errorf("Invalid command: %v", cmdname)
	}
	if cmd := shell.GetCommand(cmdname); cmd == nil {
		err = fmt.Errorf(
			"Command %q not supported in %v", cmdname, api.SHELL_CB)
	} else {
		err = cmd.Interpret(c)
	}
	return
}
Ejemplo n.º 2
0
func (cmd *CommandsCommand) Interpret(c *api.Context) (err error) {
	for name, cmd := range c.ShellCommands(c.Cursh.Name()) {
		fmt.Fprintf(c.W, "  %-15v %v\n", name, cmd.Description())
	}
	return
}