Skip to content

Commit

Permalink
tiup: fix -v/--version argument
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroProfundis committed Mar 25, 2021
1 parent ede1182 commit 4b87152
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
16 changes: 12 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ func init() {
cobra.EnableCommandSorting = false

var (
binary string
binPath string
tag string
binary string
binPath string
tag string
printVersion bool // not using cobra.Command.Version to make it possible to show component versions
)

rootCmd = &cobra.Command{
Expand All @@ -48,13 +49,15 @@ locally will be used. If the specified component does not have any version insta
the latest stable version will be downloaded from the repository.`,

SilenceErrors: true,
Version: version.NewTiUPVersion().String(),
FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true},
Args: func(cmd *cobra.Command, args []string) error {
// Support `tiup <component>`
return nil
},
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if printVersion && len(args) == 0 {
return nil
}
e, err := environment.InitEnv(repoOpts)
if err != nil {
return err
Expand All @@ -63,6 +66,10 @@ the latest stable version will be downloaded from the repository.`,
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
if printVersion && len(args) == 0 {
fmt.Println(version.NewTiUPVersion().String())
return nil
}
env := environment.GlobalEnv()
if binary != "" {
component, ver := environment.ParseCompVersion(binary)
Expand Down Expand Up @@ -114,6 +121,7 @@ the latest stable version will be downloaded from the repository.`,
// $ tiup dumpling -h ${host}.
// We try to leave the handling of `-h` flag to the component.
rootCmd.PersistentFlags().Bool("help", false, "Help for this command")
rootCmd.Flags().BoolVarP(&printVersion, "version", "v", false, "Print the version of tiup")

rootCmd.AddCommand(
newInstallCmd(),
Expand Down
1 change: 0 additions & 1 deletion pkg/cluster/manager/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func (m *Manager) DestroyTombstone(

t := b.
Func("FindTomestoneNodes", func(ctx context.Context) (err error) {

if !skipConfirm {
err = cliutil.PromptForConfirmOrAbortError(
color.HiYellowString(fmt.Sprintf("Will destroy these nodes: %v\nDo you confirm this action? [y/N]:", nodes)),
Expand Down

0 comments on commit 4b87152

Please sign in to comment.