@@ -25,38 +25,33 @@ import (
25
25
"github.com/blang/semver/v4"
26
26
)
27
27
28
- // BicepVersion is the minimum version of bicep that we require (and the one we fetch when we fetch bicep on behalf of a
28
+ // Version is the minimum version of bicep that we require (and the one we fetch when we fetch bicep on behalf of a
29
29
// user).
30
- var BicepVersion semver.Version = semver .MustParse ("0.28.1" )
30
+ var Version semver.Version = semver .MustParse ("0.28.1" )
31
31
32
- type BicepCli interface {
33
- Build (ctx context.Context , file string ) (BuildResult , error )
34
- BuildBicepParam (ctx context.Context , file string , env []string ) (BuildResult , error )
35
- }
36
-
37
- // NewBicepCli creates a new BicepCli. Azd manages its own copy of the bicep CLI, stored in `$AZD_CONFIG_DIR/bin`. If
32
+ // NewCli creates a new Bicep CLI. Azd manages its own copy of the bicep CLI, stored in `$AZD_CONFIG_DIR/bin`. If
38
33
// bicep is not present at this location, or if it is present but is older than the minimum supported version, it is
39
34
// downloaded.
40
- func NewBicepCli (
35
+ func NewCli (
41
36
ctx context.Context ,
42
37
console input.Console ,
43
38
commandRunner exec.CommandRunner ,
44
- ) (BicepCli , error ) {
45
- return newBicepCliWithTransporter (ctx , console , commandRunner , http .DefaultClient )
39
+ ) (* Cli , error ) {
40
+ return newCliWithTransporter (ctx , console , commandRunner , http .DefaultClient )
46
41
}
47
42
48
- // newBicepCliWithTransporter is like NewBicepCli but allows providing a custom transport to use when downloading the
49
- // bicep CLI, for testing purposes.
50
- func newBicepCliWithTransporter (
43
+ // newCliWithTransporter is like NewBicepCli but allows providing a custom transport to use when downloading the
44
+ // Bicep CLI, for testing purposes.
45
+ func newCliWithTransporter (
51
46
ctx context.Context ,
52
47
console input.Console ,
53
48
commandRunner exec.CommandRunner ,
54
49
transporter policy.Transporter ,
55
- ) (BicepCli , error ) {
50
+ ) (* Cli , error ) {
56
51
if override := os .Getenv ("AZD_BICEP_TOOL_PATH" ); override != "" {
57
52
log .Printf ("using external bicep tool: %s" , override )
58
53
59
- return & bicepCli {
54
+ return & Cli {
60
55
path : override ,
61
56
runner : commandRunner ,
62
57
}, nil
@@ -77,14 +72,14 @@ func newBicepCliWithTransporter(
77
72
78
73
if err := runStep (
79
74
ctx , console , "Downloading Bicep" , func () error {
80
- return downloadBicep (ctx , transporter , BicepVersion , bicepPath )
75
+ return downloadBicep (ctx , transporter , Version , bicepPath )
81
76
},
82
77
); err != nil {
83
78
return nil , fmt .Errorf ("downloading bicep: %w" , err )
84
79
}
85
80
}
86
81
87
- cli := & bicepCli {
82
+ cli := & Cli {
88
83
path : bicepPath ,
89
84
runner : commandRunner ,
90
85
}
@@ -96,12 +91,12 @@ func newBicepCliWithTransporter(
96
91
97
92
log .Printf ("bicep version: %s" , ver )
98
93
99
- if ver .LT (BicepVersion ) {
100
- log .Printf ("installed bicep version %s is older than %s; updating." , ver .String (), BicepVersion .String ())
94
+ if ver .LT (Version ) {
95
+ log .Printf ("installed bicep version %s is older than %s; updating." , ver .String (), Version .String ())
101
96
102
97
if err := runStep (
103
98
ctx , console , "Upgrading Bicep" , func () error {
104
- return downloadBicep (ctx , transporter , BicepVersion , bicepPath )
99
+ return downloadBicep (ctx , transporter , Version , bicepPath )
105
100
},
106
101
); err != nil {
107
102
return nil , fmt .Errorf ("upgrading bicep: %w" , err )
@@ -127,7 +122,7 @@ func runStep(ctx context.Context, console input.Console, title string, action fu
127
122
return nil
128
123
}
129
124
130
- type bicepCli struct {
125
+ type Cli struct {
131
126
path string
132
127
runner exec.CommandRunner
133
128
}
@@ -245,7 +240,7 @@ func preferMuslBicep(stat stater) bool {
245
240
return false
246
241
}
247
242
248
- func (cli * bicepCli ) version (ctx context.Context ) (semver.Version , error ) {
243
+ func (cli * Cli ) version (ctx context.Context ) (semver.Version , error ) {
249
244
bicepRes , err := cli .runCommand (ctx , nil , "--version" )
250
245
if err != nil {
251
246
return semver.Version {}, err
@@ -268,7 +263,7 @@ type BuildResult struct {
268
263
LintErr string
269
264
}
270
265
271
- func (cli * bicepCli ) Build (ctx context.Context , file string ) (BuildResult , error ) {
266
+ func (cli * Cli ) Build (ctx context.Context , file string ) (BuildResult , error ) {
272
267
args := []string {"build" , file , "--stdout" }
273
268
buildRes , err := cli .runCommand (ctx , nil , args ... )
274
269
@@ -285,7 +280,7 @@ func (cli *bicepCli) Build(ctx context.Context, file string) (BuildResult, error
285
280
}, nil
286
281
}
287
282
288
- func (cli * bicepCli ) BuildBicepParam (ctx context.Context , file string , env []string ) (BuildResult , error ) {
283
+ func (cli * Cli ) BuildBicepParam (ctx context.Context , file string , env []string ) (BuildResult , error ) {
289
284
args := []string {"build-params" , file , "--stdout" }
290
285
buildRes , err := cli .runCommand (ctx , env , args ... )
291
286
@@ -302,7 +297,7 @@ func (cli *bicepCli) BuildBicepParam(ctx context.Context, file string, env []str
302
297
}, nil
303
298
}
304
299
305
- func (cli * bicepCli ) runCommand (ctx context.Context , env []string , args ... string ) (exec.RunResult , error ) {
300
+ func (cli * Cli ) runCommand (ctx context.Context , env []string , args ... string ) (exec.RunResult , error ) {
306
301
runArgs := exec .NewRunArgs (cli .path , args ... )
307
302
if env != nil {
308
303
runArgs = runArgs .WithEnv (env )
0 commit comments