Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion acceptance/cmd/skills/read/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ Read the guide in references for details.

Other files in this skill, each read with its command:
databricks skills read-file guide-skill references/guide.md
databricks skills read-file -- guide-skill -notes.md

=== A file whose name starts with a hyphen: the printed command ends the flags and runs as printed

>>> eval databricks skills read-file -- guide-skill -notes.md
Notes that start with a hyphen.

=== read-file accepts -- before a leading-hyphen file name

>>> [CLI] skills read-file -- guide-skill -notes.md
Notes that start with a hyphen.

=== A skill without supporting files

Expand All @@ -33,7 +44,8 @@ description: A skill for tests.
"source": "[TESTROOT]/cmd/skills/read/../release",
"content": "---\nname: guide-skill\ndescription: A skill with a supporting file.\n---\n\n# Guide skill\n\nRead the guide in references for details.\n",
"files": [
"references/guide.md"
"references/guide.md",
"-notes.md"
]
}

Expand Down
9 changes: 9 additions & 0 deletions acceptance/cmd/skills/read/script
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ export DATABRICKS_SKILLS_DIR=$TESTDIR/../release
title "A skill with a supporting file: SKILL.md, then the file list"
trace $CLI skills read guide-skill

title "A file whose name starts with a hyphen: the printed command ends the flags and runs as printed"
databricks() { "$CLI" "$@"; }
line="databricks skills read-file -- guide-skill -notes.md"
$CLI skills read guide-skill | contains.py " $line" > LOG.read
trace eval "$line"

title "read-file accepts -- before a leading-hyphen file name"
trace $CLI skills read-file -- guide-skill -notes.md

title "A skill without supporting files"
trace $CLI skills read demo-skill

Expand Down
2 changes: 1 addition & 1 deletion acceptance/cmd/skills/release/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": "0.0.1",
"skills": {
"demo-skill": {"version": "0.0.1", "description": "A skill for tests.", "files": ["SKILL.md"], "commands": ["fs", "air"]},
"guide-skill": {"version": "0.0.1", "description": "A skill with a supporting file.", "files": ["SKILL.md", "references/guide.md"]},
"guide-skill": {"version": "0.0.1", "description": "A skill with a supporting file.", "files": ["SKILL.md", "references/guide.md", "-notes.md"]},
"future-skill": {"version": "0.0.1", "description": "A skill that needs a newer CLI.", "files": ["SKILL.md"], "min_cli_version": "99.0.0"}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Notes that start with a hyphen.
7 changes: 6 additions & 1 deletion cmd/skills/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ func writeReadText(w io.Writer, goos, name string, content []byte, files []strin
fmt.Fprintf(&b, " %s\n", f)
continue
}
fmt.Fprintf(&b, " databricks skills read-file %s %s\n", quotedName, quotedFile)
// A leading "-" would make Cobra read the name or file as a flag, so "--" ends the flags first.
endOfFlags := ""
if strings.HasPrefix(name, "-") || strings.HasPrefix(f, "-") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Question] Did you run the printed databricks skills read-file -- guide-skill -notes.md line in Windows PowerShell 5.1? Windows PowerShell can change native arguments that start with -, and the Windows CI runs the acceptance script in bash. The answer tells if the printed command runs as printed on Windows.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I did not run the printed command in Windows PowerShell 5.1, and this environment has no Windows PowerShell. The Windows CI runs the acceptance script in bash, so it does not cover PowerShell either. The Windows unit test only checks the printed text. This is unverified, and I made no code change for it. The printed form is the one the ticket asks for.

endOfFlags = "-- "
}
fmt.Fprintf(&b, " databricks skills read-file %s%s %s\n", endOfFlags, quotedName, quotedFile)
}
}
_, err := io.WriteString(w, b.String())
Expand Down
22 changes: 22 additions & 0 deletions cmd/skills/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@ func TestWriteReadTextQuotesFileCommands(t *testing.T) {
assert.Contains(t, out.String(), " databricks skills read-file guide-skill \"references/my guide.md\"\n")
}

func TestWriteReadTextEndsFlagsBeforeLeadingHyphenFile(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] No case uses a leading-hyphen value that also needs quotes, for example -my notes.md. If the check later uses quotedFile or quotedName, all current cases still pass. Add a case with such a file for linux and windows, as TestWriteReadTextQuotesFileCommands does.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in c18cfe7: TestWriteReadTextEndsFlagsBeforeLeadingHyphenFile now covers a leading-hyphen file that needs quotes, -my notes.md, for Linux ('-my notes.md') and Windows ("-my notes.md"). The check uses the raw name and path, so the -- branch is the same for quoted values.

var out bytes.Buffer
err := writeReadText(&out, "linux", "guide-skill", []byte("# Guide\n"), []string{"-notes.md", "references/ok.md"})
require.NoError(t, err)
assert.Contains(t, out.String(), " databricks skills read-file -- guide-skill -notes.md\n databricks skills read-file guide-skill references/ok.md\n")

out.Reset()
err = writeReadText(&out, "linux", "-guide-skill", []byte("# Guide\n"), []string{"references/ok.md"})
require.NoError(t, err)
assert.Contains(t, out.String(), " databricks skills read-file -- -guide-skill references/ok.md\n")

out.Reset()
err = writeReadText(&out, "linux", "guide-skill", []byte("# Guide\n"), []string{"-my notes.md"})
require.NoError(t, err)
assert.Contains(t, out.String(), " databricks skills read-file -- guide-skill '-my notes.md'\n")

out.Reset()
err = writeReadText(&out, "windows", "guide-skill", []byte("# Guide\n"), []string{"-my notes.md"})
require.NoError(t, err)
assert.Contains(t, out.String(), " databricks skills read-file -- guide-skill \"-my notes.md\"\n")
}

func TestWriteReadTextPrintsPathWithoutCommandWhenItCannotBeQuoted(t *testing.T) {
var out bytes.Buffer
err := writeReadText(&out, "linux", "guide-skill", []byte("# Guide\n"), []string{"references/a\nb.md", "references/ok.md"})
Expand Down
Loading