()
| 182 | } |
| 183 | |
| 184 | func init() { |
| 185 | tui.InitCommonStyles(os.Stdout) |
| 186 | rootCmd.SetVersionTemplate(versionTemplate()) |
| 187 | if rootCmd.Flags().Lookup("version") == nil { |
| 188 | rootCmd.Flags().BoolP("version", "v", false, "Show version information") |
| 189 | } |
| 190 | |
| 191 | rootCmd.SetFlagErrorFunc(func(_ *cobra.Command, err error) error { |
| 192 | return fmt.Errorf("%w: %w", ErrUsage, err) |
| 193 | }) |
| 194 | |
| 195 | rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error { |
| 196 | tui.SetNonInteractive(JSONOutput) |
| 197 | checkIfUpdateNeeded(cmd) |
| 198 | kickoffSubscriptionCheck(cmd) |
| 199 | showCachedSubscriptionWarning(cmd) |
| 200 | return nil |
| 201 | } |
| 202 | |
| 203 | rootCmd.SetHelpFunc(wrapHelp(helpmenus.RenderRootHelp)) |
| 204 | |
| 205 | completionCmd := &cobra.Command{ |
| 206 | Use: "completion [shell]", |
| 207 | Short: "Generate the autocompletion script for tnr for the specified shell", |
| 208 | Run: func(cmd *cobra.Command, args []string) { |
| 209 | _ = rootCmd.GenBashCompletionV2(os.Stdout, true) //nolint:errcheck // completion generation error is non-fatal |
| 210 | }, |
| 211 | } |
| 212 | |
| 213 | completionCmd.SetHelpFunc(wrapHelp(helpmenus.RenderCompletionHelp)) |
| 214 | |
| 215 | completionCmd.AddCommand(&cobra.Command{ |
| 216 | Use: "bash", |
| 217 | Short: "Generate the autocompletion script for bash", |
| 218 | Run: func(cmd *cobra.Command, args []string) { |
| 219 | _ = rootCmd.GenBashCompletionV2(os.Stdout, true) //nolint:errcheck // completion generation error is non-fatal |
| 220 | }, |
| 221 | }) |
| 222 | |
| 223 | completionCmd.AddCommand(&cobra.Command{ |
| 224 | Use: "zsh", |
| 225 | Short: "Generate the autocompletion script for zsh", |
| 226 | Run: func(cmd *cobra.Command, args []string) { |
| 227 | _ = rootCmd.GenZshCompletion(os.Stdout) //nolint:errcheck // completion generation error is non-fatal |
| 228 | }, |
| 229 | }) |
| 230 | |
| 231 | completionCmd.AddCommand(&cobra.Command{ |
| 232 | Use: "fish", |
| 233 | Short: "Generate the autocompletion script for fish", |
| 234 | Run: func(cmd *cobra.Command, args []string) { |
| 235 | _ = rootCmd.GenFishCompletion(os.Stdout, true) //nolint:errcheck // completion generation error is non-fatal |
| 236 | }, |
| 237 | }) |
| 238 | |
| 239 | completionCmd.AddCommand(&cobra.Command{ |
| 240 | Use: "powershell", |
| 241 | Short: "Generate the autocompletion script for powershell", |
nothing calls this directly
no test coverage detected