/
ignition_create.go
49 lines (41 loc) · 1.09 KB
/
ignition_create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package cli
import (
"os"
"path/filepath"
"context"
"github.com/spf13/cobra"
pb "github.com/poseidon/matchbox/matchbox/server/serverpb"
)
// ignitionPutCmd creates and updates Ignition templates.
var (
ignitionPutCmd = &cobra.Command{
Use: "create --file FILENAME",
Short: "Create an Ignition template",
Long: `Create an Ignition template`,
Run: runIgnitionPutCmd,
}
)
func init() {
ignitionCmd.AddCommand(ignitionPutCmd)
ignitionPutCmd.Flags().StringVarP(&flagFilename, "filename", "f", "", "filename to use to create an Ignition template")
ignitionPutCmd.MarkFlagRequired("filename")
}
func runIgnitionPutCmd(cmd *cobra.Command, args []string) {
if len(flagFilename) == 0 {
cmd.Help()
return
}
if err := validateArgs(cmd, args); err != nil {
return
}
client := mustClientFromCmd(cmd)
config, err := os.ReadFile(flagFilename)
if err != nil {
exitWithError(ExitError, err)
}
req := &pb.IgnitionPutRequest{Name: filepath.Base(flagFilename), Config: config}
_, err = client.Ignition.IgnitionPut(context.TODO(), req)
if err != nil {
exitWithError(ExitError, err)
}
}