From 428426b6b7a03d830cbec89c300b023e0a9b02ac Mon Sep 17 00:00:00 2001 From: p4u1 Date: Fri, 23 Feb 2024 14:29:22 +0100 Subject: [PATCH 1/6] ugrade urfave/cli to v2 --- cli/app/app.go | 48 ++--- cli/app/backup.go | 2 +- cli/app/check.go | 2 +- cli/app/cmd.go | 12 +- cli/app/config.go | 2 +- cli/app/cp.go | 2 +- cli/app/deploy.go | 2 +- cli/app/errors.go | 2 +- cli/app/list.go | 2 +- cli/app/logs.go | 2 +- cli/app/new.go | 2 +- cli/app/ps.go | 2 +- cli/app/remove.go | 2 +- cli/app/restart.go | 2 +- cli/app/restore.go | 2 +- cli/app/rollback.go | 2 +- cli/app/run.go | 8 +- cli/app/secret.go | 16 +- cli/app/services.go | 2 +- cli/app/undeploy.go | 2 +- cli/app/upgrade.go | 2 +- cli/app/version.go | 2 +- cli/app/volume.go | 8 +- cli/catalogue/catalogue.go | 6 +- cli/cli.go | 16 +- cli/internal/cli.go | 310 +++++++++++++++++++------------ cli/internal/errors.go | 2 +- cli/internal/validate.go | 6 +- cli/recipe/diff.go | 2 +- cli/recipe/fetch.go | 2 +- cli/recipe/lint.go | 2 +- cli/recipe/list.go | 2 +- cli/recipe/new.go | 2 +- cli/recipe/recipe.go | 24 +-- cli/recipe/release.go | 2 +- cli/recipe/reset.go | 2 +- cli/recipe/sync.go | 2 +- cli/recipe/upgrade.go | 2 +- cli/recipe/version.go | 2 +- cli/server/add.go | 7 +- cli/server/list.go | 2 +- cli/server/prune.go | 2 +- cli/server/remove.go | 2 +- cli/server/server.go | 12 +- cli/updater/updater.go | 42 +++-- go.mod | 6 +- go.sum | 9 + pkg/autocomplete/autocomplete.go | 2 +- 48 files changed, 339 insertions(+), 257 deletions(-) diff --git a/cli/app/app.go b/cli/app/app.go index 0afa3fa6..9ac998ab 100644 --- a/cli/app/app.go +++ b/cli/app/app.go @@ -1,7 +1,7 @@ package app import ( - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var AppCommand = cli.Command{ @@ -10,28 +10,28 @@ var AppCommand = cli.Command{ Usage: "Manage apps", ArgsUsage: "", Description: "Functionality for managing the life cycle of your apps", - Subcommands: []cli.Command{ - appBackupCommand, - appCheckCommand, - appCmdCommand, - appConfigCommand, - appCpCommand, - appDeployCommand, - appErrorsCommand, - appListCommand, - appLogsCommand, - appNewCommand, - appPsCommand, - appRemoveCommand, - appRestartCommand, - appRestoreCommand, - appRollbackCommand, - appRunCommand, - appSecretCommand, - appServicesCommand, - appUndeployCommand, - appUpgradeCommand, - appVersionCommand, - appVolumeCommand, + Subcommands: []*cli.Command{ + &appBackupCommand, + &appCheckCommand, + &appCmdCommand, + &appConfigCommand, + &appCpCommand, + &appDeployCommand, + &appErrorsCommand, + &appListCommand, + &appLogsCommand, + &appNewCommand, + &appPsCommand, + &appRemoveCommand, + &appRestartCommand, + &appRestoreCommand, + &appRollbackCommand, + &appRunCommand, + &appSecretCommand, + &appServicesCommand, + &appUndeployCommand, + &appUpgradeCommand, + &appVersionCommand, + &appVolumeCommand, }, } diff --git a/cli/app/backup.go b/cli/app/backup.go index f9a239b1..d0569b43 100644 --- a/cli/app/backup.go +++ b/cli/app/backup.go @@ -24,7 +24,7 @@ import ( "github.com/docker/docker/pkg/archive" "github.com/klauspost/pgzip" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) type backupConfig struct { diff --git a/cli/app/check.go b/cli/app/check.go index 6b0e8455..4c6b1666 100644 --- a/cli/app/check.go +++ b/cli/app/check.go @@ -8,7 +8,7 @@ import ( "coopcloud.tech/abra/pkg/recipe" recipePkg "coopcloud.tech/abra/pkg/recipe" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var appCheckCommand = cli.Command{ diff --git a/cli/app/cmd.go b/cli/app/cmd.go index 002eecfa..a247ba05 100644 --- a/cli/app/cmd.go +++ b/cli/app/cmd.go @@ -17,7 +17,7 @@ import ( "coopcloud.tech/abra/pkg/recipe" recipePkg "coopcloud.tech/abra/pkg/recipe" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var appCmdCommand = cli.Command{ @@ -45,10 +45,10 @@ Example: internal.ChaosFlag, }, Before: internal.SubCommandBefore, - Subcommands: []cli.Command{appCmdListCommand}, + Subcommands: []*cli.Command{&appCmdListCommand}, BashComplete: func(ctx *cli.Context) { args := ctx.Args() - switch len(args) { + switch args.Len() { case 0: autocomplete.AppNameComplete(ctx) case 1: @@ -84,7 +84,7 @@ Example: internal.ShowSubcommandHelpAndError(c, errors.New("cannot use --local & --user together")) } - hasCmdArgs, parsedCmdArgs := parseCmdArgs(c.Args(), internal.LocalCmd) + hasCmdArgs, parsedCmdArgs := parseCmdArgs(c.Args().Slice(), internal.LocalCmd) abraSh := path.Join(config.RECIPES_DIR, app.Recipe, "abra.sh") if _, err := os.Stat(abraSh); err != nil { @@ -95,7 +95,7 @@ Example: } if internal.LocalCmd { - if !(len(c.Args()) >= 2) { + if !(c.Args().Len() >= 2) { internal.ShowSubcommandHelpAndError(c, errors.New("missing arguments")) } @@ -131,7 +131,7 @@ Example: logrus.Fatal(err) } } else { - if !(len(c.Args()) >= 3) { + if !(c.Args().Len() >= 3) { internal.ShowSubcommandHelpAndError(c, errors.New("missing arguments")) } diff --git a/cli/app/config.go b/cli/app/config.go index 9404fae4..880d77b0 100644 --- a/cli/app/config.go +++ b/cli/app/config.go @@ -10,7 +10,7 @@ import ( "coopcloud.tech/abra/pkg/config" "github.com/AlecAivazis/survey/v2" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var appConfigCommand = cli.Command{ diff --git a/cli/app/cp.go b/cli/app/cp.go index bfc2c789..ee4256b5 100644 --- a/cli/app/cp.go +++ b/cli/app/cp.go @@ -22,7 +22,7 @@ import ( "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/archive" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var appCpCommand = cli.Command{ diff --git a/cli/app/deploy.go b/cli/app/deploy.go index edf8532f..5c79dc28 100644 --- a/cli/app/deploy.go +++ b/cli/app/deploy.go @@ -17,7 +17,7 @@ import ( "coopcloud.tech/abra/pkg/recipe" "coopcloud.tech/abra/pkg/upstream/stack" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var appDeployCommand = cli.Command{ diff --git a/cli/app/errors.go b/cli/app/errors.go index 79425be8..ada5dbe8 100644 --- a/cli/app/errors.go +++ b/cli/app/errors.go @@ -17,7 +17,7 @@ import ( "github.com/docker/docker/api/types/filters" dockerClient "github.com/docker/docker/client" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var appErrorsCommand = cli.Command{ diff --git a/cli/app/list.go b/cli/app/list.go index 08dff6f2..39bc3325 100644 --- a/cli/app/list.go +++ b/cli/app/list.go @@ -13,7 +13,7 @@ import ( "coopcloud.tech/abra/pkg/recipe" "coopcloud.tech/tagcmp" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var status bool diff --git a/cli/app/logs.go b/cli/app/logs.go index b06634a2..6b5366c2 100644 --- a/cli/app/logs.go +++ b/cli/app/logs.go @@ -19,7 +19,7 @@ import ( "github.com/docker/docker/api/types/swarm" dockerClient "github.com/docker/docker/client" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var appLogsCommand = cli.Command{ diff --git a/cli/app/new.go b/cli/app/new.go index 22f51fd2..68f45764 100644 --- a/cli/app/new.go +++ b/cli/app/new.go @@ -16,7 +16,7 @@ import ( "github.com/AlecAivazis/survey/v2" dockerClient "github.com/docker/docker/client" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var appNewDescription = ` diff --git a/cli/app/ps.go b/cli/app/ps.go index b593a64f..03a6928d 100644 --- a/cli/app/ps.go +++ b/cli/app/ps.go @@ -17,7 +17,7 @@ import ( "github.com/docker/docker/api/types" dockerClient "github.com/docker/docker/client" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var appPsCommand = cli.Command{ diff --git a/cli/app/remove.go b/cli/app/remove.go index ea4efedf..faa6801f 100644 --- a/cli/app/remove.go +++ b/cli/app/remove.go @@ -13,7 +13,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/volume" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var appRemoveCommand = cli.Command{ diff --git a/cli/app/restart.go b/cli/app/restart.go index 15b4cfd0..9737194b 100644 --- a/cli/app/restart.go +++ b/cli/app/restart.go @@ -11,7 +11,7 @@ import ( upstream "coopcloud.tech/abra/pkg/upstream/service" stack "coopcloud.tech/abra/pkg/upstream/stack" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var appRestartCommand = cli.Command{ diff --git a/cli/app/restore.go b/cli/app/restore.go index 1bf9c840..26d78b01 100644 --- a/cli/app/restore.go +++ b/cli/app/restore.go @@ -20,7 +20,7 @@ import ( dockerClient "github.com/docker/docker/client" "github.com/docker/docker/pkg/archive" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) type restoreConfig struct { diff --git a/cli/app/rollback.go b/cli/app/rollback.go index f39d114b..9669c031 100644 --- a/cli/app/rollback.go +++ b/cli/app/rollback.go @@ -15,7 +15,7 @@ import ( "coopcloud.tech/abra/pkg/client" "github.com/AlecAivazis/survey/v2" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var appRollbackCommand = cli.Command{ diff --git a/cli/app/run.go b/cli/app/run.go index 4ae68c1b..60c50708 100644 --- a/cli/app/run.go +++ b/cli/app/run.go @@ -14,7 +14,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var user string @@ -45,11 +45,11 @@ var appRunCommand = cli.Command{ Action: func(c *cli.Context) error { app := internal.ValidateApp(c) - if len(c.Args()) < 2 { + if c.Args().Len() < 2 { internal.ShowSubcommandHelpAndError(c, errors.New("no provided?")) } - if len(c.Args()) < 3 { + if c.Args().Len() < 3 { internal.ShowSubcommandHelpAndError(c, errors.New("no provided?")) } @@ -68,7 +68,7 @@ var appRunCommand = cli.Command{ logrus.Fatal(err) } - cmd := c.Args()[2:] + cmd := c.Args().Slice()[2:] execCreateOpts := types.ExecConfig{ AttachStderr: true, AttachStdin: true, diff --git a/cli/app/secret.go b/cli/app/secret.go index 3b491055..28aa7169 100644 --- a/cli/app/secret.go +++ b/cli/app/secret.go @@ -17,7 +17,7 @@ import ( "github.com/docker/docker/api/types" dockerClient "github.com/docker/docker/client" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var ( @@ -76,7 +76,7 @@ var appSecretGenerateCommand = cli.Command{ } } - if len(c.Args()) == 1 && !allSecrets { + if c.Args().Len() == 1 && !allSecrets { err := errors.New("missing arguments / or '--all'") internal.ShowSubcommandHelpAndError(c, err) } @@ -175,7 +175,7 @@ Example: Action: func(c *cli.Context) error { app := internal.ValidateApp(c) - if len(c.Args()) != 4 { + if c.Args().Len() != 4 { internal.ShowSubcommandHelpAndError(c, errors.New("missing arguments?")) } @@ -419,10 +419,10 @@ var appSecretCommand = cli.Command{ Aliases: []string{"s"}, Usage: "Manage app secrets", ArgsUsage: "", - Subcommands: []cli.Command{ - appSecretGenerateCommand, - appSecretInsertCommand, - appSecretRmCommand, - appSecretLsCommand, + Subcommands: []*cli.Command{ + &appSecretGenerateCommand, + &appSecretInsertCommand, + &appSecretRmCommand, + &appSecretLsCommand, }, } diff --git a/cli/app/services.go b/cli/app/services.go index 60a7245e..3f473497 100644 --- a/cli/app/services.go +++ b/cli/app/services.go @@ -13,7 +13,7 @@ import ( stack "coopcloud.tech/abra/pkg/upstream/stack" "github.com/docker/docker/api/types" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var appServicesCommand = cli.Command{ diff --git a/cli/app/undeploy.go b/cli/app/undeploy.go index 3a1c2ffa..114abbc1 100644 --- a/cli/app/undeploy.go +++ b/cli/app/undeploy.go @@ -14,7 +14,7 @@ import ( "github.com/docker/docker/api/types/filters" dockerClient "github.com/docker/docker/client" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var prune bool diff --git a/cli/app/upgrade.go b/cli/app/upgrade.go index 8c10337b..7a61f9d3 100644 --- a/cli/app/upgrade.go +++ b/cli/app/upgrade.go @@ -15,7 +15,7 @@ import ( "coopcloud.tech/tagcmp" "github.com/AlecAivazis/survey/v2" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var appUpgradeCommand = cli.Command{ diff --git a/cli/app/version.go b/cli/app/version.go index 7227ffdd..1c2870c3 100644 --- a/cli/app/version.go +++ b/cli/app/version.go @@ -13,7 +13,7 @@ import ( "github.com/docker/distribution/reference" "github.com/olekukonko/tablewriter" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func sortServiceByName(versions [][]string) func(i, j int) bool { diff --git a/cli/app/volume.go b/cli/app/volume.go index b64ce69c..02c1d140 100644 --- a/cli/app/volume.go +++ b/cli/app/volume.go @@ -10,7 +10,7 @@ import ( "coopcloud.tech/abra/pkg/upstream/stack" "github.com/AlecAivazis/survey/v2" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var appVolumeListCommand = cli.Command{ @@ -150,8 +150,8 @@ var appVolumeCommand = cli.Command{ Aliases: []string{"vl"}, Usage: "Manage app volumes", ArgsUsage: "", - Subcommands: []cli.Command{ - appVolumeListCommand, - appVolumeRemoveCommand, + Subcommands: []*cli.Command{ + &appVolumeListCommand, + &appVolumeRemoveCommand, }, } diff --git a/cli/catalogue/catalogue.go b/cli/catalogue/catalogue.go index b7d09ccc..3fc57a2d 100644 --- a/cli/catalogue/catalogue.go +++ b/cli/catalogue/catalogue.go @@ -15,7 +15,7 @@ import ( "coopcloud.tech/abra/pkg/recipe" "github.com/go-git/go-git/v5" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var catalogueGenerateCommand = cli.Command{ @@ -217,7 +217,7 @@ var CatalogueCommand = cli.Command{ Aliases: []string{"c"}, ArgsUsage: "", Description: "This command helps recipe packagers interact with the recipe catalogue", - Subcommands: []cli.Command{ - catalogueGenerateCommand, + Subcommands: []*cli.Command{ + &catalogueGenerateCommand, }, } diff --git a/cli/cli.go b/cli/cli.go index e338d390..0f5ce7e7 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -18,7 +18,7 @@ import ( "coopcloud.tech/abra/pkg/config" "coopcloud.tech/abra/pkg/web" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // AutoCompleteCommand helps people set up auto-complete in their shells @@ -153,13 +153,13 @@ func newAbraApp(version, commit string) *cli.App { |_| `, Version: fmt.Sprintf("%s-%s", version, commit[:7]), - Commands: []cli.Command{ - app.AppCommand, - server.ServerCommand, - recipe.RecipeCommand, - catalogue.CatalogueCommand, - UpgradeCommand, - AutoCompleteCommand, + Commands: []*cli.Command{ + &app.AppCommand, + &server.ServerCommand, + &recipe.RecipeCommand, + &catalogue.CatalogueCommand, + &UpgradeCommand, + &AutoCompleteCommand, }, BashComplete: autocomplete.SubcommandComplete, } diff --git a/cli/internal/cli.go b/cli/internal/cli.go index b7555bdc..f8161151 100644 --- a/cli/internal/cli.go +++ b/cli/internal/cli.go @@ -5,7 +5,7 @@ import ( logrusStack "github.com/Gurpartap/logrus-stack" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Secrets stores the variable from SecretsFlag @@ -13,7 +13,8 @@ var Secrets bool // SecretsFlag turns on/off automatically generating secrets var SecretsFlag = &cli.BoolFlag{ - Name: "secrets, S", + Name: "secrets", + Aliases: []string{"S"}, Usage: "Automatically generate secrets", Destination: &Secrets, } @@ -23,7 +24,8 @@ var Pass bool // PassFlag turns on/off storing generated secrets in pass var PassFlag = &cli.BoolFlag{ - Name: "pass, p", + Name: "pass", + Aliases: []string{"p"}, Usage: "Store the generated secrets in a local pass store", Destination: &Pass, } @@ -33,7 +35,8 @@ var PassRemove bool // PassRemoveFlag turns on/off removing generated secrets from pass var PassRemoveFlag = &cli.BoolFlag{ - Name: "pass, p", + Name: "pass", + Aliases: []string{"p"}, Usage: "Remove generated secrets from a local pass store", Destination: &PassRemove, } @@ -43,7 +46,8 @@ var Force bool // ForceFlag turns on/off force functionality. var ForceFlag = &cli.BoolFlag{ - Name: "force, f", + Name: "force", + Aliases: []string{"f"}, Usage: "Perform action without further prompt. Use with care!", Destination: &Force, } @@ -53,7 +57,8 @@ var Chaos bool // ChaosFlag turns on/off chaos functionality. var ChaosFlag = &cli.BoolFlag{ - Name: "chaos, C", + Name: "chaos", + Aliases: []string{"C"}, Usage: "Proceed with uncommitted recipes changes. Use with care!", Destination: &Chaos, } @@ -63,24 +68,29 @@ var Tty bool // TtyFlag turns on/off tty mode. var TtyFlag = &cli.BoolFlag{ - Name: "tty, T", + Name: "tty", + Aliases: []string{"T"}, Usage: "Disables TTY mode to run this command from a script.", Destination: &Tty, } -var NoInput bool -var NoInputFlag = &cli.BoolFlag{ - Name: "no-input, n", - Usage: "Toggle non-interactive mode", - Destination: &NoInput, -} +var ( + NoInput bool + NoInputFlag = &cli.BoolFlag{ + Name: "no-input", + Aliases: []string{"n"}, + Usage: "Toggle non-interactive mode", + Destination: &NoInput, + } +) // Debug stores the variable from DebugFlag. var Debug bool // DebugFlag turns on/off verbose logging down to the DEBUG level. var DebugFlag = &cli.BoolFlag{ - Name: "debug, d", + Name: "debug", + Aliases: []string{"d"}, Destination: &Debug, Usage: "Show DEBUG messages", } @@ -90,7 +100,8 @@ var Offline bool // DebugFlag turns on/off offline mode. var OfflineFlag = &cli.BoolFlag{ - Name: "offline, o", + Name: "offline", + Aliases: []string{"o"}, Destination: &Offline, Usage: "Prefer offline & filesystem access when possible", } @@ -100,7 +111,8 @@ var MachineReadable bool // MachineReadableFlag turns on/off machine readable output where supported var MachineReadableFlag = &cli.BoolFlag{ - Name: "machine, m", + Name: "machine", + Aliases: []string{"m"}, Destination: &MachineReadable, Usage: "Output in a machine-readable format (where supported)", } @@ -110,133 +122,185 @@ var RC bool // RCFlag chooses the latest release candidate for install var RCFlag = &cli.BoolFlag{ - Name: "rc, r", + Name: "rc", + Aliases: []string{"c"}, Destination: &RC, Usage: "Install the latest release candidate", } -var Major bool -var MajorFlag = &cli.BoolFlag{ - Name: "major, x", - Usage: "Increase the major part of the version", - Destination: &Major, -} +var ( + Major bool + MajorFlag = &cli.BoolFlag{ + Name: "major", + Aliases: []string{"x"}, + Usage: "Increase the major part of the version", + Destination: &Major, + } +) -var Minor bool -var MinorFlag = &cli.BoolFlag{ - Name: "minor, y", - Usage: "Increase the minor part of the version", - Destination: &Minor, -} +var ( + Minor bool + MinorFlag = &cli.BoolFlag{ + Name: "minor", + Aliases: []string{"y"}, + Usage: "Increase the minor part of the version", + Destination: &Minor, + } +) -var Patch bool -var PatchFlag = &cli.BoolFlag{ - Name: "patch, z", - Usage: "Increase the patch part of the version", - Destination: &Patch, -} +var ( + Patch bool + PatchFlag = &cli.BoolFlag{ + Name: "patch", + Aliases: []string{"z"}, + Usage: "Increase the patch part of the version", + Destination: &Patch, + } +) -var Dry bool -var DryFlag = &cli.BoolFlag{ - Name: "dry-run, r", - Usage: "Only reports changes that would be made", - Destination: &Dry, -} +var ( + Dry bool + DryFlag = &cli.BoolFlag{ + Name: "dry-run", + Aliases: []string{"r"}, + Usage: "Only reports changes that would be made", + Destination: &Dry, + } +) -var Publish bool -var PublishFlag = &cli.BoolFlag{ - Name: "publish, p", - Usage: "Publish changes to git.coopcloud.tech", - Destination: &Publish, -} +var ( + Publish bool + PublishFlag = &cli.BoolFlag{ + Name: "publish", + Aliases: []string{"p"}, + Usage: "Publish changes to git.coopcloud.tech", + Destination: &Publish, + } +) -var Domain string -var DomainFlag = &cli.StringFlag{ - Name: "domain, D", - Value: "", - Usage: "Choose a domain name", - Destination: &Domain, -} +var ( + Domain string + DomainFlag = &cli.StringFlag{ + Name: "domain", + Aliases: []string{"D"}, + Value: "", + Usage: "Choose a domain name", + Destination: &Domain, + } +) -var NewAppServer string -var NewAppServerFlag = &cli.StringFlag{ - Name: "server, s", - Value: "", - Usage: "Show apps of a specific server", - Destination: &NewAppServer, -} +var ( + NewAppServer string + NewAppServerFlag = &cli.StringFlag{ + Name: "server", + Aliases: []string{"s"}, + Value: "", + Usage: "Show apps of a specific server", + Destination: &NewAppServer, + } +) -var NoDomainChecks bool -var NoDomainChecksFlag = &cli.BoolFlag{ - Name: "no-domain-checks, D", - Usage: "Disable app domain sanity checks", - Destination: &NoDomainChecks, -} +var ( + NoDomainChecks bool + NoDomainChecksFlag = &cli.BoolFlag{ + Name: "no-domain-checks", + Aliases: []string{"D"}, + Usage: "Disable app domain sanity checks", + Destination: &NoDomainChecks, + } +) -var StdErrOnly bool -var StdErrOnlyFlag = &cli.BoolFlag{ - Name: "stderr, s", - Usage: "Only tail stderr", - Destination: &StdErrOnly, -} +var ( + StdErrOnly bool + StdErrOnlyFlag = &cli.BoolFlag{ + Name: "stderr", + Aliases: []string{"s"}, + Usage: "Only tail stderr", + Destination: &StdErrOnly, + } +) -var SinceLogs string -var SinceLogsFlag = &cli.StringFlag{ - Name: "since, S", - Value: "", - Usage: "tail logs since YYYY-MM-DDTHH:MM:SSZ", - Destination: &SinceLogs, -} +var ( + SinceLogs string + SinceLogsFlag = &cli.StringFlag{ + Name: "since", + Aliases: []string{"S"}, + Value: "", + Usage: "tail logs since YYYY-MM-DDTHH:MM:SSZ", + Destination: &SinceLogs, + } +) -var DontWaitConverge bool -var DontWaitConvergeFlag = &cli.BoolFlag{ - Name: "no-converge-checks, c", - Usage: "Don't wait for converge logic checks", - Destination: &DontWaitConverge, -} +var ( + DontWaitConverge bool + DontWaitConvergeFlag = &cli.BoolFlag{ + Name: "no-converge-checks", + Aliases: []string{"c"}, + Usage: "Don't wait for converge logic checks", + Destination: &DontWaitConverge, + } +) -var Watch bool -var WatchFlag = &cli.BoolFlag{ - Name: "watch, w", - Usage: "Watch status by polling repeatedly", - Destination: &Watch, -} +var ( + Watch bool + WatchFlag = &cli.BoolFlag{ + Name: "watch", + Aliases: []string{"w"}, + Usage: "Watch status by polling repeatedly", + Destination: &Watch, + } +) -var OnlyErrors bool -var OnlyErrorFlag = &cli.BoolFlag{ - Name: "errors, e", - Usage: "Only show errors", - Destination: &OnlyErrors, -} +var ( + OnlyErrors bool + OnlyErrorFlag = &cli.BoolFlag{ + Name: "errors", + Aliases: []string{"e"}, + Usage: "Only show errors", + Destination: &OnlyErrors, + } +) -var SkipUpdates bool -var SkipUpdatesFlag = &cli.BoolFlag{ - Name: "skip-updates, s", - Usage: "Skip updating recipe repositories", - Destination: &SkipUpdates, -} +var ( + SkipUpdates bool + SkipUpdatesFlag = &cli.BoolFlag{ + Name: "skip-updates", + Aliases: []string{"s"}, + Usage: "Skip updating recipe repositories", + Destination: &SkipUpdates, + } +) -var AllTags bool -var AllTagsFlag = &cli.BoolFlag{ - Name: "all-tags, a", - Usage: "List all tags, not just upgrades", - Destination: &AllTags, -} +var ( + AllTags bool + AllTagsFlag = &cli.BoolFlag{ + Name: "all-tags", + Aliases: []string{"a"}, + Usage: "List all tags, not just upgrades", + Destination: &AllTags, + } +) -var LocalCmd bool -var LocalCmdFlag = &cli.BoolFlag{ - Name: "local, l", - Usage: "Run command locally", - Destination: &LocalCmd, -} +var ( + LocalCmd bool + LocalCmdFlag = &cli.BoolFlag{ + Name: "local", + Aliases: []string{"l"}, + Usage: "Run command locally", + Destination: &LocalCmd, + } +) -var RemoteUser string -var RemoteUserFlag = &cli.StringFlag{ - Name: "user, u", - Value: "", - Usage: "User to run command within a service context", - Destination: &RemoteUser, -} +var ( + RemoteUser string + RemoteUserFlag = &cli.StringFlag{ + Name: "user", + Aliases: []string{"u"}, + Value: "", + Usage: "User to run command within a service context", + Destination: &RemoteUser, + } +) // SubCommandBefore wires up pre-action machinery (e.g. --debug handling). func SubCommandBefore(c *cli.Context) error { diff --git a/cli/internal/errors.go b/cli/internal/errors.go index b2885dba..ccd6e3fb 100644 --- a/cli/internal/errors.go +++ b/cli/internal/errors.go @@ -4,7 +4,7 @@ import ( "os" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // ShowSubcommandHelpAndError exits the program on error, logs the error to the diff --git a/cli/internal/validate.go b/cli/internal/validate.go index 46a442d6..be15738e 100644 --- a/cli/internal/validate.go +++ b/cli/internal/validate.go @@ -9,7 +9,7 @@ import ( "coopcloud.tech/abra/pkg/recipe" "github.com/AlecAivazis/survey/v2" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // ValidateRecipe ensures the recipe arg is valid. @@ -120,9 +120,9 @@ func ValidateDomain(c *cli.Context) string { // ValidateSubCmdFlags ensures flag order conforms to correct order func ValidateSubCmdFlags(c *cli.Context) bool { - for argIdx, arg := range c.Args() { + for argIdx, arg := range c.Args().Slice() { if !strings.HasPrefix(arg, "--") { - for _, flag := range c.Args()[argIdx:] { + for _, flag := range c.Args().Slice()[argIdx:] { if strings.HasPrefix(flag, "--") { return false } diff --git a/cli/recipe/diff.go b/cli/recipe/diff.go index f505bbe6..73dd5407 100644 --- a/cli/recipe/diff.go +++ b/cli/recipe/diff.go @@ -8,7 +8,7 @@ import ( "coopcloud.tech/abra/pkg/config" gitPkg "coopcloud.tech/abra/pkg/git" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var recipeDiffCommand = cli.Command{ diff --git a/cli/recipe/fetch.go b/cli/recipe/fetch.go index acfc1708..071f4c1b 100644 --- a/cli/recipe/fetch.go +++ b/cli/recipe/fetch.go @@ -5,7 +5,7 @@ import ( "coopcloud.tech/abra/pkg/autocomplete" "coopcloud.tech/abra/pkg/recipe" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var recipeFetchCommand = cli.Command{ diff --git a/cli/recipe/lint.go b/cli/recipe/lint.go index 542164f9..be17e82c 100644 --- a/cli/recipe/lint.go +++ b/cli/recipe/lint.go @@ -9,7 +9,7 @@ import ( "coopcloud.tech/abra/pkg/lint" recipePkg "coopcloud.tech/abra/pkg/recipe" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var recipeLintCommand = cli.Command{ diff --git a/cli/recipe/list.go b/cli/recipe/list.go index 4ad35476..7bbbb7c7 100644 --- a/cli/recipe/list.go +++ b/cli/recipe/list.go @@ -10,7 +10,7 @@ import ( "coopcloud.tech/abra/pkg/formatter" "coopcloud.tech/abra/pkg/recipe" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var pattern string diff --git a/cli/recipe/new.go b/cli/recipe/new.go index 87e84d87..bdaf55e8 100644 --- a/cli/recipe/new.go +++ b/cli/recipe/new.go @@ -13,7 +13,7 @@ import ( "coopcloud.tech/abra/pkg/config" "coopcloud.tech/abra/pkg/git" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // recipeMetadata is the recipe metadata for the README.md diff --git a/cli/recipe/recipe.go b/cli/recipe/recipe.go index ad3b6365..e2230ea8 100644 --- a/cli/recipe/recipe.go +++ b/cli/recipe/recipe.go @@ -1,7 +1,7 @@ package recipe import ( - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // RecipeCommand defines all recipe related sub-commands. @@ -21,16 +21,16 @@ sure the recipe is in good working order and the config upgraded in a timely manner. Abra supports convenient automation for recipe maintainenace, see the "abra recipe upgrade", "abra recipe sync" and "abra recipe release" commands. `, - Subcommands: []cli.Command{ - recipeFetchCommand, - recipeLintCommand, - recipeListCommand, - recipeNewCommand, - recipeReleaseCommand, - recipeSyncCommand, - recipeUpgradeCommand, - recipeVersionCommand, - recipeResetCommand, - recipeDiffCommand, + Subcommands: []*cli.Command{ + &recipeFetchCommand, + &recipeLintCommand, + &recipeListCommand, + &recipeNewCommand, + &recipeReleaseCommand, + &recipeSyncCommand, + &recipeUpgradeCommand, + &recipeVersionCommand, + &recipeResetCommand, + &recipeDiffCommand, }, } diff --git a/cli/recipe/release.go b/cli/recipe/release.go index d2da8230..af518162 100644 --- a/cli/recipe/release.go +++ b/cli/recipe/release.go @@ -20,7 +20,7 @@ import ( "github.com/docker/distribution/reference" "github.com/go-git/go-git/v5" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var recipeReleaseCommand = cli.Command{ diff --git a/cli/recipe/reset.go b/cli/recipe/reset.go index 67208cdc..e4f39d34 100644 --- a/cli/recipe/reset.go +++ b/cli/recipe/reset.go @@ -8,7 +8,7 @@ import ( "coopcloud.tech/abra/pkg/config" "github.com/go-git/go-git/v5" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var recipeResetCommand = cli.Command{ diff --git a/cli/recipe/sync.go b/cli/recipe/sync.go index d5b4ad00..1848a4f4 100644 --- a/cli/recipe/sync.go +++ b/cli/recipe/sync.go @@ -14,7 +14,7 @@ import ( "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var recipeSyncCommand = cli.Command{ diff --git a/cli/recipe/upgrade.go b/cli/recipe/upgrade.go index 4a4a33e2..f81df0a7 100644 --- a/cli/recipe/upgrade.go +++ b/cli/recipe/upgrade.go @@ -20,7 +20,7 @@ import ( "github.com/AlecAivazis/survey/v2" "github.com/docker/distribution/reference" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) type imgPin struct { diff --git a/cli/recipe/version.go b/cli/recipe/version.go index db276fe5..262c1cd3 100644 --- a/cli/recipe/version.go +++ b/cli/recipe/version.go @@ -10,7 +10,7 @@ import ( recipePkg "coopcloud.tech/abra/pkg/recipe" "github.com/olekukonko/tablewriter" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func sortServiceByName(versions [][]string) func(i, j int) bool { diff --git a/cli/server/add.go b/cli/server/add.go index c4bf6f13..1219d803 100644 --- a/cli/server/add.go +++ b/cli/server/add.go @@ -13,12 +13,13 @@ import ( "coopcloud.tech/abra/pkg/server" sshPkg "coopcloud.tech/abra/pkg/ssh" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var local bool var localFlag = &cli.BoolFlag{ - Name: "local, l", + Name: "local", + Aliases: []string{"l"}, Usage: "Use local server", Destination: &local, } @@ -122,7 +123,7 @@ developer machine. Before: internal.SubCommandBefore, ArgsUsage: "", Action: func(c *cli.Context) error { - if len(c.Args()) > 0 && local || !internal.ValidateSubCmdFlags(c) { + if c.Args().Len() > 0 && local || !internal.ValidateSubCmdFlags(c) { err := errors.New("cannot use and --local together") internal.ShowSubcommandHelpAndError(c, err) } diff --git a/cli/server/list.go b/cli/server/list.go index 6eaad343..1c40f0ed 100644 --- a/cli/server/list.go +++ b/cli/server/list.go @@ -9,7 +9,7 @@ import ( "coopcloud.tech/abra/pkg/formatter" "github.com/docker/cli/cli/connhelper/ssh" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var problemsFilter bool diff --git a/cli/server/prune.go b/cli/server/prune.go index 8945aadf..769dd244 100644 --- a/cli/server/prune.go +++ b/cli/server/prune.go @@ -9,7 +9,7 @@ import ( "coopcloud.tech/abra/pkg/formatter" "github.com/docker/docker/api/types/filters" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var allFilter bool diff --git a/cli/server/remove.go b/cli/server/remove.go index 83817c5a..8f29e7db 100644 --- a/cli/server/remove.go +++ b/cli/server/remove.go @@ -9,7 +9,7 @@ import ( "coopcloud.tech/abra/pkg/client" "coopcloud.tech/abra/pkg/config" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var serverRemoveCommand = cli.Command{ diff --git a/cli/server/server.go b/cli/server/server.go index 5d1c36d7..196702dd 100644 --- a/cli/server/server.go +++ b/cli/server/server.go @@ -1,7 +1,7 @@ package server import ( - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // ServerCommand defines the `abra server` command and its subcommands @@ -9,10 +9,10 @@ var ServerCommand = cli.Command{ Name: "server", Aliases: []string{"s"}, Usage: "Manage servers", - Subcommands: []cli.Command{ - serverAddCommand, - serverListCommand, - serverRemoveCommand, - serverPruneCommand, + Subcommands: []*cli.Command{ + &serverAddCommand, + &serverListCommand, + &serverRemoveCommand, + &serverPruneCommand, }, } diff --git a/cli/updater/updater.go b/cli/updater/updater.go index 4b036132..5a730c6c 100644 --- a/cli/updater/updater.go +++ b/cli/updater/updater.go @@ -21,24 +21,28 @@ import ( dockerclient "github.com/docker/docker/client" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const SERVER = "localhost" -var majorUpdate bool -var majorFlag = &cli.BoolFlag{ - Name: "major, m", - Usage: "Also check for major updates", - Destination: &majorUpdate, -} +var ( + majorUpdate bool + majorFlag = &cli.BoolFlag{ + Name: "major", + Aliases: []string{"m"}, + Usage: "Also check for major updates", + Destination: &majorUpdate, + } -var updateAll bool -var allFlag = &cli.BoolFlag{ - Name: "all, a", - Usage: "Update all deployed apps", - Destination: &updateAll, -} + updateAll bool + allFlag = &cli.BoolFlag{ + Name: "all", + Aliases: []string{"a"}, + Usage: "Update all deployed apps", + Destination: &updateAll, + } +) // Notify checks for available upgrades var Notify = cli.Command{ @@ -271,7 +275,8 @@ func getDeployedVersion(cl *dockerclient.Client, stackName string, recipeName st // than the deployed version. It only includes major upgrades if the "--major" // flag is set. func getAvailableUpgrades(cl *dockerclient.Client, stackName string, recipeName string, - deployedVersion string) ([]string, error) { + deployedVersion string, +) ([]string, error) { catl, err := recipe.ReadRecipeCatalogue(internal.Offline) if err != nil { return nil, err @@ -429,7 +434,8 @@ func tryUpgrade(cl *dockerclient.Client, stackName, recipeName string) error { // upgrade performs all necessary steps to upgrade an app. func upgrade(cl *dockerclient.Client, stackName, recipeName, - upgradeVersion string) error { + upgradeVersion string, +) error { env, err := getEnv(cl, stackName) if err != nil { return err @@ -474,9 +480,9 @@ func newAbraApp(version, commit string) *cli.App { |_| `, Version: fmt.Sprintf("%s-%s", version, commit[:7]), - Commands: []cli.Command{ - Notify, - UpgradeApp, + Commands: []*cli.Command{ + &Notify, + &UpgradeApp, }, } diff --git a/go.mod b/go.mod index 5287ec3d..0e11be03 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,7 @@ require ( require ( dario.cat/mergo v1.0.0 // indirect github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect - github.com/BurntSushi/toml v1.0.0 // indirect + github.com/BurntSushi/toml v1.3.2 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect github.com/Microsoft/hcsshim v0.9.2 // indirect github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect @@ -32,7 +32,7 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/cloudflare/circl v1.3.3 // indirect - github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/distribution/reference v0.5.0 // indirect @@ -75,9 +75,11 @@ require ( github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/skeema/knownhosts v1.2.0 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/urfave/cli/v2 v2.27.1 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect github.com/xeipuuv/gojsonschema v1.2.0 // indirect + github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e // indirect golang.org/x/crypto v0.14.0 // indirect golang.org/x/mod v0.12.0 // indirect golang.org/x/net v0.17.0 // indirect diff --git a/go.sum b/go.sum index d767d61e..64298a4e 100644 --- a/go.sum +++ b/go.sum @@ -74,6 +74,8 @@ github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBp github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU= github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= +github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/Gurpartap/logrus-stack v0.0.0-20170710170904-89c00d8a28f4 h1:vdT7QwBhJJEVNFMBNhRSFDRCB6O16T28VhvqRgqFyn8= @@ -311,6 +313,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:ma github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU= github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM= +github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= @@ -893,6 +897,7 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= @@ -992,6 +997,8 @@ github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX github.com/urfave/cli v1.22.4/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli v1.22.9 h1:cv3/KhXGBGjEXLC4bH0sLuJ9BewaAbpk5oyMOveu4pw= github.com/urfave/cli v1.22.9/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho= +github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= github.com/vbatts/tar-split v0.11.2/go.mod h1:vV3ZuO2yWSVsz+pfFzDG/upWH1JhjOiEaWq6kXyQ3VI= github.com/vishvananda/netlink v0.0.0-20181108222139-023a6dafdcdf/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk= github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE= @@ -1013,6 +1020,8 @@ github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17 github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e h1:+SOyEddqYF09QP7vr7CgJ1eti3pY9Fn3LHO1M1r/0sI= +github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/pkg/autocomplete/autocomplete.go b/pkg/autocomplete/autocomplete.go index 9d5075d6..569e9bab 100644 --- a/pkg/autocomplete/autocomplete.go +++ b/pkg/autocomplete/autocomplete.go @@ -6,7 +6,7 @@ import ( "coopcloud.tech/abra/pkg/config" "coopcloud.tech/abra/pkg/recipe" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // AppNameComplete copletes app names. -- 2.45.2 From ac39d6ab9773010c069d9880802d7b99315e8168 Mon Sep 17 00:00:00 2001 From: p4u1 Date: Sun, 18 Feb 2024 20:40:58 +0100 Subject: [PATCH 2/6] partially fix tests/integration/app_cmd.bats --- tests/integration/app_cmd.bats | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/integration/app_cmd.bats b/tests/integration/app_cmd.bats index db2808ba..648d7cc3 100644 --- a/tests/integration/app_cmd.bats +++ b/tests/integration/app_cmd.bats @@ -58,7 +58,7 @@ test_cmd_export" assert_success assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE" - run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd --local + run $ABRA app cmd --local "$TEST_APP_DOMAIN" test_cmd assert_success assert_output --partial 'baz' @@ -70,7 +70,7 @@ test_cmd_export" assert_success assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" - run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd --local + run $ABRA app cmd --local "$TEST_APP_DOMAIN" test_cmd assert_failure assert_output --partial 'locally unstaged changes' @@ -83,7 +83,7 @@ test_cmd_export" assert_success assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" - run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd --local --chaos + run $ABRA app cmd --local --chaos "$TEST_APP_DOMAIN" test_cmd assert_success assert_output --partial 'baz' @@ -96,14 +96,14 @@ test_cmd_export" assert_success run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status - assert_output --partial 'behind 3' + assert_output --partial "Your branch is behind 'origin/main' by 3 commits" - run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd --local + run $ABRA app cmd --local "$TEST_APP_DOMAIN" test_cmd assert_success assert_output --partial 'baz' run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status - refute_output --partial 'behind 3' + assert_output --partial "Your branch is up to date with 'origin/main'" _reset_recipe "$TEST_RECIPE" } @@ -113,14 +113,14 @@ test_cmd_export" assert_success run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status - assert_output --partial 'behind 3' + assert_output --partial "Your branch is behind 'origin/main' by 3 commits" - run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd --local --offline + run $ABRA app cmd --local --offline "$TEST_APP_DOMAIN" test_cmd assert_success assert_output --partial 'baz' run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status - assert_output --partial 'behind 3' + assert_output --partial "Your branch is behind 'origin/main' by 3 commits" _reset_recipe "$TEST_RECIPE" } @@ -132,13 +132,13 @@ test_cmd_export" } @test "error if missing arguments when passing --local" { - run $ABRA app cmd "$TEST_APP_DOMAIN" --local + run $ABRA app cmd --local "$TEST_APP_DOMAIN" assert_failure assert_output --partial 'missing arguments' } @test "cannot use --local and --user at same time" { - run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd --local --user root + run $ABRA app cmd --local --user root "$TEST_APP_DOMAIN" test_cmd assert_failure assert_output --partial 'cannot use --local & --user together' } @@ -147,7 +147,7 @@ test_cmd_export" run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/abra.sh" assert_success - run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd --local --chaos + run $ABRA app cmd --local --chaos "$TEST_APP_DOMAIN" test_cmd assert_failure assert_output --partial "$ABRA_DIR/recipes/$TEST_RECIPE/abra.sh does not exist" @@ -155,25 +155,25 @@ test_cmd_export" } @test "error if missing command" { - run $ABRA app cmd "$TEST_APP_DOMAIN" doesnt_exist --local + run $ABRA app cmd --local "$TEST_APP_DOMAIN" doesnt_exist assert_failure assert_output --partial "doesn't have a doesnt_exist function" } @test "run --local command" { - run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd --local + run $ABRA app cmd --local "$TEST_APP_DOMAIN" test_cmd assert_success assert_output --partial 'baz' } @test "run command with single arg" { - run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd_arg --local -- bing + run $ABRA app cmd --local "$TEST_APP_DOMAIN" test_cmd_arg -- bing assert_success assert_output --partial 'bing' } @test "run command with several args" { - run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd_args --local -- bong bang + run $ABRA app cmd --local "$TEST_APP_DOMAIN" test_cmd_args -- bong bang assert_success assert_output --partial 'bong bang' } -- 2.45.2 From deb4293fba78cc48bdfb12392ff08ab2bda88dd0 Mon Sep 17 00:00:00 2001 From: p4u1 Date: Fri, 23 Feb 2024 14:51:10 +0100 Subject: [PATCH 3/6] wip try to get tests running --- cli/app/list.go | 9 ++++++--- tests/integration/helpers/app.bash | 24 +++++++++++++----------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/cli/app/list.go b/cli/app/list.go index 39bc3325..d7389369 100644 --- a/cli/app/list.go +++ b/cli/app/list.go @@ -18,14 +18,16 @@ import ( var status bool var statusFlag = &cli.BoolFlag{ - Name: "status, S", + Name: "status", + Aliases: []string{"S"}, Usage: "Show app deployment status", Destination: &status, } var recipeFilter string var recipeFlag = &cli.StringFlag{ - Name: "recipe, r", + Name: "recipe", + Aliases: []string{"r"}, Value: "", Usage: "Show apps of a specific recipe", Destination: &recipeFilter, @@ -33,7 +35,8 @@ var recipeFlag = &cli.StringFlag{ var listAppServer string var listAppServerFlag = &cli.StringFlag{ - Name: "server, s", + Name: "server", + Aliases: []string{"s"}, Value: "", Usage: "Show apps of a specific server", Destination: &listAppServer, diff --git a/tests/integration/helpers/app.bash b/tests/integration/helpers/app.bash index ee3e30f6..a6c2420e 100644 --- a/tests/integration/helpers/app.bash +++ b/tests/integration/helpers/app.bash @@ -1,30 +1,31 @@ #!/usr/bin/env bash _new_app() { - run $ABRA app new "$TEST_RECIPE" \ + run $ABRA app new \ --no-input \ --server "$TEST_SERVER" \ --domain "$TEST_APP_DOMAIN" \ - --secrets + --secrets \ + "$TEST_RECIPE" assert_success assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" } _deploy_app() { - run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input + run $ABRA app deploy --no-input "$TEST_APP_DOMAIN" assert_success - run $ABRA app ls --server "$TEST_SERVER" --status + run $ABRA app --server "$TEST_SERVER" --status assert_success assert_output --partial "$TEST_APP_DOMAIN" assert_output --partial 'deployed' } _undeploy_app() { - run $ABRA app undeploy "$TEST_APP_DOMAIN" --no-input + run $ABRA app undeploy --no-input "$TEST_APP_DOMAIN" assert_success - run $ABRA app ls --server "$TEST_SERVER" --status + run $ABRA app ls --server "$TEST_SERVER" --status assert_success assert_output --partial "$TEST_APP_DOMAIN" assert_output --partial 'unknown' @@ -34,10 +35,10 @@ _rm_app() { # NOTE(d1): not asserting outcomes on teardown here since some might fail # depending on what the test created. all commands run through anyway if [[ -f "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" ]]; then - run $ABRA app undeploy "$TEST_APP_DOMAIN" --no-input - run $ABRA app secret remove "$TEST_APP_DOMAIN" --all --no-input - run $ABRA app volume remove "$TEST_APP_DOMAIN" --no-input - run $ABRA app remove "$TEST_APP_DOMAIN" --no-input + run $ABRA app undeploy --no-input "$TEST_APP_DOMAIN" + run $ABRA app secret remove --all --no-input "$TEST_APP_DOMAIN" + run $ABRA app volume remove --no-input "$TEST_APP_DOMAIN" + run $ABRA app remove --no-input "$TEST_APP_DOMAIN" fi } @@ -46,10 +47,11 @@ _reset_app(){ assert_success assert_not_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" - run $ABRA app new "$TEST_RECIPE" \ + run $ABRA app new \ --no-input \ --server "$TEST_SERVER" \ --domain "$TEST_APP_DOMAIN" \ + "$TEST_RECIPE" assert_success assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" } -- 2.45.2 From 8a7d17f37b25af65a0965e587408584fdd9a7de5 Mon Sep 17 00:00:00 2001 From: p4u1 Date: Fri, 23 Feb 2024 14:57:28 +0100 Subject: [PATCH 4/6] fix --- cli/app/cmd.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/app/cmd.go b/cli/app/cmd.go index a247ba05..0e0eca3b 100644 --- a/cli/app/cmd.go +++ b/cli/app/cmd.go @@ -187,8 +187,8 @@ func parseCmdArgs(args []string, isLocal bool) (bool, string) { ) if isLocal { - if len(args) > 2 { - return true, fmt.Sprintf("%s ", strings.Join(args[2:], " ")) + if len(args) > 3 { + return true, fmt.Sprintf("%s ", strings.Join(args[3:], " ")) } } else { if len(args) > 3 { -- 2.45.2 From 7d80f4d56b2213fb4e2247b58e30457e19b4a88f Mon Sep 17 00:00:00 2001 From: p4u1 Date: Mon, 11 Mar 2024 16:07:15 +0100 Subject: [PATCH 5/6] fix --- cli/app/backup.go | 10 +++++----- cli/app/cmd.go | 24 ++++++++---------------- cli/app/cmd_test.go | 2 +- cli/app/new.go | 2 +- tests/integration/helpers/app.bash | 4 ++-- 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/cli/app/backup.go b/cli/app/backup.go index 4baf23a9..16423728 100644 --- a/cli/app/backup.go +++ b/cli/app/backup.go @@ -287,10 +287,10 @@ var appBackupCommand = cli.Command{ Aliases: []string{"b"}, Usage: "Manage app backups", ArgsUsage: "", - Subcommands: []cli.Command{ - appBackupListCommand, - appBackupSnapshotsCommand, - appBackupDownloadCommand, - appBackupCreateCommand, + Subcommands: []*cli.Command{ + &appBackupListCommand, + &appBackupSnapshotsCommand, + &appBackupDownloadCommand, + &appBackupCreateCommand, }, } diff --git a/cli/app/cmd.go b/cli/app/cmd.go index 0e0eca3b..c0289396 100644 --- a/cli/app/cmd.go +++ b/cli/app/cmd.go @@ -84,7 +84,7 @@ Example: internal.ShowSubcommandHelpAndError(c, errors.New("cannot use --local & --user together")) } - hasCmdArgs, parsedCmdArgs := parseCmdArgs(c.Args().Slice(), internal.LocalCmd) + hasCmdArgs, parsedCmdArgs := parseCmdArgs(c.Args().Slice()) abraSh := path.Join(config.RECIPES_DIR, app.Recipe, "abra.sh") if _, err := os.Stat(abraSh); err != nil { @@ -180,23 +180,15 @@ Example: }, } -func parseCmdArgs(args []string, isLocal bool) (bool, string) { - var ( - parsedCmdArgs string - hasCmdArgs bool - ) - - if isLocal { - if len(args) > 3 { - return true, fmt.Sprintf("%s ", strings.Join(args[3:], " ")) - } - } else { - if len(args) > 3 { - return true, fmt.Sprintf("%s ", strings.Join(args[3:], " ")) - } +// Parse the command arguments from the cli args. +// Arguments should look like this: +// DOMAIN COMMAND -- ARGUMENT1 ARGUMENT2 ... +func parseCmdArgs(args []string) (bool, string) { + if len(args) < 4 { + return false, "" } - return hasCmdArgs, parsedCmdArgs + return true, fmt.Sprintf("%s ", strings.Join(args[3:], " ")) } func cmdNameComplete(appName string) { diff --git a/cli/app/cmd_test.go b/cli/app/cmd_test.go index ed3ac6f9..cfd975c5 100644 --- a/cli/app/cmd_test.go +++ b/cli/app/cmd_test.go @@ -20,7 +20,7 @@ func TestParseCmdArgs(t *testing.T) { } for _, test := range tests { - ok, parsed := parseCmdArgs(test.input, false) + ok, parsed := parseCmdArgs(test.input) if ok != test.shouldParse { t.Fatalf("[%s] should not parse", strings.Join(test.input, " ")) } diff --git a/cli/app/new.go b/cli/app/new.go index 00c6a3b6..2a6560b5 100644 --- a/cli/app/new.go +++ b/cli/app/new.go @@ -58,7 +58,7 @@ var appNewCommand = cli.Command{ ArgsUsage: "[] []", BashComplete: func(ctx *cli.Context) { args := ctx.Args() - switch len(args) { + switch args.Len() { case 0: autocomplete.RecipeNameComplete(ctx) case 1: diff --git a/tests/integration/helpers/app.bash b/tests/integration/helpers/app.bash index a6c2420e..bf1368a5 100644 --- a/tests/integration/helpers/app.bash +++ b/tests/integration/helpers/app.bash @@ -15,7 +15,7 @@ _deploy_app() { run $ABRA app deploy --no-input "$TEST_APP_DOMAIN" assert_success - run $ABRA app --server "$TEST_SERVER" --status + run $ABRA app ls --server "$TEST_SERVER" --status assert_success assert_output --partial "$TEST_APP_DOMAIN" assert_output --partial 'deployed' @@ -25,7 +25,7 @@ _undeploy_app() { run $ABRA app undeploy --no-input "$TEST_APP_DOMAIN" assert_success - run $ABRA app ls --server "$TEST_SERVER" --status + run $ABRA app ls --server "$TEST_SERVER" --status assert_success assert_output --partial "$TEST_APP_DOMAIN" assert_output --partial 'unknown' -- 2.45.2 From b81f5651d3ce8e584225eaf6ab26cd8973151b8d Mon Sep 17 00:00:00 2001 From: p4u1 Date: Mon, 11 Mar 2024 16:14:36 +0100 Subject: [PATCH 6/6] fmt --- cli/app/cmd.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/app/cmd.go b/cli/app/cmd.go index c0289396..28a13c9d 100644 --- a/cli/app/cmd.go +++ b/cli/app/cmd.go @@ -182,7 +182,8 @@ Example: // Parse the command arguments from the cli args. // Arguments should look like this: -// DOMAIN COMMAND -- ARGUMENT1 ARGUMENT2 ... +// +// DOMAIN COMMAND -- ARGUMENT1 ARGUMENT2 ... func parseCmdArgs(args []string) (bool, string) { if len(args) < 4 { return false, "" -- 2.45.2