Change command setprefixname to setnameprefix

This commit is contained in:
Jingfang Liu 2018-02-06 15:00:50 -08:00
parent c82e0c3564
commit 932009c951
3 changed files with 18 additions and 18 deletions

View File

@ -27,7 +27,7 @@ import (
func main() { func main() {
var c = &cobra.Command{} var c = &cobra.Command{}
c.AddCommand(commands.NewCmdSetPrefixName(os.Stdout, os.Stderr, fs.MakeRealFS())) c.AddCommand(commands.NewCmdSetNamePrefix(os.Stdout, os.Stderr, fs.MakeRealFS()))
c.AddCommand(commands.NewCmdInflate(os.Stdout, os.Stderr)) c.AddCommand(commands.NewCmdInflate(os.Stdout, os.Stderr))
c.AddCommand(commands.NewCmdAddResource(os.Stdout, os.Stderr, fs.MakeRealFS())) c.AddCommand(commands.NewCmdAddResource(os.Stdout, os.Stderr, fs.MakeRealFS()))
c.AddCommand(commands.NewCmdInit(os.Stdout, os.Stderr, fs.MakeRealFS())) c.AddCommand(commands.NewCmdInit(os.Stdout, os.Stderr, fs.MakeRealFS()))

View File

@ -29,22 +29,22 @@ import (
"k8s.io/kubectl/pkg/kinflate/util/fs" "k8s.io/kubectl/pkg/kinflate/util/fs"
) )
type setPrefixNameOptions struct { type setNamePrefixOptions struct {
prefix string prefix string
} }
// NewCmdSetPrefixName sets the value of the namePrefix field in the manifest. // NewCmdSetNamePrefix sets the value of the namePrefix field in the manifest.
func NewCmdSetPrefixName(out, errOut io.Writer, fsys fs.FileSystem) *cobra.Command { func NewCmdSetNamePrefix(out, errOut io.Writer, fsys fs.FileSystem) *cobra.Command {
var o setPrefixNameOptions var o setNamePrefixOptions
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "setprefixname", Use: "setnameprefix",
Short: "Sets the value of the namePrefix field in the manifest.", Short: "Sets the value of the namePrefix field in the manifest.",
Long: "Sets the value of the namePrefix field in the manifest.", Long: "Sets the value of the namePrefix field in the manifest.",
// //
Example: ` Example: `
The command The command
setprefixname acme- setnameprefix acme-
will add the field "namePrefix: acme-" to the manifest file if it doesn't exist, will add the field "namePrefix: acme-" to the manifest file if it doesn't exist,
and overwrite the value with "acme-" if the field does exist. and overwrite the value with "acme-" if the field does exist.
`, `,
@ -57,14 +57,14 @@ and overwrite the value with "acme-" if the field does exist.
if err != nil { if err != nil {
return err return err
} }
return o.RunSetPrefixName(out, errOut, fsys) return o.RunSetNamePrefix(out, errOut, fsys)
}, },
} }
return cmd return cmd
} }
// Validate validates setPrefixName command. // Validate validates setNamePrefix command.
func (o *setPrefixNameOptions) Validate(args []string) error { func (o *setNamePrefixOptions) Validate(args []string) error {
if len(args) != 1 { if len(args) != 1 {
return errors.New("must specify exactly one prefix value") return errors.New("must specify exactly one prefix value")
} }
@ -73,13 +73,13 @@ func (o *setPrefixNameOptions) Validate(args []string) error {
return nil return nil
} }
// Complete completes setPrefixName command. // Complete completes setNamePrefix command.
func (o *setPrefixNameOptions) Complete(cmd *cobra.Command, args []string) error { func (o *setNamePrefixOptions) Complete(cmd *cobra.Command, args []string) error {
return nil return nil
} }
// RunSetPrefixName runs setPrefixName command (does real work). // RunSetNamePrefix runs setNamePrefix command (does real work).
func (o *setPrefixNameOptions) RunSetPrefixName(out, errOut io.Writer, fsys fs.FileSystem) error { func (o *setNamePrefixOptions) RunSetNamePrefix(out, errOut io.Writer, fsys fs.FileSystem) error {
content, err := fsys.ReadFile(constants.KubeManifestFileName) content, err := fsys.ReadFile(constants.KubeManifestFileName)
if err != nil { if err != nil {
return err return err

View File

@ -31,12 +31,12 @@ const (
goodPrefixValue = "acme-" goodPrefixValue = "acme-"
) )
func TestSetPrefixNameHappyPath(t *testing.T) { func TestSetNamePrefixHappyPath(t *testing.T) {
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
fakeFS := fs.MakeFakeFS() fakeFS := fs.MakeFakeFS()
fakeFS.WriteFile(constants.KubeManifestFileName, []byte(manifestTemplate)) fakeFS.WriteFile(constants.KubeManifestFileName, []byte(manifestTemplate))
cmd := NewCmdSetPrefixName(buf, os.Stderr, fakeFS) cmd := NewCmdSetNamePrefix(buf, os.Stderr, fakeFS)
args := []string{goodPrefixValue} args := []string{goodPrefixValue}
err := cmd.RunE(cmd, args) err := cmd.RunE(cmd, args)
if err != nil { if err != nil {
@ -51,11 +51,11 @@ func TestSetPrefixNameHappyPath(t *testing.T) {
} }
} }
func TestSetPrefixNameNoArgs(t *testing.T) { func TestSetNamePrefixNoArgs(t *testing.T) {
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
fakeFS := fs.MakeFakeFS() fakeFS := fs.MakeFakeFS()
cmd := NewCmdSetPrefixName(buf, os.Stderr, fakeFS) cmd := NewCmdSetNamePrefix(buf, os.Stderr, fakeFS)
err := cmd.Execute() err := cmd.Execute()
if err == nil { if err == nil {
t.Errorf("expected error: %v", err) t.Errorf("expected error: %v", err)