Skip to content
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
31 changes: 31 additions & 0 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"os"
"runtime/debug"

"github.com/spf13/cobra"

Expand All @@ -17,10 +18,40 @@ var RootCmd = &cobra.Command{
Use: "mcc",
Short: "A tool to operate M-CMP system",
Long: `The mcc is a tool to operate M-CMP system.`,
Version: buildVersion(),
CompletionOptions: cobra.CompletionOptions{HiddenDefaultCmd: true}, //completion 옵션 출력 제거
// Uncomment the following line if your bare application
}

// buildVersion reads the VCS revision Go embeds automatically when building
// from within a git checkout (default since Go 1.18, no ldflags required).
func buildVersion() string {
info, ok := debug.ReadBuildInfo()
if !ok {
return "dev"
}
var revision string
var dirty bool
for _, s := range info.Settings {
switch s.Key {
case "vcs.revision":
revision = s.Value
case "vcs.modified":
dirty = s.Value == "true"
}
}
if revision == "" {
return "dev"
}
if len(revision) > 12 {
revision = revision[:12]
}
if dirty {
revision += "-dirty"
}
return revision
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
Expand Down