Skip to content

Commit

Permalink
Allow pallets to define feature flags which other pallets can referen…
Browse files Browse the repository at this point in the history
…ce in file imports (#297)

* By default, make `[dev] plt ls-file` hide files in hidden dirs, e.g. `.git`

* By default, make `[dev] plt ls-plt-file` hide files in hidden root-level dirs

* Allow pallets to expose feature flags, and allow other pallets to reference them in file import groups

* Update `CHANGELOG.md` for previous commit

* Fix uninitialized set

* Allow singular form of string slice cli flags for repo/pallet overrides in `dev plt`

* Allow setting and showing deprecation notices for pallet features.

* Fix some error messages & code comments I had forgotten to rename after copy-pasting

* Add support for referencing features exposed by required pallets
  • Loading branch information
ethanjli authored Sep 19, 2024
1 parent 4357aeb commit 3c7fb69
Show file tree
Hide file tree
Showing 20 changed files with 731 additions and 91 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- (cli) Added support for `add-feature` and `remove-feature` types to file import group modifiers. `add-feature` will add all files determined by evaluation of a named feature flag exposed by the import group's referenced pallet, while `remove-feature` will remove those files. Pallet feature flags are constructed with the same file schema as file import groups, but are located in the pallet's `/features` directory and have a `.feature.yml` file extension instead.
- (cli) Added a `[dev] plt ls-feat` command to list feature flags exposed by the local/development pallet.
- (cli) Added a `[dev] plt show-feat` command to show the specified feature exposed by the local/development pallet, including any deprecation notices of deprecated features referenced directly or indirectly by this feature.
- (cli) Added a `[dev] plt ls-plt-feat` command to list feature flags exposed by the specified pallet required by the local/development pallet.
- (cli) Added a `[dev] plt show-plt-feat` command to show the specified feature exposed by the specified pallet required by the local/development pallet, including any deprecation notices of deprecated features referenced directly or indirectly by this feature.
- (cli) Added a `[dev] plt ls-plt-file` command to list files in the specified pallet required by the local/development pallet, including files imported by that required pallet from its own required pallets.
- (cli) Added a `[dev] plt locate-plt-file` command to print the actual filesystem path of the specified file in the specified pallet required by the local/development pallet.
- (cli) Added a `[dev] plt show-plt-file` command to print the contents of the specified file in the specified pallet required by the local/development pallet.
Expand All @@ -17,7 +22,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- (Breaking change; cli) Removed some aliases for `[dev] plt add-plt` and `[dev] plt add-repo` which should not have been added, because they were constructed as a combination of an abbrebiation and an unabbreviated word.
- (Breaking change; cli) Now, by default `[dev] plt ls-file` and `[dev] plt ls-plt-file` don't list files in hidden directories (i.e. directories whose names start with `.`) at the root of the pallet. To list all files including those in hidden directories, you should now specify `**` as the file path glob (e.g. by running `[dev] plt ls-file '**'` or `[dev] plt ls-plt-file required_pallet_path '**'`).
- (cli) Suppressed some noisy Git cloning output in `[dev] plt cache-plt`, `[dev] plt cache-all`, and other related commands.
- (cli) `[dev] plt show-imp` now shows any deprecated notices of deprecated features referenced directly or indirectly by the specified import group.

### Fixed

Expand Down
64 changes: 56 additions & 8 deletions cmd/forklift/dev/plt/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ func MakeCmd(versions Versions) *cli.Command {
"directory",
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "repos",
Aliases: []string{"repositories"},
Name: "repo",
Aliases: []string{"repos", "repository", "repositories"},
Usage: "Replaces version-locked required repos from the cache with the corresponding " +
"repos in the specified directory paths",
},
&cli.StringSliceFlag{
Name: "plts",
Aliases: []string{"pallets"},
Name: "plt",
Aliases: []string{"plts", "pallet", "pallets"},
Usage: "Replaces version-locked required pallets from the cache with the corresponding " +
"pallets in the specified directory paths",
},
Expand Down Expand Up @@ -153,6 +153,7 @@ func makeQuerySubcmds() []*cli.Command {
makeQueryFileSubcmds(category),
makeQueryPkgSubcmds(category),
makeQueryDeplSubcmds(category),
makeQueryFeatSubcmds(category),
[]*cli.Command{
{
Name: "ls-dl",
Expand Down Expand Up @@ -204,6 +205,7 @@ func makeQueryReqSubcmds(category string) []*cli.Command {
},
},
makeQueryPltFileSubcmds(category),
makeQueryPltFeatSubcmds(category),
[]*cli.Command{
{
Name: "ls-repo",
Expand Down Expand Up @@ -265,6 +267,29 @@ func makeQueryPltFileSubcmds(category string) []*cli.Command {
}
}

func makeQueryPltFeatSubcmds(category string) []*cli.Command {
return []*cli.Command{
{
Name: "ls-plt-feat",
Aliases: []string{"list-pallet-features"},
Category: category,
Usage: "Lists feature flags exposed by the specified pallet which the development pallet " +
"may import files from",
ArgsUsage: "pallet_path",
Action: lsPltFeatAction,
},
{
Name: "show-plt-feat",
Aliases: []string{"show-pallet-feature"},
Category: category,
Usage: "Prints the specified feature exposed by the specified pallet which the development " +
"pallet may import files from",
ArgsUsage: "pallet_path feature_name",
Action: showPltFeatAction,
},
}
}

func makeQueryImportSubcmds(category string) []*cli.Command {
return []*cli.Command{
{
Expand Down Expand Up @@ -376,6 +401,28 @@ func makeQueryDeplSubcmds(category string) []*cli.Command {
}
}

func makeQueryFeatSubcmds(category string) []*cli.Command {
return []*cli.Command{
{
Name: "ls-feat",
Aliases: []string{"list-features"},
Category: category,
Usage: "Lists the feature flags exposed by the development pallet for other pallets " +
"to import",
Action: lsFeatAction,
},
{
Name: "show-feat",
Aliases: []string{"show-feature"},
Category: category,
Usage: "Describes a feature exposed by the development pallet for other pallets " +
"to import",
ArgsUsage: "feature_name",
Action: showFeatAction,
},
}
}

func makeModifySubcmds(versions Versions) []*cli.Command {
return slices.Concat(
makeModifyFileSubcmds(),
Expand Down Expand Up @@ -542,8 +589,9 @@ func makeModifyDeplSubcmds( //nolint:funlen // this is already decomposed; it's
Flags: slices.Concat(
[]cli.Flag{
&cli.StringSliceFlag{
Name: "feature",
Usage: "Enable the specified feature flag in the package deployment",
Name: "feat",
Aliases: []string{"feature", "features"},
Usage: "Enable the specified feature in the package deployment",
},
&cli.BoolFlag{
Name: "disabled",
Expand Down Expand Up @@ -582,7 +630,7 @@ func makeModifyDeplSubcmds( //nolint:funlen // this is already decomposed; it's
&cli.BoolFlag{
Name: "force",
Usage: "Use the specified package path even if it cannot be resolved or makes the " +
"enabled feature flags invalid",
"enabled package features invalid",
},
},
baseFlags,
Expand All @@ -605,7 +653,7 @@ func makeModifyDeplSubcmds( //nolint:funlen // this is already decomposed; it's
[]cli.Flag{
&cli.BoolFlag{
Name: "force",
Usage: "Enable the specified feature flags even if they're not allowed by the " +
Usage: "Enable the specified package features even if they're not allowed by the " +
"deployment's package",
},
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/forklift/dev/plt/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func addDeplAction(versions Versions) cli.ActionFunc {
deplName := c.Args().Slice()[0]
pkgPath := c.Args().Slice()[1]
if err = fcli.AddDepl(
0, plt, caches.r, deplName, pkgPath, c.StringSlice("feature"), c.Bool("disabled"),
0, plt, caches.r, deplName, pkgPath, c.StringSlice("feat"), c.Bool("disabled"),
c.Bool("force"),
); err != nil {
return err
Expand Down
37 changes: 37 additions & 0 deletions cmd/forklift/dev/plt/features.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package plt

import (
"github.com/urfave/cli/v2"

fcli "github.com/PlanktoScope/forklift/internal/app/forklift/cli"
)

// ls-feat

func lsFeatAction(c *cli.Context) error {
plt, _, err := processFullBaseArgs(c, processingOptions{
requirePalletCache: true,
enableOverrides: true,
merge: true,
})
if err != nil {
return err
}

return fcli.PrintPalletFeatures(0, plt)
}

// show-feat

func showFeatAction(c *cli.Context) error {
plt, caches, err := processFullBaseArgs(c, processingOptions{
requirePalletCache: true,
enableOverrides: true,
merge: true,
})
if err != nil {
return err
}

return fcli.PrintFeatureInfo(0, plt, caches.p, c.Args().First())
}
7 changes: 6 additions & 1 deletion cmd/forklift/dev/plt/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ func lsFileAction(c *cli.Context) error {
return err
}

paths, err := fcli.ListPalletFiles(plt, c.Args().First())
filter := c.Args().First()
if filter == "" {
// Exclude hidden directories such as `.git`
filter = "{*,[^.]*/**}"
}
paths, err := fcli.ListPalletFiles(plt, filter)
if err != nil {
return err
}
Expand Down
45 changes: 42 additions & 3 deletions cmd/forklift/dev/plt/pallets.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func processFullBaseArgs(
}
if opts.enableOverrides {
if caches.p, err = overlayPalletCacheOverrides(
caches.p.Underlay, c.StringSlice("plts"), plt,
caches.p.Underlay, c.StringSlice("plt"), plt,
); err != nil {
return nil, workspaceCaches{}, err
}
Expand All @@ -67,7 +67,7 @@ func processFullBaseArgs(
}
if opts.enableOverrides {
if caches.r, err = overlayRepoCacheOverrides(
caches.r, c.StringSlice("repos"), plt,
caches.r, c.StringSlice("repo"), plt,
); err != nil {
return nil, workspaceCaches{}, err
}
Expand Down Expand Up @@ -530,7 +530,12 @@ func lsPltFileAction(c *cli.Context) error {
if err != nil {
return nil
}
paths, err := fcli.ListPalletFiles(plt, c.Args().Get(1))
filter := c.Args().Get(1)
if filter == "" {
// Exclude hidden directories such as `.git`
filter = "{*,[^.]*/**}"
}
paths, err := fcli.ListPalletFiles(plt, filter)
if err != nil {
return err
}
Expand Down Expand Up @@ -578,3 +583,37 @@ func showPltFileAction(c *cli.Context) error {
}
return fcli.PrintFile(plt, c.Args().Get(1))
}

// ls-plt-feat

func lsPltFeatAction(c *cli.Context) error {
plt, caches, err := processFullBaseArgs(c, processingOptions{
enableOverrides: true,
})
if err != nil {
return err
}

plt, err = fcli.GetRequiredPallet(plt, caches.p, c.Args().First())
if err != nil {
return nil
}
return fcli.PrintPalletFeatures(0, plt)
}

// show-plt-feat

func showPltFeatAction(c *cli.Context) error {
plt, caches, err := processFullBaseArgs(c, processingOptions{
enableOverrides: true,
})
if err != nil {
return err
}

plt, err = fcli.GetRequiredPallet(plt, caches.p, c.Args().First())
if err != nil {
return nil
}
return fcli.PrintFeatureInfo(0, plt, caches.p, c.Args().Get(1))
}
Loading

0 comments on commit 3c7fb69

Please sign in to comment.