diff --git a/cmd/config/cmddocs/commands/docs.go b/cmd/config/cmddocs/commands/docs.go index dea7a3047..a7e9bcec5 100644 --- a/cmd/config/cmddocs/commands/docs.go +++ b/cmd/config/cmddocs/commands/docs.go @@ -4,9 +4,9 @@ // Code generated by "mdtogo"; DO NOT EDIT. package commands -var CatShort = `Print Resource Config from a local directory.` +var CatShort = `[Alpha] Print Resource Config from a local directory.` var CatLong = ` -Print Resource Config from a local directory. +[Alpha] Print Resource Config from a local directory. DIR: Path to local directory. @@ -21,9 +21,9 @@ var CatExamples = ` # unwrap Resource config from a directory in an ResourceList ... | kyaml cat` -var CountShort = `Count Resources Config from a local directory.` +var CountShort = `[Alpha] Count Resources Config from a local directory.` var CountLong = ` -Count Resources Config from a local directory. +[Alpha] Count Resources Config from a local directory. DIR: Path to local directory. @@ -32,9 +32,9 @@ var CountExamples = ` # print Resource counts from a directory kyaml count my-dir/` -var FmtShort = `Format yaml configuration files.` +var FmtShort = `[Alpha] Format yaml configuration files.` var FmtLong = ` -Format yaml configuration files. +[Alpha] Format yaml configuration files. Fmt will format input by ordering fields and unordered list items in Kubernetes objects. Inputs may be directories, files or stdin, and their contents must @@ -72,9 +72,9 @@ var FmtExamples = ` # format kustomize output kustomize build | kyaml fmt` -var GrepShort = `Search for matching Resources in a directory or from stdin` +var GrepShort = `[Alpha] Search for matching Resources in a directory or from stdin` var GrepLong = ` - Search for matching Resources in a directory or from stdin. +[Alpha] Search for matching Resources in a directory or from stdin. QUERY: Query to match expressed as 'path.to.field=value'. @@ -99,9 +99,9 @@ var GrepExamples = ` # look for Resources matching a specific container image kyaml grep "spec.template.spec.containers[name=nginx].image=nginx:1\.7\.9" my-dir/ | kyaml tree` -var MergeShort = `Merge Resource configuration files` +var MergeShort = `[Alpha] Merge Resource configuration files` var MergeLong = ` -Merge Resource configuration files +[Alpha] Merge Resource configuration files Merge reads Kubernetes Resource yaml configuration files from stdin or sources packages and write the result to stdout or a destination package. @@ -119,9 +119,9 @@ For information on merge rules, run: var MergeExamples = ` cat resources_and_patches.yaml | kyaml merge > merged_resources.yaml` -var RunFnsShort = `Apply config functions to Resources.` +var RunFnsShort = `[Alpha] Reoncile config functions to Resources.` var RunFnsLong = ` -Apply config functions to Resources. +[Alpha] Reconcile config functions to Resources. run-fns sequentially invokes all config functions in the directly, providing Resources in the directory as input to the first function, and writing the output of the last @@ -168,9 +168,9 @@ order they appear in the file). var RunFnsExamples = ` kyaml run-fns example/` -var TreeShort = `Display Resource structure from a directory or stdin.` +var TreeShort = `[Alpha] Display Resource structure from a directory or stdin.` var TreeLong = ` -Display Resource structure from a directory or stdin. +[Alpha] Display Resource structure from a directory or stdin. kyaml tree may be used to print Resources in a directory or cluster, preserving structure diff --git a/cmd/config/cmds/cmds.go b/cmd/config/cmds/cmds.go new file mode 100644 index 000000000..cd19cef53 --- /dev/null +++ b/cmd/config/cmds/cmds.go @@ -0,0 +1,66 @@ +// Copyright 2019 The Kubernetes Authors. +// SPDX-License-Identifier: Apache-2.0 + +// Package cmds provides a target for embedding the config command group in another +// cobra command. +package cmds + +import ( + "strings" + + "github.com/spf13/cobra" + "sigs.k8s.io/kustomize/cmd/config/cmd" + "sigs.k8s.io/kustomize/cmd/config/cmddocs/api" +) + +var root = &cobra.Command{ + Use: "config", + Short: "[Alpha] Utilities for working with Resource Configuration.", + Long: `[Alpha] Utilities for working with Resource Configuration.`, + Version: "v0.0.1", +} + +// NewConfigCommand returns a new *cobra.Command for the config command group. This may +// be embedded into other go binaries as a way of packaging the "config" command as part +// of another binary. +// +// name is substituted into the built-in documentation for each sub-command as the command +// invocation prefix -- e.g. if the result is embedded in kustomize, then name should be +// "kustomize" and the built-in docs will display "kustomize config" in the examples. +// +func NewConfigCommand(name string) *cobra.Command { + root.PersistentFlags().BoolVar(&cmd.StackOnError, "stack-trace", false, + "print a stack-trace on failure") + + name = strings.TrimSpace(name + " config") + cmd.ExitOnError = true + root.AddCommand(cmd.GrepCommand(name)) + root.AddCommand(cmd.TreeCommand(name)) + root.AddCommand(cmd.CatCommand(name)) + root.AddCommand(cmd.FmtCommand(name)) + root.AddCommand(cmd.MergeCommand(name)) + root.AddCommand(cmd.CountCommand(name)) + root.AddCommand(cmd.RunFnCommand(name)) + + root.AddCommand(&cobra.Command{ + Use: "docs-merge", + Short: "[Alpha] Documentation for merging Resources (2-way merge).", + Long: api.Merge2Long, + }) + root.AddCommand(&cobra.Command{ + Use: "docs-merge3", + Short: "[Alpha] Documentation for merging Resources (3-way merge).", + Long: api.Merge3Long, + }) + root.AddCommand(&cobra.Command{ + Use: "docs-fn", + Short: "[Alpha] Documentation for writing containerized functions run by run-fns.", + Long: api.ConfigFnLong, + }) + root.AddCommand(&cobra.Command{ + Use: "docs-io-annotations", + Short: "[Alpha] Documentation for annotations used by io.", + Long: api.ConfigIoLong, + }) + return root +} diff --git a/cmd/config/cmds/example_test.go b/cmd/config/cmds/example_test.go new file mode 100644 index 000000000..4634a2c02 --- /dev/null +++ b/cmd/config/cmds/example_test.go @@ -0,0 +1,20 @@ +// Copyright 2019 The Kubernetes Authors. +// SPDX-License-Identifier: Apache-2.0 + +package cmds_test + +import ( + "github.com/spf13/cobra" + "sigs.k8s.io/kustomize/cmd/config/cmds" +) + +// ExampleNewConfigCommand demonstrates how to embed the config command as a command inside +// another group. +func ExampleNewConfigCommand() { + var root = &cobra.Command{ + Use: "my-cmd", + Short: "My command.", + Long: `My command.`, + } + root.AddCommand(cmds.NewConfigCommand("my-cmd")) +} diff --git a/cmd/config/docs/commands/cat.md b/cmd/config/docs/commands/cat.md index 49bb7b245..08e7b8c2d 100644 --- a/cmd/config/docs/commands/cat.md +++ b/cmd/config/docs/commands/cat.md @@ -1,10 +1,10 @@ ## cat -Print Resource Config from a local directory. +[Alpha] Print Resource Config from a local directory. ### Synopsis -Print Resource Config from a local directory. +[Alpha] Print Resource Config from a local directory. DIR: Path to local directory. diff --git a/cmd/config/docs/commands/count.md b/cmd/config/docs/commands/count.md index a537c1a52..70be322bc 100644 --- a/cmd/config/docs/commands/count.md +++ b/cmd/config/docs/commands/count.md @@ -1,10 +1,10 @@ ## count -Count Resources Config from a local directory. +[Alpha] Count Resources Config from a local directory. ### Synopsis -Count Resources Config from a local directory. +[Alpha] Count Resources Config from a local directory. DIR: Path to local directory. diff --git a/cmd/config/docs/commands/fmt.md b/cmd/config/docs/commands/fmt.md index 1539c2da5..5c7509e66 100644 --- a/cmd/config/docs/commands/fmt.md +++ b/cmd/config/docs/commands/fmt.md @@ -1,10 +1,10 @@ ## fmt -Format yaml configuration files. +[Alpha] Format yaml configuration files. ### Synopsis -Format yaml configuration files. +[Alpha] Format yaml configuration files. Fmt will format input by ordering fields and unordered list items in Kubernetes objects. Inputs may be directories, files or stdin, and their contents must diff --git a/cmd/config/docs/commands/grep.md b/cmd/config/docs/commands/grep.md index e21655567..8b4a8c17a 100644 --- a/cmd/config/docs/commands/grep.md +++ b/cmd/config/docs/commands/grep.md @@ -1,10 +1,10 @@ ## grep -Search for matching Resources in a directory or from stdin +[Alpha] Search for matching Resources in a directory or from stdin ### Synopsis - Search for matching Resources in a directory or from stdin. +[Alpha] Search for matching Resources in a directory or from stdin. QUERY: Query to match expressed as 'path.to.field=value'. diff --git a/cmd/config/docs/commands/merge.md b/cmd/config/docs/commands/merge.md index 84f0f68df..eae88650c 100644 --- a/cmd/config/docs/commands/merge.md +++ b/cmd/config/docs/commands/merge.md @@ -1,10 +1,10 @@ ## merge -Merge Resource configuration files +[Alpha] Merge Resource configuration files ### Synopsis -Merge Resource configuration files +[Alpha] Merge Resource configuration files Merge reads Kubernetes Resource yaml configuration files from stdin or sources packages and write the result to stdout or a destination package. diff --git a/cmd/config/docs/commands/run-fns.md b/cmd/config/docs/commands/run-fns.md index 1d40105f0..d4b66ec28 100644 --- a/cmd/config/docs/commands/run-fns.md +++ b/cmd/config/docs/commands/run-fns.md @@ -1,10 +1,10 @@ ## run-fns -Apply config functions to Resources. +[Alpha] Reoncile config functions to Resources. ### Synopsis -Apply config functions to Resources. +[Alpha] Reconcile config functions to Resources. run-fns sequentially invokes all config functions in the directly, providing Resources in the directory as input to the first function, and writing the output of the last diff --git a/cmd/config/docs/commands/tree.md b/cmd/config/docs/commands/tree.md index e64d1f08f..adb261166 100644 --- a/cmd/config/docs/commands/tree.md +++ b/cmd/config/docs/commands/tree.md @@ -1,10 +1,10 @@ ## tree -Display Resource structure from a directory or stdin. +[Alpha] Display Resource structure from a directory or stdin. ### Synopsis -Display Resource structure from a directory or stdin. +[Alpha] Display Resource structure from a directory or stdin. kyaml tree may be used to print Resources in a directory or cluster, preserving structure diff --git a/cmd/config/main.go b/cmd/config/main.go index 7ae0c275f..520fe7f97 100644 --- a/cmd/config/main.go +++ b/cmd/config/main.go @@ -8,53 +8,11 @@ package main import ( "os" - "github.com/spf13/cobra" - "sigs.k8s.io/kustomize/cmd/config/cmd" - "sigs.k8s.io/kustomize/cmd/config/cmddocs/api" + "sigs.k8s.io/kustomize/cmd/config/cmds" ) -var root = &cobra.Command{ - Use: "config", - Short: "Utilities for working with Resource Configuration.", - Long: `Utilities for working with Resource Configuration.`, -} - func main() { - root.PersistentFlags().BoolVar(&cmd.StackOnError, "stack-trace", false, - "print a stack-trace on failure") - - name := "config" - cmd.ExitOnError = true - root.AddCommand(cmd.GrepCommand(name)) - root.AddCommand(cmd.TreeCommand(name)) - root.AddCommand(cmd.CatCommand(name)) - root.AddCommand(cmd.FmtCommand(name)) - root.AddCommand(cmd.MergeCommand(name)) - root.AddCommand(cmd.CountCommand(name)) - root.AddCommand(cmd.RunFnCommand(name)) - - root.AddCommand(&cobra.Command{ - Use: "docs-merge", - Short: "Documentation for merging Resources (2-way merge).", - Long: api.Merge2Long, - }) - root.AddCommand(&cobra.Command{ - Use: "docs-merge3", - Short: "Documentation for merging Resources (3-way merge).", - Long: api.Merge3Long, - }) - root.AddCommand(&cobra.Command{ - Use: "docs-fn", - Short: "Documentation for writing containerized functions run by run-fns.", - Long: api.ConfigFnLong, - }) - root.AddCommand(&cobra.Command{ - Use: "docs-io-annotations", - Short: "Documentation for annotations used by io.", - Long: api.ConfigIoLong, - }) - - if err := root.Execute(); err != nil { + if err := cmds.NewConfigCommand("").Execute(); err != nil { os.Exit(1) } } diff --git a/kustomize/go.mod b/kustomize/go.mod index 644dad071..8b3686996 100644 --- a/kustomize/go.mod +++ b/kustomize/go.mod @@ -7,5 +7,14 @@ require ( github.com/spf13/cobra v0.0.5 github.com/spf13/pflag v1.0.5 sigs.k8s.io/kustomize/api v0.2.0 + sigs.k8s.io/kustomize/cmd/config v0.0.0 + sigs.k8s.io/kustomize/kyaml v0.0.0 + sigs.k8s.io/kustomize/pseudo/k8s v0.1.0 sigs.k8s.io/yaml v1.1.0 ) + +replace ( + sigs.k8s.io/kustomize/cmd/config v0.0.0 => ../cmd/config + sigs.k8s.io/kustomize/kyaml v0.0.0 => ../kyaml + sigs.k8s.io/kustomize/pseudo/k8s v0.0.0 => ../pseudo/k8s +) diff --git a/kustomize/go.sum b/kustomize/go.sum index 34899ee36..5c530cddb 100644 --- a/kustomize/go.sum +++ b/kustomize/go.sum @@ -57,6 +57,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-critic/go-critic v0.3.5-0.20190904082202-d79a9f0c64db/go.mod h1:+sE8vrLDS2M0pZkBk0wy6+nLdKexVDrl/jBqQOTDThA= +github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w= +github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-lintpack/lintpack v0.5.2/go.mod h1:NwZuYi2nUHho8XEIZ6SIxihrnPoqBTDqfpXvXAN0sXM= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= @@ -273,6 +275,8 @@ github.com/valyala/fasthttp v1.2.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk github.com/valyala/quicktemplate v1.2.0/go.mod h1:EH+4AkTd43SvgIbQHYu59/cJyxDoOVRUAfrukLPuGJ4= github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca h1:1CFlNzQhALwjS9mBAUkycX616GzgsuYUOCHA5+HSlXI= +github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= @@ -371,6 +375,8 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20191026110619-0b21df46bc1d h1:LCPbGQ34PMrwad11aMZ+dbz5SAsq/0ySjRwQ8I9Qwd8= +gopkg.in/yaml.v3 v3.0.0-20191026110619-0b21df46bc1d/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= diff --git a/kustomize/internal/commands/config/config.go b/kustomize/internal/commands/config/config.go index 84df4351b..93c4ea349 100644 --- a/kustomize/internal/commands/config/config.go +++ b/kustomize/internal/commands/config/config.go @@ -10,20 +10,13 @@ import ( "github.com/spf13/cobra" "sigs.k8s.io/kustomize/api/filesys" "sigs.k8s.io/kustomize/api/konfig/builtinpluginconsts" + "sigs.k8s.io/kustomize/cmd/config/cmds" ) // NewCmdConfig returns an instance of 'config' subcommand. func NewCmdConfig(fSys filesys.FileSystem) *cobra.Command { - c := &cobra.Command{ - Use: "config", - Short: "Config Kustomize transformers", - Long: "", - Example: ` - # Save the default transformer configurations to a local directory - kustomize config save -d ~/.kustomize/config -`, - Args: cobra.MinimumNArgs(1), - } + c := cmds.NewConfigCommand("kustomize") + c.AddCommand( newCmdSave(fSys), ) @@ -57,6 +50,12 @@ func newCmdSave(fSys filesys.FileSystem) *cobra.Command { } return o.RunSave(fSys) }, + Hidden: true, // Don't display this command, but keep it for backwards compatibility. + Deprecated: `The save command is deprecated and will be removed in a future release. + +If you require this command file an issue at https://github.com/kubernetes-sigs/kustomize/issues +so we can capture your requirements. +`, } c.Flags().StringVarP( &o.saveDirectory,