mirror of https://github.com/knative/client.git
chore: Some minor printout fixes (#442)
* chore: Some minor printout fixes * test fixes
This commit is contained in:
parent
a2d1ef7d83
commit
53125bcbdb
|
|
@ -46,7 +46,6 @@ func NewServiceCommand(p *commands.KnParams) *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitForService(client serving_kn_v1alpha1.KnServingClient, serviceName string, out io.Writer, timeout int) error {
|
func waitForService(client serving_kn_v1alpha1.KnServingClient, serviceName string, out io.Writer, timeout int) error {
|
||||||
fmt.Println("")
|
|
||||||
err, duration := client.WaitForService(serviceName, time.Duration(timeout)*time.Second, wait.SimpleMessageCallback(out))
|
err, duration := client.WaitForService(serviceName, time.Duration(timeout)*time.Second, wait.SimpleMessageCallback(out))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command {
|
||||||
Example: update_example,
|
Example: update_example,
|
||||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return errors.New("requires the service name.")
|
return errors.New("requires the service name")
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace, err := p.GetNamespace(cmd)
|
namespace, err := p.GetNamespace(cmd)
|
||||||
|
|
@ -114,7 +114,7 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command {
|
||||||
|
|
||||||
out := cmd.OutOrStdout()
|
out := cmd.OutOrStdout()
|
||||||
if !waitFlags.Async {
|
if !waitFlags.Async {
|
||||||
fmt.Fprintf(cmd.OutOrStdout(), "Updating Service '%s' in namespace '%s':\n", args[0], namespace)
|
fmt.Fprintf(out, "Updating Service '%s' in namespace '%s':\n", args[0], namespace)
|
||||||
err := waitForService(client, name, out, waitFlags.TimeoutInSeconds)
|
err := waitForService(client, name, out, waitFlags.TimeoutInSeconds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -122,7 +122,6 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command {
|
||||||
return showUrl(client, name, latestRevisionBeforeUpdate, "updated", out)
|
return showUrl(client, name, latestRevisionBeforeUpdate, "updated", out)
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(out, "Service '%s' updated in namespace '%s'.\n", args[0], namespace)
|
fmt.Fprintf(out, "Service '%s' updated in namespace '%s'.\n", args[0], namespace)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -43,17 +43,18 @@ func NewVersionCommand(p *KnParams) *cobra.Command {
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "Prints the client version",
|
Short: "Prints the client version",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
fmt.Printf("Version: %s\n", Version)
|
out := cmd.OutOrStdout()
|
||||||
fmt.Printf("Build Date: %s\n", BuildDate)
|
fmt.Fprintf(out, "Version: %s\n", Version)
|
||||||
fmt.Printf("Git Revision: %s\n", GitRevision)
|
fmt.Fprintf(out, "Build Date: %s\n", BuildDate)
|
||||||
fmt.Printf("Support:\n")
|
fmt.Fprintf(out, "Git Revision: %s\n", GitRevision)
|
||||||
|
fmt.Fprintf(out, "Support:\n")
|
||||||
if m, ok := supportMatrix[ServingVersion]; ok {
|
if m, ok := supportMatrix[ServingVersion]; ok {
|
||||||
fmt.Printf("- Serving: %s\n", strings.Join(m.Versions, " "))
|
fmt.Fprintf(out, "- Serving: %s\n", strings.Join(m.Versions, " "))
|
||||||
fmt.Printf("- API(s): %s\n", strings.Join(m.APIs, " "))
|
fmt.Fprintf(out, "- API(s): %s\n", strings.Join(m.APIs, " "))
|
||||||
} else {
|
} else {
|
||||||
// ensure the go build works when we update,
|
// ensure the go build works when we update,
|
||||||
// but version command tests fails to prevent shipping
|
// but version command tests fails to prevent shipping
|
||||||
fmt.Printf("- Serving: %s\n", ServingVersion)
|
fmt.Fprintf(out, "- Serving: %s\n", ServingVersion)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ func TestVersion(t *testing.T) {
|
||||||
versionCmd *cobra.Command
|
versionCmd *cobra.Command
|
||||||
knParams *KnParams
|
knParams *KnParams
|
||||||
expectedVersionOutput string
|
expectedVersionOutput string
|
||||||
|
output *bytes.Buffer
|
||||||
)
|
)
|
||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
|
|
@ -66,12 +67,12 @@ func TestVersion(t *testing.T) {
|
||||||
|
|
||||||
knParams = &KnParams{}
|
knParams = &KnParams{}
|
||||||
versionCmd = NewVersionCommand(knParams)
|
versionCmd = NewVersionCommand(knParams)
|
||||||
|
output = new(bytes.Buffer)
|
||||||
|
versionCmd.SetOutput(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("creates a VersionCommand", func(t *testing.T) {
|
t.Run("creates a VersionCommand", func(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
CaptureStdout(t)
|
|
||||||
defer ReleaseStdout(t)
|
|
||||||
|
|
||||||
assert.Equal(t, versionCmd.Use, "version")
|
assert.Equal(t, versionCmd.Use, "version")
|
||||||
assert.Equal(t, versionCmd.Short, "Prints the client version")
|
assert.Equal(t, versionCmd.Short, "Prints the client version")
|
||||||
|
|
@ -80,12 +81,10 @@ func TestVersion(t *testing.T) {
|
||||||
|
|
||||||
t.Run("prints version, build date, git revision, supported serving version and APIs", func(t *testing.T) {
|
t.Run("prints version, build date, git revision, supported serving version and APIs", func(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
CaptureStdout(t)
|
|
||||||
defer ReleaseStdout(t)
|
|
||||||
|
|
||||||
err := versionCmd.RunE(nil, []string{})
|
err := versionCmd.RunE(versionCmd, []string{})
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Equal(t, ReadStdout(t), expectedVersionOutput)
|
assert.Equal(t, output.String(), expectedVersionOutput)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ func NewDefaultKnCommand() *cobra.Command {
|
||||||
// and will not be parsed
|
// and will not be parsed
|
||||||
pluginsDir, lookupPluginsInPath, err := extractKnPluginFlags(os.Args)
|
pluginsDir, lookupPluginsInPath, err := extractKnPluginFlags(os.Args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,8 +79,7 @@ func NewDefaultKnCommandWithArgs(rootCmd *cobra.Command,
|
||||||
err := plugin.HandlePluginCommand(pluginHandler, cmdPathPieces)
|
err := plugin.HandlePluginCommand(pluginHandler, cmdPathPieces)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rootCmd.Help()
|
rootCmd.Help()
|
||||||
fmt.Println()
|
fmt.Fprintf(rootCmd.OutOrStderr(), "Unknown command or plugin '%s'.\n", args[1])
|
||||||
fmt.Printf("unknown command or plugin \"%s\" for \"kn\"\n", args[1])
|
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -171,8 +170,6 @@ func EmptyAndUnknownSubCommands(cmd *cobra.Command) {
|
||||||
if childCmd.HasSubCommands() && childCmd.RunE == nil {
|
if childCmd.HasSubCommands() && childCmd.RunE == nil {
|
||||||
childCmd.RunE = func(aCmd *cobra.Command, args []string) error {
|
childCmd.RunE = func(aCmd *cobra.Command, args []string) error {
|
||||||
aCmd.Help()
|
aCmd.Help()
|
||||||
fmt.Println()
|
|
||||||
|
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return fmt.Errorf("please provide a valid sub-command for \"kn %s\"", aCmd.Name())
|
return fmt.Errorf("please provide a valid sub-command for \"kn %s\"", aCmd.Name())
|
||||||
}
|
}
|
||||||
|
|
@ -196,7 +193,7 @@ func initConfig() {
|
||||||
// Find home directory.
|
// Find home directory.
|
||||||
home, err := homedir.Dir()
|
home, err := homedir.Dir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue