Add flag to skip mod tidy

This commit is contained in:
Dario Emerson
2021-12-12 15:01:16 +01:00
parent 008a5c70b9
commit 44035637f7
3 changed files with 17 additions and 10 deletions

View File

@@ -38,6 +38,9 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) {
compilerCommand := "go"
command.StringFlag("compiler", "Use a different go compiler to build, eg go1.15beta1", &compilerCommand)
skipModTidy := false
command.BoolFlag("m", "Skip mod tidy before compile", &skipModTidy)
compress := false
command.BoolFlag("upx", "Compress final binary with UPX (if installed)", &compress)
@@ -167,6 +170,7 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) {
Pack: !noPackage,
LDFlags: ldflags,
Compiler: compilerCommand,
SkipModTidy: skipModTidy,
Verbosity: verbosity,
ForceBuild: forceBuild,
IgnoreFrontend: skipFrontend,

View File

@@ -198,15 +198,17 @@ func (b *BaseBuilder) CompileProject(options *Options) error {
verbose := options.Verbosity == VERBOSE
// Run go mod tidy first
cmd := exec.Command(options.Compiler, "mod", "tidy")
cmd.Stderr = os.Stderr
if verbose {
println("")
cmd.Stdout = os.Stdout
}
err = cmd.Run()
if err != nil {
return err
if !options.SkipModTidy {
cmd := exec.Command(options.Compiler, "mod", "tidy")
cmd.Stderr = os.Stderr
if verbose {
println("")
cmd.Stdout = os.Stdout
}
err = cmd.Run()
if err != nil {
return err
}
}
// Default go build command
@@ -280,7 +282,7 @@ func (b *BaseBuilder) CompileProject(options *Options) error {
options.CompiledBinary = compiledBinary
// Create the command
cmd = exec.Command(options.Compiler, commands.AsSlice()...)
cmd := exec.Command(options.Compiler, commands.AsSlice()...)
cmd.Stderr = os.Stderr
if verbose {
println(" Build command:", commands.Join(" "))

View File

@@ -37,6 +37,7 @@ type Options struct {
Platform string // The platform to build for
Arch string // The architecture to build for
Compiler string // The compiler command to use
SkipModTidy bool // Skip mod tidy before compile
IgnoreFrontend bool // Indicates if the frontend does not need building
OutputFile string // Override the output filename
BuildDirectory string // Directory to use for building the application