|
1 | 1 | package cli |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "fmt" |
| 4 | + "fmt" |
5 | 5 |
|
6 | | - "github.com/spf13/cobra" |
| 6 | + "github.com/spf13/cobra" |
7 | 7 | ) |
8 | 8 |
|
9 | 9 | var ( |
10 | | - version = "1.0.0" |
| 10 | + // Version information - set via ldflags during build |
| 11 | + version = "dev" |
| 12 | + commit = "none" |
| 13 | + buildDate = "unknown" |
11 | 14 | ) |
12 | 15 |
|
13 | 16 | // Global flags |
14 | 17 | var ( |
15 | | - projectFlag string |
16 | | - rawFlag bool |
17 | | - csvFlag bool |
| 18 | + projectFlag string |
| 19 | + rawFlag bool |
| 20 | + csvFlag bool |
18 | 21 | ) |
19 | 22 |
|
20 | 23 | // rootCmd represents the base command |
21 | 24 | var rootCmd = &cobra.Command{ |
22 | | - Use: "otc-cli", |
23 | | - Short: "OTC CLI - Manage your Open Telekom Cloud resources", |
24 | | - Long: `A command-line tool for managing Open Telekom Cloud (OTC) resources. |
| 25 | + Use: "otc-cli", |
| 26 | + Short: "OTC CLI - Manage your Open Telekom Cloud resources", |
| 27 | + Long: `A command-line tool for managing Open Telekom Cloud (OTC) resources. |
25 | 28 | Supports authentication, resource management, and automation.`, |
26 | | - Version: version, |
| 29 | + Version: version, |
27 | 30 | } |
28 | 31 |
|
29 | 32 | // Execute runs the root command |
30 | 33 | func Execute() error { |
31 | | - return rootCmd.Execute() |
| 34 | + return rootCmd.Execute() |
32 | 35 | } |
33 | 36 |
|
34 | 37 | func init() { |
35 | | - // Persistent flags available to all subcommands |
36 | | - rootCmd.PersistentFlags().StringVarP(&projectFlag, "project", "p", "", "Project ID or name") |
37 | | - rootCmd.PersistentFlags().BoolVar(&rawFlag, "raw", false, "Output raw JSON response") |
38 | | - rootCmd.PersistentFlags().BoolVar(&rawFlag, "json", false, "Output raw JSON response (alias)") |
39 | | - rootCmd.PersistentFlags().BoolVar(&csvFlag, "csv", false, "Output in CSV format") |
40 | | - |
41 | | - rootCmd.MarkFlagsMutuallyExclusive("raw", "csv") |
42 | | - rootCmd.MarkFlagsMutuallyExclusive("json", "csv") |
43 | | - // Add subcommands |
44 | | - rootCmd.AddCommand(loginCmd) |
45 | | - rootCmd.AddCommand(logoutCmd) |
46 | | - rootCmd.AddCommand(docsCmd) |
47 | | - rootCmd.AddCommand(listCmd) |
48 | | - rootCmd.AddCommand(getCmd) |
49 | | - rootCmd.AddCommand(consoleCmd) |
50 | | - rootCmd.AddCommand(versionCmd) |
| 38 | + // Persistent flags available to all subcommands |
| 39 | + rootCmd.PersistentFlags().StringVarP(&projectFlag, "project", "p", "", "Project ID or name") |
| 40 | + rootCmd.PersistentFlags().BoolVar(&rawFlag, "raw", false, "Output raw JSON response") |
| 41 | + rootCmd.PersistentFlags().BoolVar(&rawFlag, "json", false, "Output raw JSON response (alias)") |
| 42 | + rootCmd.PersistentFlags().BoolVar(&csvFlag, "csv", false, "Output in CSV format") |
| 43 | + |
| 44 | + rootCmd.MarkFlagsMutuallyExclusive("raw", "csv") |
| 45 | + rootCmd.MarkFlagsMutuallyExclusive("json", "csv") |
| 46 | + |
| 47 | + // Add subcommands |
| 48 | + rootCmd.AddCommand(loginCmd) |
| 49 | + rootCmd.AddCommand(logoutCmd) |
| 50 | + rootCmd.AddCommand(docsCmd) |
| 51 | + rootCmd.AddCommand(listCmd) |
| 52 | + rootCmd.AddCommand(getCmd) |
| 53 | + rootCmd.AddCommand(consoleCmd) |
| 54 | + rootCmd.AddCommand(versionCmd) |
51 | 55 | } |
52 | 56 |
|
53 | 57 | var versionCmd = &cobra.Command{ |
54 | | - Use: "version", |
55 | | - Short: "Print the version number", |
56 | | - Run: func(cmd *cobra.Command, args []string) { |
57 | | - fmt.Printf("otc-cli v%s\n", version) |
58 | | - }, |
| 58 | + Use: "version", |
| 59 | + Short: "Print the version number", |
| 60 | + Long: "Display version information including build details", |
| 61 | + Run: func(cmd *cobra.Command, args []string) { |
| 62 | + fmt.Printf("otc-cli version %s\n", version) |
| 63 | + if commit != "none" { |
| 64 | + fmt.Printf(" commit: %s\n", commit) |
| 65 | + } |
| 66 | + if buildDate != "unknown" { |
| 67 | + fmt.Printf(" built: %s\n", buildDate) |
| 68 | + } |
| 69 | + }, |
59 | 70 | } |
0 commit comments