-
Notifications
You must be signed in to change notification settings - Fork 3
/
primarybuild.go
62 lines (48 loc) · 1.48 KB
/
primarybuild.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package commands
import (
"flag"
"github.com/hashicorp/actions-go-build/pkg/build"
"github.com/hashicorp/composite-action-framework-go/pkg/cli"
)
const primaryBuildHelp = `
Run the primary build by executing the build instructions in the current directory.
` + buildInstructionsHelp
// pbOpts = "primary build opts"
type pbOpts struct {
logOpts
buildFlags
buildConfig build.Config
output output
}
func (opts *pbOpts) ReadEnv() error {
return cli.ReadEnvAll(&opts.output)
}
func (opts *pbOpts) Flags(fs *flag.FlagSet) {
cli.FlagFuncsAll(fs, opts.logOpts.Flags, opts.buildFlags.ownFlags, opts.output.ownFlags)
}
// ownFlags does nothing but marks pbOpts as not definining any of its own flags.
func (opts *pbOpts) ownFlags(fs *flag.FlagSet) {}
func (opts *pbOpts) Init() error {
opts.buildFlags.logOpts = opts.logOpts
opts.output.logOpts = opts.logOpts
var err error
opts.buildConfig, err = opts.primaryBuildConfig()
return err
}
// PrimaryBuild runs the primary build, in the current directory.
var PrimaryBuild = cli.LeafCommand("primary", "run the primary build", func(opts *pbOpts) error {
pb, err := opts.build()
if err != nil {
return err
}
result, err := pb.Result()
if err != nil {
return err
}
return opts.output.result("Primary build", result)
}).WithHelp(primaryBuildHelp)
func (opts *pbOpts) build() (*build.Manager, error) {
return opts.buildFlags.newPrimaryManager(opts.buildConfig)
}