代码拉取完成,页面将自动刷新
package app
import (
"flag"
"io"
"math/rand"
"strings"
"time"
"gitee.com/blackbelly/gherkingen/internal/model"
"github.com/google/uuid"
)
const (
internalPathPrefix = "@/"
defaultTemplate = "std.simple.v1.go.tmpl"
defaultDisableGoParallel = false
defaultOutputFormat = model.FormatAutoDetect
)
// Run the application.
func Run(arguments []string, out io.Writer, version string) (err error) {
flagSet := flag.NewFlagSet(flag.CommandLine.Name(), flag.ContinueOnError)
flagSet.SetOutput(out)
outputFormat := flagSet.String(
"format",
string(defaultOutputFormat),
"output format: "+strings.Join(model.Formats(), ", "),
)
templateFile := flagSet.String(
"template",
internalPathPrefix+defaultTemplate,
"template file",
)
permanentIDs := flagSet.Bool(
"permanent-ids",
false,
"The same calls to the generator always produces the same output",
)
helpCmd := flagSet.Bool(
"help",
false,
"print usage",
)
_ = flagSet.Bool(
"go-parallel",
!defaultDisableGoParallel,
"add parallel mark (deprecated, enabled by default)",
)
disableGoParallel := flagSet.Bool(
"disable-go-parallel",
defaultDisableGoParallel,
"disable execution of tests in parallel",
)
listCmd := flagSet.Bool(
"list",
false,
"list internal templates",
)
packageName := flagSet.String(
"package",
"generated_test",
"name of the generated package",
)
versionCmd := flagSet.Bool(
"version",
false,
"print version",
)
if err = flagSet.Parse(arguments); err != nil {
return err
}
var seed int64
if *permanentIDs {
seed = 1
} else {
seed = time.Now().UnixNano()
}
var inputFile string
if flagSet.NArg() == 1 {
inputFile = flagSet.Args()[0]
}
switch {
case *versionCmd:
return runVersion(out, version)
case *listCmd:
return runListTemplates(out)
case *helpCmd, inputFile == "":
return runHelp(flagSet)
default:
return runGenerator(appArgs{
Output: out,
OutputFormat: model.Format(*outputFormat),
TemplateFile: *templateFile,
InputFile: inputFile,
PackageName: *packageName,
GoParallel: !(*disableGoParallel),
GenerateUUID: newUUIDRandomGenerator(seed),
})
}
}
func newUUIDRandomGenerator(seed int64) func() string {
// nolint:gosec // Usage for uniq ids.
randomGenerator := rand.New(rand.NewSource(seed))
return func() string {
uuidValue, err := uuid.NewRandomFromReader(randomGenerator)
return uuid.Must(uuidValue, err).String()
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。