DRY the definition of "--source" flag

Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
Dimitris Karakasilis 2023-09-29 17:11:51 +03:00
parent 85196fbc59
commit a10390e0a8
No known key found for this signature in database
GPG Key ID: 286DCAFD2C97DDE3

25
main.go
View File

@ -54,6 +54,11 @@ func ReleasesToOutput(rels semver.Collection, output string) []string {
}
}
var sourceFlag = cli.StringFlag{
Name: "source",
Usage: "Source for upgrade. Composed of `type:address`. Accepts `file:`,`dir:` or `oci:` for the type of source.\nFor example `file:/var/share/myimage.tar`, `dir:/tmp/extracted` or `oci:repo/image:tag`",
}
var cmds = []*cli.Command{
{
Name: "upgrade",
@ -66,10 +71,7 @@ var cmds = []*cli.Command{
Name: "image",
Usage: "[DEPRECATED] Specify a full image reference, e.g.: quay.io/some/image:tag",
},
&cli.StringFlag{
Name: "source",
Usage: "Source for upgrade. Composed of `type:address`. Accepts `file:`,`dir:` or `oci:` for the type of source.\nFor example `file:/var/share/myimage.tar`, `dir:/tmp/extracted` or `oci:repo/image:tag`",
},
&sourceFlag,
&cli.BoolFlag{Name: "pre", Usage: "Include pre-releases (rc, beta, alpha)"},
&cli.BoolFlag{Name: "recovery", Usage: "Upgrade recovery"},
},
@ -378,10 +380,7 @@ This command is meant to be used from the boot GRUB menu, but can be also starte
&cli.BoolFlag{
Name: "shell",
},
&cli.StringFlag{
Name: "source",
Usage: "Source for upgrade. Composed of `type:address`. Accepts `file:`,`dir:` or `oci:` for the type of source.\nFor example `file:/var/share/myimage.tar`, `dir:/tmp/extracted` or `oci:repo/image:tag`",
},
&sourceFlag,
},
Usage: "Starts interactive installation",
Before: func(c *cli.Context) error {
@ -413,10 +412,7 @@ This command is meant to be used from the boot GRUB menu, but can be also starte
&cli.BoolFlag{
Name: "reboot",
},
&cli.StringFlag{
Name: "source",
Usage: "Source for upgrade. Composed of `type:address`. Accepts `file:`,`dir:` or `oci:` for the type of source.\nFor example `file:/var/share/myimage.tar`, `dir:/tmp/extracted` or `oci:repo/image:tag`",
},
&sourceFlag,
},
Before: func(c *cli.Context) error {
if err := validateSource(c.String("source")); err != nil {
@ -456,10 +452,7 @@ This command is meant to be used from the boot GRUB menu, but can be started man
return checkRoot()
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "source",
Usage: "Source for upgrade. Composed of `type:address`. Accepts `file:`,`dir:` or `oci:` for the type of source.\nFor example `file:/var/share/myimage.tar`, `dir:/tmp/extracted` or `oci:repo/image:tag`",
},
&sourceFlag,
},
Action: func(c *cli.Context) error {
source := c.String("source")