diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a8b2b76..0362f11f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ 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 + +### Added + +- (cli) Added a `stage show-next-index` command to print the index of the next staged pallet bundle (if it exists). + ## 0.8.0-alpha.2 - 2024-09-22 ### Added diff --git a/cmd/forklift/stage/cli.go b/cmd/forklift/stage/cli.go index 3c209ec4..56676636 100644 --- a/cmd/forklift/stage/cli.go +++ b/cmd/forklift/stage/cli.go @@ -74,6 +74,12 @@ func makeQuerySubcmds(versions Versions) []*cli.Command { Usage: "Shows the history of successfully-applied staged pallet bundles", Action: showHistAction(versions), }, + { + Name: "show-next-index", + Category: category, + Usage: "Prints the index of next staged pallet bundle to be applied", + Action: showNextIndexAction(versions), + }, }, makeQueryBunSubcmds(versions)..., ) diff --git a/cmd/forklift/stage/store.go b/cmd/forklift/stage/store.go index ec14bc32..7ab7abdc 100644 --- a/cmd/forklift/stage/store.go +++ b/cmd/forklift/stage/store.go @@ -237,6 +237,27 @@ func showHistAction(versions Versions) cli.ActionFunc { } } +// show-next-index + +func showNextIndexAction(versions Versions) cli.ActionFunc { + return func(c *cli.Context) error { + store, err := getStageStore(c.String("workspace"), c.String("stage-store"), versions) + if err != nil { + return err + } + if !store.Exists() { + return errMissingStore + } + + next, ok := store.GetNext() + if !ok { + return errors.New("there is currently no staged pallet bundle to be applied next!") + } + fmt.Println(next) + return nil + } +} + // set-next func setNextAction(versions Versions) cli.ActionFunc { @@ -251,7 +272,10 @@ func setNextAction(versions Versions) cli.ActionFunc { if c.Args().First() == "0" { store.SetNext(0) - fmt.Println("Committing update to the stage store so that no stage will be applied next...") + fmt.Println( + "Committing update to the stage store so that no staged pallet bundle will be applied " + + "next...", + ) if err := store.CommitState(); err != nil { return errors.Wrap(err, "couldn't commit updated stage store state") }