diff --git a/cmd/tk/export.go b/cmd/tk/export.go index edc68c8e3..8ed287f81 100644 --- a/cmd/tk/export.go +++ b/cmd/tk/export.go @@ -29,7 +29,6 @@ func exportCmd() *cli.Command { vars := workflowFlags(cmd.Flags()) getExtCode := extCodeParser(cmd.Flags()) - createDirs := cmd.Flags().Bool("dirs", false, "Treat '/' in filenames as directories") format := cmd.Flags().String("format", "{{.apiVersion}}.{{.kind}}-{{.metadata.name}}", "https://tanka.dev/exporting#filenames") extension := cmd.Flags().String("extension", "yaml", "File extension") @@ -37,8 +36,8 @@ func exportCmd() *cli.Command { "lower": func(s string) string { return strings.ToLower(s) }, - "replace": func(old, new string, s string) string { - return strings.Replace(s, old, new, -1) + "mkdir": func() string { + return string(rune(7)) }, } @@ -75,10 +74,8 @@ func exportCmd() *cli.Command { log.Fatalln("executing name template:", err) } - name := buf.String() - if !*createDirs { - name = strings.Replace(name, "/", "-", -1) - } + name := strings.Replace(buf.String(), "/", "-", -1) + name = strings.Replace(name, string(rune(7)), "/", -1) path := filepath.Join(to, name+"."+*extension) if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil { return fmt.Errorf("creating filepath '%s': %s", filepath.Dir(path), err) diff --git a/docs/docs/exporting.md b/docs/docs/exporting.md index 0dda0a537..b86e0862e 100644 --- a/docs/docs/exporting.md +++ b/docs/docs/exporting.md @@ -66,26 +66,13 @@ You can optionally use one of the following template functions: loki-distributor-deployment ``` etc. -- `replace` for replacing occurrences of a character +- `mkdir` create new subdirectory ```bash - ... --format='{{.metadata.labels.app}}-{{.metadata.name}}-{{.kind | replace "e" "_" }}' + ... --format='{{.metadata.labels.app}}{{mkdir}}{{.metadata.name}}{{mkdir}}{{.kind}}' ``` - would yield - - ``` - loki-distributor-d_ploym_nt - ``` - etc. - -You can also use a different file extension by providing `--extension='yml'`, for example. + would create following directory structure: + - loki + - distributor + - deployment -If you want your format to be able to create subfolders you can enable this by providing `--dirs`. -With this format -```bash - ... --format='{{.metadata.labels.app}}/{{.metadata.name}}/{{.kind}}' --dirs -``` -you would create following folder structure -- loki - - distributor - - deployment -etc. \ No newline at end of file +You can also use a different file extension by providing `--extension='yml'`, for example. \ No newline at end of file