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

resolve flag conflicts between tiup and component #1698

Merged
merged 3 commits into from
Dec 28, 2021
Merged
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
21 changes: 7 additions & 14 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,10 @@ the latest stable version will be downloaded from the repository.`,
}

rootCmd.PersistentFlags().BoolVarP(&repoOpts.SkipVersionCheck, "skip-version-check", "", false, "Skip the strict version check, by default a version must be a valid SemVer string")
rootCmd.Flags().StringVarP(&binary, "binary", "B", "", "Print binary path of a specific version of a component `<component>[:version]`\n"+
rootCmd.Flags().StringVar(&binary, "binary", "", "Print binary path of a specific version of a component `<component>[:version]`\n"+
"and the latest version installed will be selected if no version specified")
rootCmd.Flags().StringVarP(&tag, "tag", "T", "", "[Deprecated] Specify a tag for component instance")
rootCmd.Flags().StringVar(&binPath, "binpath", "", "Specify the binary path of component instance")
// Some components will define themself -h flag, eg:
// $ 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(
Expand All @@ -201,18 +197,15 @@ the latest stable version will be downloaded from the repository.`,

originHelpFunc := rootCmd.HelpFunc()
rootCmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
if len(args) < 2 {
cmd, _, _ = cmd.Root().Find(args)
if len(args) < 2 || cmd != rootCmd {
originHelpFunc(cmd, args)
return
}
env, err := environment.InitEnv(repoOpts)
cmd, n, e := cmd.Root().Find(args)
if (cmd == rootCmd || e != nil) && len(n) > 0 && err == nil {
externalHelp(env, n[0], n[1:]...)
} else {
cmd.InitDefaultHelpFlag() // make possible 'help' flag to be shown
_ = cmd.Help()
}

env, _ := environment.InitEnv(repoOpts)
environment.SetGlobalEnv(env)
_ = cmd.RunE(cmd, args)
})

rootCmd.SetHelpCommand(newHelpCmd())
Expand Down