From c3a78bfc39cb262c087a3e3a3a5da72fa77ea5e8 Mon Sep 17 00:00:00 2001 From: Julian Fahrer Date: Sun, 7 Jul 2019 17:23:37 -0700 Subject: [PATCH] Strip the path of the command to execute --- parser.go | 4 +++- parser_test.go | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/parser.go b/parser.go index ea2394b..3540ec2 100644 --- a/parser.go +++ b/parser.go @@ -3,6 +3,7 @@ package main import ( "errors" "fmt" + "path" ) // ErrInvalidHandler is thrown if any handler that is unknown to the program is specified @@ -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 diff --git a/parser_test.go b/parser_test.go index 08c2caa..2440e15 100644 --- a/parser_test.go +++ b/parser_test.go @@ -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) }