Skip to content

Commit

Permalink
Add CLI for modifying local pallets' package deployments (#205)
Browse files Browse the repository at this point in the history
* Bump `tools/` to go 1.22

* Resolve golancilint deprecation notice

* Add `[dev] plt rm-repo` subcommand

* Add a `[dev] plt add-depl` subcommand

* Add a `[dev] plt rm-depl` subcommand

* Add a `[dev] plt add-depl-feat` subcommand

* Add a `[dev] plt rm-depl-feat` subcommand

* Add a `[dev] plt set-depl-pkg` subcommand

* Add `[dev] plt set-depl-disabled` and `[dev] plt unset-depl-disabled` subcommands

* Add `--stage` and `--apply` flags to depl-modifying subcommands

* Bump goreleaser

* Bump version number in `CHANGELOG.md`

* Fix errors in `CHANGELOG.md`

* Add enable/disable aliases for `[dev] plt add-depl-feat` and `[dev] plt rm-depl-feat`
  • Loading branch information
ethanjli authored May 14, 2024
1 parent 5ae1401 commit 07e7443
Show file tree
Hide file tree
Showing 14 changed files with 1,427 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ linters:
- gocyclo
- godot
- gofumpt
- gomnd
- goprintffuncname
- gosec
- lll
- misspell
- mnd
- noctx
- nolintlint
- rowserrcheck
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

## 0.7.2-alpha.2 - 2024-05-13

## Added

- Added a `[dev] plt rm-repo` subcommand which removes requirements for the specified repo paths, as an inverse of the `[dev] plt add-repo` subcommand.
- Added a `[dev] plt add-depl` subcommand which adds a package deployment at the specified deployment name, for the specified package path (and optionally for the specified feature flags and enabled/disabled setting).
- Added a `[dev] plt rm-depl` subcommand which deletes the package deployment declaration(s) at the specified deployment name(s), as the inverse of the `[dev] plt add-depl` subcommand.
- Added a `[dev] plt set-depl-pkg` subcommand which modifies a package deployment at the specified deployment name, to change the deployment's package.
- Added a `[dev] plt add-depl-feat` (or `[dev] plt enable-depl-feat`) subcommand which modifies a package deployment at the specified deployment name, to enable the specified feature flags (for feature flags which are not already enabled).
- Added a `[dev] plt rm-depl-feat` (or `[dev] plt disable-depl-feat`) subcommand which modifies a package deployment at the specified deployment name, to disable the specified feature flags (for feature flags which are not already disabled), as the inverse of the `[dev] plt add-depl-feat` subcommand.
- Added a `[dev] plt set-depl-disabled` (or `[dev] plt disable-depl`) subcommand which modifies a package deployment at the specified deployment name, to disable the deployment.
- Added a `[dev] plt unset-depl` (or `[dev] plt enable-depl`) subcommand which modifies a package deployment at the specified deployment name, to enable the deployment.

## 0.7.2-alpha.1 - 2024-05-07

## Fixed
Expand Down
161 changes: 155 additions & 6 deletions cmd/forklift/dev/plt/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ func makeQueryDeplSubcmds(category string) []*cli.Command {
}

func makeModifySubcmds(versions Versions) []*cli.Command {
return slices.Concat(
makeModifyRepoSubcmds(versions),
makeModifyDeplSubcmds(versions),
)
}

func makeModifyRepoSubcmds(versions Versions) []*cli.Command {
const category = "Modify the pallet"
return []*cli.Command{
{
Expand All @@ -219,11 +226,153 @@ func makeModifySubcmds(versions Versions) []*cli.Command {
},
Action: addRepoAction(versions),
},
// TODO: add an rm-repo action with alias "drop-repo"; it should ensure no depls depend on it
// or delete those depls if `--force` is set
// TODO: add an add-depl --features=... depl_path package_path action
// TODO: add an rm-depl action
// TODO: add an add-depl-feat depl_path [feature]... action
// TODO: add an rm-depl-feat depl_path [feature]... action
{
Name: "rm-repo",
Aliases: []string{"remove-repositories", "drop-repo", "drop-repositories"},
Category: category,
Usage: "Removes repo requirements from the pallet",
ArgsUsage: "repo_path...",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "force",
Usage: "Remove specified repo requirements even if some declared package deployments " +
"depend on them",
},
},
Action: rmRepoAction(versions),
},
}
}

