Skip to content

Commit

Permalink
Add plt switch subcommand (#127)
Browse files Browse the repository at this point in the history
* Add `plt switch` subcommand

* Bump version in changelog
  • Loading branch information
ethanjli authored Feb 7, 2024
1 parent 1932bbf commit d6fb49d
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### 0.5.1 - 2024-02-07

- (cli) Added a `plt switch` subcommand which is the equivalent of running `plt clone --force` and then running `plt cache-repo` and then running `plt apply`. This allows a common task (switching the version of a pallet and applying it immediately) to be run with a single command, for a simpler user experience.

## 0.5.0 - 2024-01-14

### Added
Expand Down
17 changes: 15 additions & 2 deletions cmd/forklift/plt/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@ import (
)

func MakeCmd(toolVersion, repoMinVersion, palletMinVersion string) *cli.Command {
var subcommands []*cli.Command
subcommands := []*cli.Command{
{
Name: "switch",
Usage: "(Re)initializes the local pallet, updates the cache, and deploys the pallet",
ArgsUsage: "[github_repository_path@release]",
Action: switchAction(toolVersion, repoMinVersion, palletMinVersion),
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "parallel",
Usage: "parallelize updating of deployments",
},
},
},
}
for _, group := range makeSubcommandGroups(toolVersion, repoMinVersion, palletMinVersion) {
subcommands = append(subcommands, group...)
}
Expand Down Expand Up @@ -80,7 +93,7 @@ func makeUseSubcmds(toolVersion, repoMinVersion, palletMinVersion string) []*cli
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "parallel",
Usage: "parallelize downloading of images",
Usage: "parallelize updating of deployments",
},
},
},
Expand Down
63 changes: 59 additions & 4 deletions cmd/forklift/plt/pallets.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,59 @@ func getPallet(wpath string) (pallet *forklift.FSPallet, err error) {
return pallet, nil
}

// switch

func switchAction(toolVersion, repoMinVersion, palletMinVersion string) cli.ActionFunc {
return func(c *cli.Context) error {
wpath := c.String("workspace")
if !forklift.Exists(wpath) {
fmt.Printf("Making a new workspace at %s...", wpath)
}
if err := forklift.EnsureExists(wpath); err != nil {
return errors.Wrapf(err, "couldn't make new workspace at %s", wpath)
}

// clone pallet
remoteRelease := c.Args().First()
remote, release, err := git.ParseRemoteRelease(remoteRelease)
if err != nil {
return errors.Wrapf(err, "couldn't parse remote release %s", remoteRelease)
}
if err = clonePallet(remote, release, wpath, true); err != nil {
return errors.Wrapf(err, "couldn't clone %s@%s into %s", remote, release, wpath)
}
fmt.Println()
// TODO: warn if the git repo doesn't appear to be an actual pallet, or if the pallet's forklift
// version is incompatible

// cache repos required by pallet
pallet, cache, err := processFullBaseArgs(c, false)
if err != nil {
return err
}
if err = fcli.CheckShallowCompatibility(
pallet, cache, toolVersion, repoMinVersion, palletMinVersion, c.Bool("ignore-tool-version"),
); err != nil {
return err
}
fmt.Println("Downloading repos specified by the local pallet...")
if _, err = fcli.DownloadRepos(0, pallet, cache); err != nil {
return err
}
fmt.Println()

// apply pallet
if err = fcli.ApplyPallet(0, pallet, cache, c.Bool("parallel")); err != nil {
return errors.Wrap(
err, "couldn't deploy local pallet (have you run `forklift plt cache` recently?)",
)
}
fmt.Println()
fmt.Println("Done!")
return nil
}
}

// clone

func cloneAction(c *cli.Context) error {
Expand Down Expand Up @@ -100,9 +153,11 @@ func clonePallet(remote, release, wpath string, force bool) error {
if perr != nil {
return err
}
// TODO: we should instead clone each pallet into a pallet cache to avoid the need to overwrite
// the local pallet
fmt.Println(
"Removing local pallet from workspace, because it already exists and the " +
"command's --force flag was enabled...",
"Removing local pallet from workspace, because it already exists and we're " +
"overwriting the local pallet with the pallet to be cloned...",
)
if err = pallet.Remove(); err != nil {
return errors.Wrap(err, "couldn't remove local pallet")
Expand All @@ -114,9 +169,9 @@ func clonePallet(remote, release, wpath string, force bool) error {
)
}
}
fmt.Printf("Checking out release %s...\n", release)
fmt.Printf("Checking out version query %s...\n", release)
if err = gitRepo.Checkout(release, "origin"); err != nil {
return errors.Wrapf(err, "couldn't check out release %s at %s", release, local)
return errors.Wrapf(err, "couldn't check out version query %s at %s", release, local)
}
return nil
}
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/blang/semver/v4 v4.0.0
github.com/bmatcuk/doublestar/v4 v4.6.1
github.com/carlmjohnson/versioninfo v0.22.5
github.com/compose-spec/compose-go/v2 v2.0.0-rc.3
github.com/compose-spec/compose-go/v2 v2.0.0-rc.4
github.com/distribution/reference v0.5.0
github.com/docker/cli v25.0.2+incompatible
github.com/docker/compose/v2 v2.24.5
Expand Down Expand Up @@ -172,15 +172,15 @@ require (
go.opentelemetry.io/otel/trace v1.20.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/mock v0.4.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/oauth2 v0.11.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.13.0 // indirect
golang.org/x/tools v0.17.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
Expand Down
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+g
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE=
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4=
github.com/compose-spec/compose-go/v2 v2.0.0-rc.3 h1:t0qajSNkH3zR4HEN2CM+GVU7GBx5AwqiYJk5w800M7w=
github.com/compose-spec/compose-go/v2 v2.0.0-rc.3/go.mod h1:r7CJHU0GaLtRVLm2ch8RCNkJh3GHyaqqc2rSti7VP44=
github.com/compose-spec/compose-go/v2 v2.0.0-rc.4 h1:vVDWv1xm7Lqi7sEevU0Jk+T2huxNzf92lFhqKbn3sT8=
github.com/compose-spec/compose-go/v2 v2.0.0-rc.4/go.mod h1:IbZsys5a7eFTsdcWvM3brnghkK7ctZwUSr7mCj5NXu0=
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw=
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
Expand Down Expand Up @@ -586,11 +586,11 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 h1:MGwJjxBy0HJshjDNfLsYO8xppfqWlA5ZT9OhtUUhTNw=
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 h1:hNQpMuAJe5CtcUqCXaWga3FHu+kQvCqcsoVaQgSV60o=
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
Expand Down Expand Up @@ -618,8 +618,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.11.0 h1:vPL4xzxBM4niKCW6g9whtaWVXTJf1U5e4aZxxFx/gbU=
golang.org/x/oauth2 v0.11.0/go.mod h1:LdF7O/8bLR/qWK9DrpXmbHLTouvRHK0SgJl0GmDBchk=
Expand Down Expand Up @@ -669,8 +669,8 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand All @@ -693,8 +693,8 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down

0 comments on commit d6fb49d

Please sign in to comment.