Skip to content

Commit

Permalink
minor update to how resolveScript works to allow 'show' command to di…
Browse files Browse the repository at this point in the history
…stinguish bare playbooks vs scriptnames
  • Loading branch information
sawka committed May 29, 2022
1 parent 02d9ee4 commit 3ee27aa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ func resolveScript(cmdName string, scriptName string, curPlaybookFile string, al
if playFile == "" {
playFile = "."
}
if playScript == "" {
if !allowBarePlaybook && playScript == "" {
return emptyRtn, fmt.Errorf("playbook script name cannot be empty")
}
if !mdparser.IsValidScriptName(playScript) {
if playScript != "" && !mdparser.IsValidScriptName(playScript) {
return emptyRtn, fmt.Errorf("invalid characters in playbook script name '%s'", playScript)
}
return commanddef.ScriptDef{PlaybookFile: playFile, PlaybookScript: playScript}, nil
Expand Down
6 changes: 6 additions & 0 deletions pkg/pathutil/pathutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,19 @@ func SplitScriptName(scriptName string) (string, string, error) {
fields := strings.SplitN(scriptName, "::", 2)
return fields[0], fields[1], nil
}
if strings.HasSuffix(scriptName, ".md") {
return scriptName, "", nil
}
if strings.HasPrefix(scriptName, "^") {
return "^", scriptName[1:], nil
}
m := dotPrefixRe.FindStringSubmatch(scriptName)
if m != nil {
return m[1], scriptName[len(m[1]):], nil
}
if strings.HasPrefix(scriptName, ".") {
return scriptName, "", nil
}
return "", scriptName, nil
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/pathutil/pathutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ func TestSplitScriptName(t *testing.T) {
trySplit(t, "@sawka::foo", "@sawka", "foo")
trySplit(t, ".hello.md::test", ".hello.md", "test")
trySplit(t, "./foo.md::bar", "./foo.md", "bar")
trySplit(t, ".", ".", "")
trySplit(t, "..", "..", "")
trySplit(t, "^", "^", "")
trySplit(t, "^foo.md", "^foo.md", "")
trySplit(t, "^sub/test.md", "^sub/test.md", "")
trySplit(t, ".foo.md", ".foo.md", "")
trySplit(t, "test.md", "test.md", "")
trySplit(t, "./test.md", "./test.md", "")
trySplit(t, "../test.md", "../test.md", "")
trySplit(t, "/home/test.md", "/home/test.md", "")
}

func tryResolve(t *testing.T, resolver Resolver, input string, goodResolve string, shouldError bool) {
Expand Down

0 comments on commit 3ee27aa

Please sign in to comment.