Skip to content

Commit

Permalink
Strip the path of the command to execute
Browse files Browse the repository at this point in the history
  • Loading branch information
jfahrer committed Jul 10, 2019
1 parent 9eb6ae5 commit c3a78bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"errors"
"fmt"
"path"
)

// ErrInvalidHandler is thrown if any handler that is unknown to the program is specified
Expand Down Expand Up @@ -55,7 +56,8 @@ func GenerateConfig(file []byte) (*Cfg, error) {

// GetHandlerFor will try to find a handler for the specified command
func (cfg *Cfg) GetHandlerFor(command string, strictMode bool) (Handler, error) {
if handler, ok := cfg.commands[command]; ok {
executable := path.Base(command)
if handler, ok := cfg.commands[executable]; ok {
return handler, nil
} else if strictMode {
return nil, ErrUndefinedCommand
Expand Down
5 changes: 5 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ func TestGetHandlerFor(t *testing.T) {
handler, err = cfg.GetHandlerFor("some-cmd", false)
assert.NoError(t, err)
assert.NotNil(t, handler)

// When specifying a path to the command
handler, err = cfg.GetHandlerFor("/bin/ls", true)
assert.NoError(t, err)
assert.NotNil(t, handler)
}

0 comments on commit c3a78bf

Please sign in to comment.