Skip to content

Commit

Permalink
make --remote and --s as default for istioctl version command (istio#…
Browse files Browse the repository at this point in the history
…13389)

* make remote and short as default

* fix lint
  • Loading branch information
irisdingbj authored and istio-testing committed Apr 25, 2019
1 parent 137e1b3 commit 9c9a15f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion istioctl/cmd/istioctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func init() {

cmd.AddFlags(rootCmd)

rootCmd.AddCommand(version.CobraCommandWithOptions(version.CobraOptions{GetRemoteVersion: getRemoteInfo}))
rootCmd.AddCommand(newVersionCommand())
rootCmd.AddCommand(gendeployment.Command(&istioNamespace))

experimentalCmd.AddCommand(install.NewVerifyCommand(&istioNamespace))
Expand Down
30 changes: 30 additions & 0 deletions istioctl/cmd/istioctl/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

istioVersion "istio.io/istio/pkg/version"
)

func newVersionCommand() *cobra.Command {
versionCmd := istioVersion.CobraCommandWithOptions(istioVersion.CobraOptions{GetRemoteVersion: getRemoteInfo})
versionCmd.Flags().VisitAll(func(flag *pflag.Flag) {
if flag.Name == "short" {
err := flag.Value.Set("true")
if err != nil {
fmt.Fprint(os.Stdout, fmt.Sprintf("set flag %q as true failed due to error %v", flag.Name, err))
}
}
if flag.Name == "remote" {
err := flag.Value.Set("true")
if err != nil {
fmt.Fprint(os.Stdout, fmt.Sprintf("set flag %q as true failed due to error %v", flag.Name, err))
}
}
})
return versionCmd
}
2 changes: 1 addition & 1 deletion istioctl/cmd/istioctl/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestVersion(t *testing.T) {
cases := []testCase{
{ // case 0 client-side only, normal output
configs: []model.Config{},
args: strings.Split("version --remote=false", " "),
args: strings.Split("version --remote=false --short=false", " "),
expectedRegexp: regexp.MustCompile("version.BuildInfo{Version:\"unknown\", GitRevision:\"unknown\", " +
"User:\"unknown\", Host:\"unknown\", GolangVersion:\"go1.([0-9+?(\\.)?]+)(rc[0-9]?)?\", " +
"DockerHub:\"unknown\", BuildStatus:\"unknown\", GitTag:\"unknown\"}"),
Expand Down

0 comments on commit 9c9a15f

Please sign in to comment.