Files
enki/cmd/convert.go

55 lines
1.5 KiB
Go
Raw Normal View History

package cmd
import (
"github.com/kairos-io/enki/pkg/action"
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
"github.com/spf13/cobra"
)
// NewConvertCmd returns a new instance of the build-iso subcommand and appends it to
// the root command.
func NewConvertCmd() *cobra.Command {
c := &cobra.Command{
Use: "convert /path/to/rootfs /path/to/result image_name",
Short: "Convert a base image to a Kairos image",
Long: "Convert a base image to a Kairos image\n\n" +
"This is best effort. Enki will try to detect the distribution and add\n" +
"the necessary bits to convert it to a Kairos image",
Args: cobra.ExactArgs(3),
PreRunE: func(cmd *cobra.Command, args []string) error {
return CheckRoot() // TODO: Do we need root?
},
RunE: func(cmd *cobra.Command, args []string) error {
// Set this after parsing of the flags, so it fails on parsing and prints usage properly
cmd.SilenceUsage = true
cmd.SilenceErrors = true // Do not propagate errors down the line, we control them
// TODO: Convert these to named arguments
rootfsDir := args[0]
resultPath := args[1]
imageName := args[2]
frameworkImage := args[3]
logger := v1.NewLogger()
runner := action.RealRunner{
Logger: logger,
}
convertAction := action.NewConverterAction(rootfsDir, resultPath, frameworkImage, imageName, runner)
err := convertAction.Run()
if err != nil {
logger.Errorf(err.Error())
return err
}
return nil
},
}
return c
}
func init() {
rootCmd.AddCommand(NewConvertCmd())
}