mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
yaml supports commands with slashes
This commit is contained in:
parent
a913e1fbab
commit
0bfd1c113a
2 changed files with 19 additions and 2 deletions
|
@ -19,7 +19,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
@ -66,7 +65,7 @@ func GenYamlTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
basename := strings.ReplaceAll(cmd.CommandPath(), " ", "_") + ".yaml"
|
basename := cleanCommandName(cmd.CommandPath()) + ".yaml"
|
||||||
filename := filepath.Join(dir, basename)
|
filename := filepath.Join(dir, basename)
|
||||||
f, err := os.Create(filename)
|
f, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -57,6 +57,24 @@ func TestGenYamlTree(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGenYamlTreeSlashCommands(t *testing.T) {
|
||||||
|
c := &cobra.Command{Use: "run/first [OPTIONS] arg1 arg2"}
|
||||||
|
|
||||||
|
tmpdir, err := ioutil.TempDir("", "test-gen-yaml-tree-slash-commands")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create tmpdir: %s", err.Error())
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
if err := GenYamlTree(c, tmpdir); err != nil {
|
||||||
|
t.Fatalf("GenYamlTree failed: %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(filepath.Join(tmpdir, "run_first.yaml")); err != nil {
|
||||||
|
t.Fatalf("Expected file 'run_first.yaml' to exist")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGenYamlDocRunnable(t *testing.T) {
|
func TestGenYamlDocRunnable(t *testing.T) {
|
||||||
// Testing a runnable command: should contain the "usage" field
|
// Testing a runnable command: should contain the "usage" field
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|
Loading…
Reference in a new issue