arrow_up: Upgrade urfave/cli to v2 (#713)

Upgrade urfave/cli to v2

Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com>

Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com>
This commit is contained in:
Mauro Morales
2023-01-25 00:39:51 +01:00
committed by Itxaka
parent 9bd28bccf5
commit 21ab650dc3
2 changed files with 30 additions and 26 deletions

View File

@@ -16,12 +16,12 @@ import (
bundles "github.com/kairos-io/kairos/sdk/bundles" bundles "github.com/kairos-io/kairos/sdk/bundles"
"github.com/kairos-io/kairos/sdk/state" "github.com/kairos-io/kairos/sdk/state"
"github.com/urfave/cli" "github.com/urfave/cli/v2"
) )
var configScanDir = []string{"/oem", "/usr/local/cloud-config", "/run/initramfs/live"} var configScanDir = []string{"/oem", "/usr/local/cloud-config", "/run/initramfs/live"}
var cmds = []cli.Command{ var cmds = []*cli.Command{
{ {
Name: "upgrade", Name: "upgrade",
Flags: []cli.Flag{ Flags: []cli.Flag{
@@ -52,7 +52,7 @@ $ kairos upgrade list-releases
See https://kairos.io/docs/upgrade/manual/ for documentation. See https://kairos.io/docs/upgrade/manual/ for documentation.
`, `,
Subcommands: []cli.Command{ Subcommands: []*cli.Command{
{ {
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
@@ -75,10 +75,9 @@ See https://kairos.io/docs/upgrade/manual/ for documentation.
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
args := c.Args()
var v string var v string
if len(args) == 1 { if c.Args().Len() == 1 {
v = args[0] v = c.Args().First()
} }
return agent.Upgrade(v, c.String("image"), c.Bool("force"), c.Bool("debug"), configScanDir) return agent.Upgrade(v, c.String("image"), c.Bool("force"), c.Bool("debug"), configScanDir)
}, },
@@ -95,12 +94,11 @@ Sends a generic event payload with the configuration found in the scanned direct
Flags: []cli.Flag{}, Flags: []cli.Flag{},
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
dirs := []string{"/oem", "/usr/local/cloud-config"} dirs := []string{"/oem", "/usr/local/cloud-config"}
args := c.Args() if c.Args().Len() > 1 {
if len(args) > 1 { dirs = c.Args().Slice()[1:]
dirs = args[1:]
} }
return agent.Notify(args[0], dirs) return agent.Notify(c.Args().First(), dirs)
}, },
}, },
@@ -126,9 +124,8 @@ Starts the kairos agent which automatically bootstrap and advertize to the kairo
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
dirs := []string{"/oem", "/usr/local/cloud-config"} dirs := []string{"/oem", "/usr/local/cloud-config"}
args := c.Args() if c.Args().Present() {
if len(args) > 0 { dirs = c.Args().Slice()
dirs = args
} }
opts := []agent.Option{ opts := []agent.Option{
@@ -161,18 +158,17 @@ E.g. kairos-agent install-bundle container:quay.io/kairos/kairos...
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "repository", Name: "repository",
EnvVar: "REPOSITORY", EnvVars: []string{"REPOSITORY"},
Value: "docker://quay.io/kairos/packages", Value: "docker://quay.io/kairos/packages",
}, },
}, },
UsageText: "Install a bundle manually in the node", UsageText: "Install a bundle manually in the node",
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
args := c.Args() if c.Args().Len() != 1 {
if len(args) != 1 {
return fmt.Errorf("bundle name required") return fmt.Errorf("bundle name required")
} }
return bundles.RunBundles([]bundles.BundleOption{bundles.WithRepository(c.String("repository")), bundles.WithTarget(args[0])}) return bundles.RunBundles([]bundles.BundleOption{bundles.WithRepository(c.String("repository")), bundles.WithTarget(c.Args().First())})
}, },
}, },
{ {
@@ -209,7 +205,7 @@ E.g. kairos-agent install-bundle container:quay.io/kairos/kairos...
fmt.Print(runtime) fmt.Print(runtime)
return err return err
}, },
Subcommands: []cli.Command{ Subcommands: []*cli.Command{
{ {
Name: "show", Name: "show",
Usage: "Shows the machine configuration", Usage: "Shows the machine configuration",
@@ -270,7 +266,7 @@ enabled: true`,
fmt.Print(runtime) fmt.Print(runtime)
return err return err
}, },
Subcommands: []cli.Command{ Subcommands: []*cli.Command{
{ {
Name: "apply", Name: "apply",
Usage: "Applies a machine state", Usage: "Applies a machine state",
@@ -414,7 +410,11 @@ func main() {
app := &cli.App{ app := &cli.App{
Name: "kairos-agent", Name: "kairos-agent",
Version: common.VERSION, Version: common.VERSION,
Author: "Ettore Di Giacinto", Authors: []*cli.Author{
{
Name: "Ettore Di Giacinto",
},
},
Usage: "kairos agent start", Usage: "kairos agent start",
Description: ` Description: `
The kairos agent is a component to abstract away node ops, providing a common feature-set across kairos variants. The kairos agent is a component to abstract away node ops, providing a common feature-set across kairos variants.

View File

@@ -6,7 +6,7 @@ import (
"github.com/kairos-io/kairos/internal/common" "github.com/kairos-io/kairos/internal/common"
"github.com/kairos-io/kairos/sdk/profile" "github.com/kairos-io/kairos/sdk/profile"
"github.com/urfave/cli" "github.com/urfave/cli/v2"
) )
func main() { func main() {
@@ -14,7 +14,11 @@ func main() {
app := &cli.App{ app := &cli.App{
Name: "profile-build", Name: "profile-build",
Version: common.VERSION, Version: common.VERSION,
Author: "Kairos authors", Authors: []*cli.Author{
{
Name: "Kairos authors",
},
},
Usage: "Build kairos framework images", Usage: "Build kairos framework images",
Description: ` Description: `
Uses profile files to build kairos images`, Uses profile files to build kairos images`,