Newer
Older
"os"
"orus.io/cloudcrane/beaver/runner"
)
DryRun bool `short:"d" long:"dry-run" description:"if set only prints commands but do not run them"`
Keep bool `short:"k" long:"keep" descriptions:"Keep the temporary files"`
DirName string `required:"yes" positional-arg-name:"directory"`
} `positional-args:"yes"`
}
// NewBuildCmd ...
func NewBuildCmd() *BuildCmd {
cmd := BuildCmd{}
return &cmd
}
// Execute ...
func (cmd *BuildCmd) Execute([]string) error {
Logger.Info().Str("directory", cmd.PositionnalArgs.DirName).Msg("starting beaver")
config := runner.NewCmdConfig(Logger, ".", cmd.PositionnalArgs.DirName, cmd.Args.DryRun)
tmpDir, err := os.MkdirTemp(os.TempDir(), "beaver-")
if err != nil {
return fmt.Errorf("failed to create temp dir: %w", err)
}
defer func() {
if err := os.RemoveAll(tmpDir); err != nil {
Logger.Err(err).Str("tempdir", tmpDir).Msg("failed to remove temp dir")
}
}()
if err := config.Initialize(tmpDir); err != nil {
return fmt.Errorf("failed to prepare config: %w", err)