|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + "fmt" |
| 6 | + |
| 7 | + "github.com/spf13/cobra" |
| 8 | + |
| 9 | + "github.com/codesphere-cloud/oms/internal/env" |
| 10 | + "github.com/codesphere-cloud/oms/internal/installer" |
| 11 | +) |
| 12 | + |
| 13 | +// ExtendBaseimageCmd represents the baseimage command |
| 14 | +type ExtendBaseimageCmd struct { |
| 15 | + cmd *cobra.Command |
| 16 | + Opts *ExtendBaseimageOpts |
| 17 | +} |
| 18 | + |
| 19 | +type ExtendBaseimageOpts struct { |
| 20 | + *GlobalOptions |
| 21 | + Package string |
| 22 | + Force bool |
| 23 | +} |
| 24 | + |
| 25 | +func (c *ExtendBaseimageCmd) RunE(_ *cobra.Command, args []string) error { |
| 26 | + if c.Opts.Package == "" { |
| 27 | + return errors.New("Required option package not set") |
| 28 | + } |
| 29 | + |
| 30 | + p := installer.NewPackage(c.Opts.Package) |
| 31 | + err := p.Extract(env.NewEnv().GetOmsWorkdir(), c.Opts.Force) |
| 32 | + if err != nil { |
| 33 | + return fmt.Errorf("failed to extract package to workdir: %w", err) |
| 34 | + } |
| 35 | + |
| 36 | + return nil |
| 37 | +} |
| 38 | + |
| 39 | +func AddExtendBaseimageCmd(extend *cobra.Command, opts *GlobalOptions) { |
| 40 | + baseimage := ExtendBaseimageCmd{ |
| 41 | + cmd: &cobra.Command{ |
| 42 | + Use: "baseimage", |
| 43 | + Short: "A brief description of your command", |
| 44 | + Long: `A longer description that spans multiple lines and likely contains examples |
| 45 | +and usage of using your command. For example: |
| 46 | +
|
| 47 | +Cobra is a CLI library for Go that empowers applications. |
| 48 | +This application is a tool to generate the needed files |
| 49 | +to quickly create a Cobra application.`, |
| 50 | + }, |
| 51 | + Opts: &ExtendBaseimageOpts{GlobalOptions: opts}, |
| 52 | + } |
| 53 | + baseimage.cmd.Flags().StringVarP(&baseimage.Opts.Package, "package", "p", "", "Package file (e.g. codesphere-v1.2.3-installer.tar.gz) to load base image from") |
| 54 | + baseimage.cmd.Flags().BoolVarP(&baseimage.Opts.Force, "force", "f", false, "Enforce package extraction") |
| 55 | + extend.AddCommand(baseimage.cmd) |
| 56 | + baseimage.cmd.RunE = baseimage.RunE |
| 57 | +} |
0 commit comments