Creates a new RootCmd params: commandName: what to call the base command in examples (e.g., "docker-language-server")
(commandName string)
| 25 | // |
| 26 | // commandName: what to call the base command in examples (e.g., "docker-language-server") |
| 27 | func NewRootCmd(commandName string) *RootCmd { |
| 28 | cmd := RootCmd{ |
| 29 | Command: &cobra.Command{ |
| 30 | Use: commandName, |
| 31 | Short: "Language server for Docker", |
| 32 | Version: metadata.Version, |
| 33 | }, |
| 34 | } |
| 35 | |
| 36 | cmd.PersistentFlags().BoolVar(&cmd.debug, "debug", false, "Enable debug logging") |
| 37 | cmd.PersistentFlags().BoolVar(&cmd.verbose, "verbose", false, "Enable verbose logging") |
| 38 | |
| 39 | cmd.PersistentPreRun = func(cc *cobra.Command, args []string) { |
| 40 | if cmd.debug { |
| 41 | logLevel.Set(slog.LevelDebug) |
| 42 | } else if cmd.verbose { |
| 43 | logLevel.Set(slog.LevelInfo) |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | cmd.AddCommand(newStartCmd(commandName).Command) |
| 48 | |
| 49 | return &cmd |
| 50 | } |
| 51 | |
| 52 | func Execute() { |
| 53 | logLevel.Set(slog.LevelError) |
no test coverage detected