func makeModifyDeplSubcmds( //nolint:funlen // this is already decomposed; it's hard to split more
versions Versions,
) []*cli.Command {
const category = "Modify the pallet"
baseFlags := []cli.Flag{
&cli.BoolFlag{
Name: "stage",
Usage: "Immediately stage the pallet after making the modification (this flag is ignored " +
"if --apply is set)",
},
&cli.BoolFlag{
Name: "no-cache-img",
Usage: "Don't download container images (this flag is only used if --stage is set)",
},
&cli.BoolFlag{
Name: "apply",
Usage: "Immediately apply the pallet after staging it",
},
}
return []*cli.Command{
{
Name: "add-depl",
Aliases: []string{"add-deployment"},
Category: category,
Usage: "Adds (or re-adds) a package deployment to the pallet",
ArgsUsage: "deployment_name package_path...",
Flags: slices.Concat(
[]cli.Flag{
&cli.StringSliceFlag{
Name: "feature",
Usage: "Enable the specified feature flag in the package deployment",
},
&cli.BoolFlag{
Name: "disabled",
Usage: "Add a disabled package deployment",
},
&cli.BoolFlag{
Name: "force",
Usage: "Add specified deployment even if package_path cannot be resolved or the " +
"specified feature flags are not allowed for it",
},
},
baseFlags,
),
Action: addDeplAction(versions),
},
{
Name: "rm-depl",
Aliases: []string{"remove-deployment", "remove-deployments"},
Category: category,
Usage: "Removes deployment from the pallet",
ArgsUsage: "deployment_name...",
Flags: baseFlags,
Action: rmDeplAction(versions),
},
{
Name: "set-depl-pkg",
Aliases: []string{"set-deployment-package"},
Category: category,
Usage: "Sets the path of the package to deploy in the specified deployment",
ArgsUsage: "deployment_name package_path...",
Flags: slices.Concat(
[]cli.Flag{
&cli.BoolFlag{
Name: "force",
Usage: "Use the specified package path even if it cannot be resolved or makes the " +
"enabled feature flags invalid",
},
},
baseFlags,
),
Action: setDeplPkgAction(versions),
},
{
Name: "add-depl-feat",
Aliases: []string{
"add-deployment-feature",
"add-deployment-features",
"enable-depl-feat",
"enable-deployment-feature",
"enable-deployment-features",
},
Category: category,
Usage: "Enables the specified package features in the specified deployment",
ArgsUsage: "deployment_name feature_name...",
Flags: slices.Concat(
[]cli.Flag{
&cli.BoolFlag{
Name: "force",
Usage: "Enable the specified feature flags even if they're not allowed by the " +
"deployment's package",
},
},
baseFlags,
),
Action: addDeplFeatAction(versions),
},
{
Name: "rm-depl-feat",
Aliases: []string{
"remove-deployment-feature",
"remove-deployment-features",
"disable-depl-feat",
"disable-deployment-feature",
"disable-deployment-features",
},
Category: category,
Usage: "Disables the specified package features in the specified deployment",
ArgsUsage: "deployment_name feature_name...",
Flags: baseFlags,
Action: rmDeplFeatAction(versions),
},
{
Name: "set-depl-disabled",
Aliases: []string{"set-deployment-disabled", "disable-depl", "disable-deployment"},
Category: category,
Usage: "Disables the specified deployment",
ArgsUsage: "deployment_name",
Flags: baseFlags,
Action: setDeplDisabledAction(versions, true),
},
{
Name: "unset-depl-disabled",
Aliases: []string{"unset-deployment-disabled", "enable-depl", "enable-deployment"},
Category: category,
Usage: "Enables the specified deployment",
ArgsUsage: "deployment_name",
Flags: baseFlags,
Action: setDeplDisabledAction(versions, false),
},
}
}
Loading

0 comments on commit 07e7443

Please sign in to comment.