package main
import (
)
const (
runTestsNone = "none"
runTestsWork = "work"
runTestsAll = "all"
)
const (
formatHTML = "html"
formatJSON = "json"
formatText = "text"
)
var errParse = errors.New("parse error")
type flags struct {
goVersion string
outPath string
outFormat string
runTests string
testShort bool
}
const usage = `goupdate [flags]
-go string
If non-empty, sets go directive in all workspace’s go.mod files.
-o string
Report output path relative to the working directory. By default, report
is written to stdout in "text" format. If this flag is set, the default
format is "html".
-format string
Report output format ("html", "json", "text"). Newlines in "html" format
are escaped for Markdown compatibility.
-test string
Run tests after updating modules ("none", "work", "all"). By default,
no tests are run. Setting this flag to "work" runs tests for packages
in the current workspace; "all" runs tests for all packages in the build
graph, i.e. go test all. Test results are parsed and included in report
output.
-test-short
Pass -short flag to go test when running tests. If -test is not already
set, it defaults to "work".
`
func ( []string) (*flags, error) {
var flags
:= flag.NewFlagSet("goupdate", flag.ContinueOnError)
.Usage = func() {}
.StringVar(&.goVersion, "go", "", "")
.StringVar(&.outPath, "o", "", "")
.BoolVar(&.testShort, "test-short", false, "")
.Func("format", "", func( string) error {
switch {
case formatHTML:
case formatJSON:
case formatText:
default:
return errParse
}
.outFormat =
return nil
})
.Func("test", "run tests; values are none (default), work, all", func( string) error {
switch {
case runTestsNone:
case runTestsWork:
case runTestsAll:
default:
return errParse
}
.runTests =
return nil
})
if := .Parse(); != nil {
return nil,
}
if .runTests == "" {
if .testShort {
.runTests = runTestsWork
} else {
.runTests = runTestsNone
}
}
if .outFormat == "" {
if .outPath != "" {
.outFormat = formatHTML
} else {
.outFormat = formatText
}
}
return &, nil
}