|
| 1 | +/* |
| 2 | + * Copyright 2025 The CNAI Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package cmd |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + |
| 22 | + "github.com/CloudNativeAI/modctl/pkg/version" |
| 23 | + |
| 24 | + "github.com/spf13/cobra" |
| 25 | + "github.com/spf13/viper" |
| 26 | +) |
| 27 | + |
| 28 | +// versionCmd represents the modctl command for version. |
| 29 | +var versionCmd = &cobra.Command{ |
| 30 | + Use: "version", |
| 31 | + Short: "A command line tool for modctl version", |
| 32 | + DisableAutoGenTag: true, |
| 33 | + SilenceUsage: true, |
| 34 | + FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true}, |
| 35 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 36 | + return runVersion() |
| 37 | + }, |
| 38 | +} |
| 39 | + |
| 40 | +// init initializes version command. |
| 41 | +func init() { |
| 42 | + flags := rmCmd.Flags() |
| 43 | + |
| 44 | + if err := viper.BindPFlags(flags); err != nil { |
| 45 | + panic(fmt.Errorf("bind version flags to viper: %w", err)) |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +// runVersion runs the version modctl. |
| 50 | +func runVersion() error { |
| 51 | + fmt.Printf("%-12s%s\n", "Version:", version.GitVersion) |
| 52 | + fmt.Printf("%-12s%s\n", "Commit:", version.GitCommit) |
| 53 | + fmt.Printf("%-12s%s\n", "Platform:", version.Platform) |
| 54 | + fmt.Printf("%-12s%s\n", "BuildTime:", version.BuildTime) |
| 55 | + return nil |
| 56 | +} |
0 commit comments