package cli import ( "fmt" "os" "strings" ) // const ( // VER_PROGRAM = iota // VER_VERSION // VER_DATE // VER_EMAIL // ) // GetVersionSection() func (cli *CliParser) GetVersionSection(sectionName string) (secValue string, err error) { var sectionId int if sectionName == "" || sectionName == "all" || sectionName == "full" { secValue = cli.version[5 : len(cli.version)-2] } else { sections := strings.Split(cli.version[5:len(cli.version)-2], ",") switch sectionName { case "program": sectionId = 0 case "version", "number": sectionId = 1 case "date": sectionId = 2 case "email": sectionId = 3 case "full": sectionId = -1 default: sectionId = 1 } if sectionId >= 0 && sectionId < len(sections) { secValue = sections[sectionId] } else { err = fmt.Errorf("unknown version section %q", sectionName) } } return } // PrintVersion() func (cli *CliParser) PrintVersion(specs []string) { if len(specs) == 0 { if specValue, err := cli.GetVersionSection("number"); err == nil { os.Stdout.WriteString(specValue + "\n") } } else { for _, spec := range specs { if specValue, err := cli.GetVersionSection(spec); err == nil { os.Stdout.WriteString(specValue + "\n") } } } }