From 4243c2ae6705d4d6cc9d1cca4b793e1061ebc859 Mon Sep 17 00:00:00 2001 From: "simon.faltum" Date: Fri, 27 Nov 2026 14:06:17 +0000 Subject: [PATCH 1/4] cmd/skills: end flags before a leading-hyphen file in read output `skills read` printed `databricks skills read-file ` for each supporting file. A name or path that starts with "-" was read by Cobra as a flag when the agent ran the printed command. Print "--" before the arguments when the name or the file starts with "-". Ordinary names print as before. Co-authored-by: Isaac --- acceptance/cmd/skills/hyphen/manifest.json | 6 +++++ acceptance/cmd/skills/hyphen/out.test.toml | 1 + acceptance/cmd/skills/hyphen/output.txt | 23 +++++++++++++++++++ acceptance/cmd/skills/hyphen/script | 11 +++++++++ .../skills/hyphen/skills/demo-skill/-notes.md | 1 + .../skills/hyphen/skills/demo-skill/SKILL.md | 6 +++++ acceptance/cmd/skills/hyphen/test.toml | 3 +++ cmd/skills/read.go | 7 +++++- cmd/skills/read_test.go | 12 ++++++++++ 9 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 acceptance/cmd/skills/hyphen/manifest.json create mode 100644 acceptance/cmd/skills/hyphen/out.test.toml create mode 100644 acceptance/cmd/skills/hyphen/output.txt create mode 100644 acceptance/cmd/skills/hyphen/script create mode 100644 acceptance/cmd/skills/hyphen/skills/demo-skill/-notes.md create mode 100644 acceptance/cmd/skills/hyphen/skills/demo-skill/SKILL.md create mode 100644 acceptance/cmd/skills/hyphen/test.toml diff --git a/acceptance/cmd/skills/hyphen/manifest.json b/acceptance/cmd/skills/hyphen/manifest.json new file mode 100644 index 00000000000..7aff125e539 --- /dev/null +++ b/acceptance/cmd/skills/hyphen/manifest.json @@ -0,0 +1,6 @@ +{ + "version": "0.0.1", + "skills": { + "demo-skill": {"version": "0.0.1", "description": "A skill with a file named with a leading hyphen.", "files": ["SKILL.md", "-notes.md"]} + } +} diff --git a/acceptance/cmd/skills/hyphen/out.test.toml b/acceptance/cmd/skills/hyphen/out.test.toml new file mode 100644 index 00000000000..18b1a88417e --- /dev/null +++ b/acceptance/cmd/skills/hyphen/out.test.toml @@ -0,0 +1 @@ +Cloud = false diff --git a/acceptance/cmd/skills/hyphen/output.txt b/acceptance/cmd/skills/hyphen/output.txt new file mode 100644 index 00000000000..e543d5b4797 --- /dev/null +++ b/acceptance/cmd/skills/hyphen/output.txt @@ -0,0 +1,23 @@ + +=== the read output prints the command for -notes.md after -- + +>>> [CLI] skills read demo-skill +--- +name: demo-skill +description: A skill with a file named with a leading hyphen. +--- + +# Demo skill + +Other files in this skill, each read with its command: + databricks skills read-file -- demo-skill -notes.md + +=== the printed command runs as printed and prints the file + +>>> eval databricks skills read-file -- demo-skill -notes.md +Notes that start with a hyphen. + +=== read-file with -- reads the file directly + +>>> [CLI] skills read-file -- demo-skill -notes.md +Notes that start with a hyphen. diff --git a/acceptance/cmd/skills/hyphen/script b/acceptance/cmd/skills/hyphen/script new file mode 100644 index 00000000000..22e9d59ab4a --- /dev/null +++ b/acceptance/cmd/skills/hyphen/script @@ -0,0 +1,11 @@ +# The printed read-file command ends the flags, so a file named -notes.md is read. +title "the read output prints the command for -notes.md after --" +trace $CLI skills read demo-skill + +title "the printed command runs as printed and prints the file" +databricks() { "$CLI" "$@"; } +line=$($CLI skills read demo-skill | grep -- '-notes.md') +trace eval "$line" + +title "read-file with -- reads the file directly" +trace $CLI skills read-file -- demo-skill -notes.md diff --git a/acceptance/cmd/skills/hyphen/skills/demo-skill/-notes.md b/acceptance/cmd/skills/hyphen/skills/demo-skill/-notes.md new file mode 100644 index 00000000000..8655544cc84 --- /dev/null +++ b/acceptance/cmd/skills/hyphen/skills/demo-skill/-notes.md @@ -0,0 +1 @@ +Notes that start with a hyphen. diff --git a/acceptance/cmd/skills/hyphen/skills/demo-skill/SKILL.md b/acceptance/cmd/skills/hyphen/skills/demo-skill/SKILL.md new file mode 100644 index 00000000000..2ef8ee6ba8e --- /dev/null +++ b/acceptance/cmd/skills/hyphen/skills/demo-skill/SKILL.md @@ -0,0 +1,6 @@ +--- +name: demo-skill +description: A skill with a file named with a leading hyphen. +--- + +# Demo skill diff --git a/acceptance/cmd/skills/hyphen/test.toml b/acceptance/cmd/skills/hyphen/test.toml new file mode 100644 index 00000000000..f7c4cc2e00e --- /dev/null +++ b/acceptance/cmd/skills/hyphen/test.toml @@ -0,0 +1,3 @@ +Cloud = false +Env.DATABRICKS_SKILLS_PREVIEW = "1" +Env.DATABRICKS_SKILLS_DIR = "." diff --git a/cmd/skills/read.go b/cmd/skills/read.go index 09ba8b617c0..ed4c253430c 100644 --- a/cmd/skills/read.go +++ b/cmd/skills/read.go @@ -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, "-") { + endOfFlags = "-- " + } + fmt.Fprintf(&b, " databricks skills read-file %s%s %s\n", endOfFlags, quotedName, quotedFile) } } _, err := io.WriteString(w, b.String()) diff --git a/cmd/skills/read_test.go b/cmd/skills/read_test.go index cde69b0efa6..23f8ea9da0e 100644 --- a/cmd/skills/read_test.go +++ b/cmd/skills/read_test.go @@ -27,6 +27,18 @@ 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) { + 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") +} + 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"}) From 2a5b94f28108eb524ea304f11c730047dc749f79 Mon Sep 17 00:00:00 2001 From: "simon.faltum" Date: Fri, 27 Nov 2026 14:44:25 +0000 Subject: [PATCH 2/4] cmd/skills: cover a leading-hyphen file in the read acceptance test Move the printed read-file case into the existing read acceptance test, using the shared release fixture, instead of a separate hyphen directory. The printed command is asserted with contains.py before it is run, and the separate test.toml is dropped because the parent directory sets the same variables. Co-authored-by: Isaac --- acceptance/cmd/skills/hyphen/manifest.json | 6 ----- acceptance/cmd/skills/hyphen/out.test.toml | 1 - acceptance/cmd/skills/hyphen/output.txt | 23 ------------------- acceptance/cmd/skills/hyphen/script | 11 --------- .../skills/hyphen/skills/demo-skill/SKILL.md | 6 ----- acceptance/cmd/skills/hyphen/test.toml | 3 --- acceptance/cmd/skills/read/output.txt | 14 ++++++++++- acceptance/cmd/skills/read/script | 9 ++++++++ acceptance/cmd/skills/release/manifest.json | 2 +- .../skills/guide-skill}/-notes.md | 0 10 files changed, 23 insertions(+), 52 deletions(-) delete mode 100644 acceptance/cmd/skills/hyphen/manifest.json delete mode 100644 acceptance/cmd/skills/hyphen/out.test.toml delete mode 100644 acceptance/cmd/skills/hyphen/output.txt delete mode 100644 acceptance/cmd/skills/hyphen/script delete mode 100644 acceptance/cmd/skills/hyphen/skills/demo-skill/SKILL.md delete mode 100644 acceptance/cmd/skills/hyphen/test.toml rename acceptance/cmd/skills/{hyphen/skills/demo-skill => release/skills/guide-skill}/-notes.md (100%) diff --git a/acceptance/cmd/skills/hyphen/manifest.json b/acceptance/cmd/skills/hyphen/manifest.json deleted file mode 100644 index 7aff125e539..00000000000 --- a/acceptance/cmd/skills/hyphen/manifest.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "version": "0.0.1", - "skills": { - "demo-skill": {"version": "0.0.1", "description": "A skill with a file named with a leading hyphen.", "files": ["SKILL.md", "-notes.md"]} - } -} diff --git a/acceptance/cmd/skills/hyphen/out.test.toml b/acceptance/cmd/skills/hyphen/out.test.toml deleted file mode 100644 index 18b1a88417e..00000000000 --- a/acceptance/cmd/skills/hyphen/out.test.toml +++ /dev/null @@ -1 +0,0 @@ -Cloud = false diff --git a/acceptance/cmd/skills/hyphen/output.txt b/acceptance/cmd/skills/hyphen/output.txt deleted file mode 100644 index e543d5b4797..00000000000 --- a/acceptance/cmd/skills/hyphen/output.txt +++ /dev/null @@ -1,23 +0,0 @@ - -=== the read output prints the command for -notes.md after -- - ->>> [CLI] skills read demo-skill ---- -name: demo-skill -description: A skill with a file named with a leading hyphen. ---- - -# Demo skill - -Other files in this skill, each read with its command: - databricks skills read-file -- demo-skill -notes.md - -=== the printed command runs as printed and prints the file - ->>> eval databricks skills read-file -- demo-skill -notes.md -Notes that start with a hyphen. - -=== read-file with -- reads the file directly - ->>> [CLI] skills read-file -- demo-skill -notes.md -Notes that start with a hyphen. diff --git a/acceptance/cmd/skills/hyphen/script b/acceptance/cmd/skills/hyphen/script deleted file mode 100644 index 22e9d59ab4a..00000000000 --- a/acceptance/cmd/skills/hyphen/script +++ /dev/null @@ -1,11 +0,0 @@ -# The printed read-file command ends the flags, so a file named -notes.md is read. -title "the read output prints the command for -notes.md after --" -trace $CLI skills read demo-skill - -title "the printed command runs as printed and prints the file" -databricks() { "$CLI" "$@"; } -line=$($CLI skills read demo-skill | grep -- '-notes.md') -trace eval "$line" - -title "read-file with -- reads the file directly" -trace $CLI skills read-file -- demo-skill -notes.md diff --git a/acceptance/cmd/skills/hyphen/skills/demo-skill/SKILL.md b/acceptance/cmd/skills/hyphen/skills/demo-skill/SKILL.md deleted file mode 100644 index 2ef8ee6ba8e..00000000000 --- a/acceptance/cmd/skills/hyphen/skills/demo-skill/SKILL.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -name: demo-skill -description: A skill with a file named with a leading hyphen. ---- - -# Demo skill diff --git a/acceptance/cmd/skills/hyphen/test.toml b/acceptance/cmd/skills/hyphen/test.toml deleted file mode 100644 index f7c4cc2e00e..00000000000 --- a/acceptance/cmd/skills/hyphen/test.toml +++ /dev/null @@ -1,3 +0,0 @@ -Cloud = false -Env.DATABRICKS_SKILLS_PREVIEW = "1" -Env.DATABRICKS_SKILLS_DIR = "." diff --git a/acceptance/cmd/skills/read/output.txt b/acceptance/cmd/skills/read/output.txt index 1b298027865..c046e6dce10 100644 --- a/acceptance/cmd/skills/read/output.txt +++ b/acceptance/cmd/skills/read/output.txt @@ -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 @@ -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" ] } diff --git a/acceptance/cmd/skills/read/script b/acceptance/cmd/skills/read/script index 99d41334672..a4374f2f307 100644 --- a/acceptance/cmd/skills/read/script +++ b/acceptance/cmd/skills/read/script @@ -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" > /dev/null +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 diff --git a/acceptance/cmd/skills/release/manifest.json b/acceptance/cmd/skills/release/manifest.json index 0281c53fe69..5d5b05b1e7d 100644 --- a/acceptance/cmd/skills/release/manifest.json +++ b/acceptance/cmd/skills/release/manifest.json @@ -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"} } } diff --git a/acceptance/cmd/skills/hyphen/skills/demo-skill/-notes.md b/acceptance/cmd/skills/release/skills/guide-skill/-notes.md similarity index 100% rename from acceptance/cmd/skills/hyphen/skills/demo-skill/-notes.md rename to acceptance/cmd/skills/release/skills/guide-skill/-notes.md From c18cfe76b5e517354e34763d1534863ee772a739 Mon Sep 17 00:00:00 2001 From: "simon.faltum" Date: Fri, 27 Nov 2026 17:14:44 +0000 Subject: [PATCH 3/4] skills: end flags in the help hint for a leading-hyphen skill name The help footer printed the skill name unquoted, so a skill named with a leading hyphen was read by Cobra as a flag. Print "--" first in that case. Also add a quoted leading-hyphen file case and send the acceptance check's output to LOG.read. Co-authored-by: Isaac --- acceptance/cmd/skills/read/script | 2 +- cmd/skills/read_test.go | 10 ++++++++++ libs/skills/hints.go | 12 +++++++++++- libs/skills/hints_test.go | 5 +++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/acceptance/cmd/skills/read/script b/acceptance/cmd/skills/read/script index a4374f2f307..432f42823af 100644 --- a/acceptance/cmd/skills/read/script +++ b/acceptance/cmd/skills/read/script @@ -7,7 +7,7 @@ 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" > /dev/null +$CLI skills read guide-skill | contains.py " $line" > LOG.read trace eval "$line" title "read-file accepts -- before a leading-hyphen file name" diff --git a/cmd/skills/read_test.go b/cmd/skills/read_test.go index 23f8ea9da0e..5af1faa587b 100644 --- a/cmd/skills/read_test.go +++ b/cmd/skills/read_test.go @@ -37,6 +37,16 @@ func TestWriteReadTextEndsFlagsBeforeLeadingHyphenFile(t *testing.T) { 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) { diff --git a/libs/skills/hints.go b/libs/skills/hints.go index ddeabb95118..340dcb3182b 100644 --- a/libs/skills/hints.go +++ b/libs/skills/hints.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "slices" + "strings" "github.com/databricks/cli/libs/log" ) @@ -49,6 +50,15 @@ func WriteGroupHint(ctx context.Context, w io.Writer, group string) { fmt.Fprintln(w) fmt.Fprintln(w, "Coding agents: read the skills for this command group before you use it.") for _, name := range names { - fmt.Fprintf(w, " databricks skills read %s\n", name) + fmt.Fprintf(w, " %s\n", hintReadCommand(name)) } } + +// hintReadCommand returns the command that reads the skill named name. A name +// that starts with "-" gets "--" first, so Cobra does not read it as a flag. +func hintReadCommand(name string) string { + if strings.HasPrefix(name, "-") { + return "databricks skills read -- " + name + } + return "databricks skills read " + name +} diff --git a/libs/skills/hints_test.go b/libs/skills/hints_test.go index 69ddd731676..df69b68ed9e 100644 --- a/libs/skills/hints_test.go +++ b/libs/skills/hints_test.go @@ -36,3 +36,8 @@ func TestWriteGroupHint(t *testing.T) { }) } } + +func TestHintReadCommand(t *testing.T) { + assert.Equal(t, "databricks skills read alpha", hintReadCommand("alpha")) + assert.Equal(t, "databricks skills read -- -alpha", hintReadCommand("-alpha")) +} From e73a6a04f850ded4aa9a53111322898d1158dc50 Mon Sep 17 00:00:00 2001 From: "simon.faltum" Date: Fri, 27 Nov 2026 17:16:51 +0000 Subject: [PATCH 4/4] skills: leave the help footer to the stacked change The help footer's leading-hyphen handling moves to the stacked pull request that owns the footer, so this branch no longer changes libs/skills. Co-authored-by: Isaac --- libs/skills/hints.go | 12 +----------- libs/skills/hints_test.go | 5 ----- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/libs/skills/hints.go b/libs/skills/hints.go index 340dcb3182b..ddeabb95118 100644 --- a/libs/skills/hints.go +++ b/libs/skills/hints.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "slices" - "strings" "github.com/databricks/cli/libs/log" ) @@ -50,15 +49,6 @@ func WriteGroupHint(ctx context.Context, w io.Writer, group string) { fmt.Fprintln(w) fmt.Fprintln(w, "Coding agents: read the skills for this command group before you use it.") for _, name := range names { - fmt.Fprintf(w, " %s\n", hintReadCommand(name)) + fmt.Fprintf(w, " databricks skills read %s\n", name) } } - -// hintReadCommand returns the command that reads the skill named name. A name -// that starts with "-" gets "--" first, so Cobra does not read it as a flag. -func hintReadCommand(name string) string { - if strings.HasPrefix(name, "-") { - return "databricks skills read -- " + name - } - return "databricks skills read " + name -} diff --git a/libs/skills/hints_test.go b/libs/skills/hints_test.go index df69b68ed9e..69ddd731676 100644 --- a/libs/skills/hints_test.go +++ b/libs/skills/hints_test.go @@ -36,8 +36,3 @@ func TestWriteGroupHint(t *testing.T) { }) } } - -func TestHintReadCommand(t *testing.T) { - assert.Equal(t, "databricks skills read alpha", hintReadCommand("alpha")) - assert.Equal(t, "databricks skills read -- -alpha", hintReadCommand("-alpha")) -}