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 {
|
||||
fmt.Println("")
|
||||
err, duration := client.WaitForService(serviceName, time.Duration(timeout)*time.Second, wait.SimpleMessageCallback(out))
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command {
|
|||
Example: update_example,
|
||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
if len(args) != 1 {
|
||||
return errors.New("requires the service name.")
|
||||
return errors.New("requires the service name")
|
||||
}
|
||||
|
||||
namespace, err := p.GetNamespace(cmd)
|
||||
|
|
@ -114,7 +114,7 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command {
|
|||
|
||||
out := cmd.OutOrStdout()
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -122,7 +122,6 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command {
|
|||
return showUrl(client, name, latestRevisionBeforeUpdate, "updated", out)
|
||||
} else {
|
||||
fmt.Fprintf(out, "Service '%s' updated in namespace '%s'.\n", args[0], namespace)
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -43,17 +43,18 @@ func NewVersionCommand(p *KnParams) *cobra.Command {
|
|||
Use: "version",
|
||||
Short: "Prints the client version",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf("Version: %s\n", Version)
|
||||
fmt.Printf("Build Date: %s\n", BuildDate)
|
||||
fmt.Printf("Git Revision: %s\n", GitRevision)
|
||||
fmt.Printf("Support:\n")
|
||||
out := cmd.OutOrStdout()
|
||||
fmt.Fprintf(out, "Version: %s\n", Version)
|
||||
fmt.Fprintf(out, "Build Date: %s\n", BuildDate)
|
||||
fmt.Fprintf(out, "Git Revision: %s\n", GitRevision)
|
||||
fmt.Fprintf(out, "Support:\n")
|
||||
if m, ok := supportMatrix[ServingVersion]; ok {
|
||||
fmt.Printf("- Serving: %s\n", strings.Join(m.Versions, " "))
|
||||
fmt.Printf("- API(s): %s\n", strings.Join(m.APIs, " "))
|
||||
fmt.Fprintf(out, "- Serving: %s\n", strings.Join(m.Versions, " "))
|
||||
fmt.Fprintf(out, "- API(s): %s\n", strings.Join(m.APIs, " "))
|
||||
} else {
|
||||
// ensure the go build works when we update,
|
||||
// but version command tests fails to prevent shipping
|
||||
fmt.Printf("- Serving: %s\n", ServingVersion)
|
||||
fmt.Fprintf(out, "- Serving: %s\n", ServingVersion)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ func TestVersion(t *testing.T) {
|
|||
versionCmd *cobra.Command
|
||||
knParams *KnParams
|
||||
expectedVersionOutput string
|
||||
output *bytes.Buffer
|
||||
)
|
||||
|
||||
setup := func() {
|
||||
|
|
@ -66,12 +67,12 @@ func TestVersion(t *testing.T) {
|
|||
|
||||
knParams = &KnParams{}
|
||||
versionCmd = NewVersionCommand(knParams)
|
||||
output = new(bytes.Buffer)
|
||||
versionCmd.SetOutput(output)
|
||||
}
|
||||
|
||||
t.Run("creates a VersionCommand", func(t *testing.T) {
|
||||
setup()
|
||||
CaptureStdout(t)
|
||||
defer ReleaseStdout(t)
|
||||
|
||||
assert.Equal(t, versionCmd.Use, "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) {
|
||||
setup()
|
||||
CaptureStdout(t)
|
||||
defer ReleaseStdout(t)
|
||||
|
||||
err := versionCmd.RunE(nil, []string{})
|
||||
err := versionCmd.RunE(versionCmd, []string{})
|
||||
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
|
||||
pluginsDir, lookupPluginsInPath, err := extractKnPluginFlags(os.Args)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
|
@ -79,8 +79,7 @@ func NewDefaultKnCommandWithArgs(rootCmd *cobra.Command,
|
|||
err := plugin.HandlePluginCommand(pluginHandler, cmdPathPieces)
|
||||
if err != nil {
|
||||
rootCmd.Help()
|
||||
fmt.Println()
|
||||
fmt.Printf("unknown command or plugin \"%s\" for \"kn\"\n", args[1])
|
||||
fmt.Fprintf(rootCmd.OutOrStderr(), "Unknown command or plugin '%s'.\n", args[1])
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
@ -171,8 +170,6 @@ func EmptyAndUnknownSubCommands(cmd *cobra.Command) {
|
|||
if childCmd.HasSubCommands() && childCmd.RunE == nil {
|
||||
childCmd.RunE = func(aCmd *cobra.Command, args []string) error {
|
||||
aCmd.Help()
|
||||
fmt.Println()
|
||||
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("please provide a valid sub-command for \"kn %s\"", aCmd.Name())
|
||||
}
|
||||
|
|
@ -196,7 +193,7 @@ func initConfig() {
|
|||
// Find home directory.
|
||||
home, err := homedir.Dir()
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue