Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tiup: fix -v/--version argument #1243

Merged
merged 2 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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