@@ -14,7 +14,7 @@ import (
14
14
"github.com/coder/coder/v2/codersdk"
15
15
"github.com/coder/coder/v2/codersdk/agentsdk"
16
16
"github.com/coder/envbuilder"
17
- "github.com/spf13/cobra "
17
+ "github.com/coder/serpent "
18
18
19
19
// *Never* remove this. Certificates are not bundled as part
20
20
// of the container, so this is necessary for all connections
@@ -23,15 +23,11 @@ import (
23
23
)
24
24
25
25
func main () {
26
- root := & cobra.Command {
27
- Use : "envbuilder" ,
28
- // Hide usage because we don't want to show the
29
- // "envbuilder [command] --help" output on error.
30
- SilenceUsage : true ,
31
- SilenceErrors : true ,
32
- RunE : func (cmd * cobra.Command , args []string ) error {
33
- options := envbuilder .OptionsFromEnv (os .LookupEnv )
34
-
26
+ var options envbuilder.Options
27
+ cmd := serpent.Command {
28
+ Use : "envbuilder" ,
29
+ Options : options .CLI (),
30
+ Handler : func (inv * serpent.Invocation ) error {
35
31
var sendLogs func (ctx context.Context , log ... agentsdk.Log ) error
36
32
agentURL := os .Getenv ("CODER_AGENT_URL" )
37
33
agentToken := os .Getenv ("CODER_AGENT_TOKEN" )
@@ -54,7 +50,7 @@ func main() {
54
50
}
55
51
var flushAndClose func (ctx context.Context ) error
56
52
sendLogs , flushAndClose = agentsdk .LogsSender (agentsdk .ExternalLogSourceID , client .PatchLogs , slog.Logger {})
57
- defer flushAndClose (cmd .Context ())
53
+ defer flushAndClose (inv .Context ())
58
54
59
55
// This adds the envbuilder subsystem.
60
56
// If telemetry is enabled in a Coder deployment,
@@ -70,23 +66,24 @@ func main() {
70
66
71
67
options .Logger = func (level codersdk.LogLevel , format string , args ... interface {}) {
72
68
output := fmt .Sprintf (format , args ... )
73
- fmt .Fprintln (cmd . ErrOrStderr () , output )
69
+ fmt .Fprintln (inv . Stderr , output )
74
70
if sendLogs != nil {
75
- sendLogs (cmd .Context (), agentsdk.Log {
71
+ sendLogs (inv .Context (), agentsdk.Log {
76
72
CreatedAt : time .Now (),
77
73
Output : output ,
78
74
Level : level ,
79
75
})
80
76
}
81
77
}
82
- err := envbuilder .Run (cmd .Context (), options )
78
+
79
+ err := envbuilder .Run (inv .Context (), options )
83
80
if err != nil {
84
81
options .Logger (codersdk .LogLevelError , "error: %s" , err )
85
82
}
86
83
return err
87
84
},
88
85
}
89
- err := root . Execute ()
86
+ err := cmd . Invoke (). WithOS (). Run ()
90
87
if err != nil {
91
88
fmt .Fprintf (os .Stderr , "error: %v" , err )
92
89
os .Exit (1 )
0 commit comments