Skip to content

Commit ecf7f19

Browse files
authored
Add --set-upgrade-query flag to plt clone/switch/upgrade (#399)
* Add `--set-upgrade-query` flag to `plt clone/switch/upgrade` * Update `CHANGELOG.md`
1 parent a7c457a commit ecf7f19

File tree

5 files changed

+65
-32
lines changed

5 files changed

+65
-32
lines changed

CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## Unrelease
8+
## 0.8.0-beta.0 - 2025-03-19
9+
10+
### Added
11+
12+
- (cli) Added a default-true `--set-upgrade-query` boolean flag to the `plt clone`, `plt switch`, and `plt upgrade` subcommands which can be set to false to prevent the `[pallet_path]@[version_query]` query from being saved into the file which tracks the last-used query.
913

1014
### Changed
1115

@@ -15,13 +19,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1519

1620
- (cli) In cases where trying to run `plt upgrade` without the `--force` flag (in order to upgrade from a commit which was only ancestral to the origin repo's references) incorrectly failed, now that operation should work.
1721

18-
## 0.8.0-alpha.7 - 2024-03-05
22+
## 0.8.0-alpha.7 - 2025-03-05
1923

2024
### Fixed
2125

2226
- (cli) Symlinks to nonexistent targets no longer fail to be merged in as part of file imports from pallets.
2327

24-
## 0.8.0-alpha.6 - 2024-01-27
28+
## 0.8.0-alpha.6 - 2025-01-27
2529

2630
### Added
2731

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ your hardware-specific embedded Linux operating systems.
2222
Note: this is still an experimental prototype in the sense that Forklift's architectural design and
2323
command-line interface may undergo significant backwards-incompatible simplifications. While
2424
Forklift is already used in production as a lower-level implementation detail of the
25-
[PlanktoScope OS](https://docs-edge.planktoscope.community/reference/software/architecture/os/)
25+
[PlanktoScope OS](https://docs.planktoscope.community/reference/software/architecture/os/)
2626
and is exposed to advanced users with a command-line interface for customization of PlanktoScope OS,
2727
any other use of Forklift is not yet officially documented or supported.
2828

@@ -45,7 +45,7 @@ specified, composed, deployed, and reversibly upgraded/downgraded as version-con
4545
software modules. The [PlanktoScope](https://www.planktoscope.org/), an open-source microscope for
4646
quantitative imaging of plankton, uses Forklift as low-level infrastructure for software
4747
releases, deployment, and extensibility in the
48-
[PlanktoScope OS](https://docs-edge.planktoscope.community/reference/software/architecture/os/), a
48+
[PlanktoScope OS](https://docs.planktoscope.community/reference/software/architecture/os/), a
4949
hardware-specific operating system based on the Raspberry Pi OS; and Forklift was designed
5050
specifically to solve the OS/software maintenance, customization, and operations challenges
5151
experienced in the PlanktoScope project.

cmd/forklift/plt/cli.go

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ func MakeCmd(versions Versions) *cli.Command {
3232
ArgsUsage: "[[pallet_path]@[version_query]]",
3333
Action: switchAction(versions),
3434
Flags: []cli.Flag{
35+
&cli.BoolFlag{
36+
Name: "set-upgrade-query",
37+
Usage: "Remember the pallet path and version query used in this operation for " +
38+
"future clone/switch/upgrade operations",
39+
Value: true,
40+
},
3541
&cli.BoolFlag{
3642
Name: "force",
3743
Usage: "Even if the local pallet already exists and has uncommitted/unpushed " +
@@ -67,26 +73,7 @@ func makeUpgradeSubcmds(versions Versions) []*cli.Command {
6773
"stages the pallet",
6874
ArgsUsage: "[[pallet_path]@[version_query]]",
6975
Action: upgradeAction(versions),
70-
Flags: []cli.Flag{
71-
&cli.BoolFlag{
72-
Name: "allow-downgrade",
73-
Usage: "Allow upgrading to an older version (i.e. performing a downgrade)",
74-
},
75-
&cli.BoolFlag{
76-
Name: "force",
77-
Usage: "Even if the local pallet has uncommitted/unpushed changes, replace it with the " +
78-
"upgraded version",
79-
},
80-
&cli.BoolFlag{
81-
Name: "cache-img",
82-
Usage: "Download container images (this flag is ignored if --apply is set)",
83-
Value: true,
84-
},
85-
&cli.BoolFlag{
86-
Name: "apply",
87-
Usage: "Immediately apply the upgraded pallet after staging it",
88-
},
89-
},
76+
Flags: upgradeFlags,
9077
},
9178
{
9279
Name: "check-upgrade",
@@ -120,6 +107,33 @@ func makeUpgradeSubcmds(versions Versions) []*cli.Command {
120107
}
121108
}
122109

110+
var upgradeFlags = []cli.Flag{
111+
&cli.BoolFlag{
112+
Name: "allow-downgrade",
113+
Usage: "Allow upgrading to an older version (i.e. performing a downgrade)",
114+
},
115+
&cli.BoolFlag{
116+
Name: "set-upgrade-query",
117+
Usage: "Remember the pallet path and version query used in this operation for future " +
118+
"clone/switch/upgrade operations",
119+
Value: true,
120+
},
121+
&cli.BoolFlag{
122+
Name: "force",
123+
Usage: "Even if the local pallet has uncommitted/unpushed changes, replace it with the " +
124+
"upgraded version",
125+
},
126+
&cli.BoolFlag{
127+
Name: "cache-img",
128+
Usage: "Download container images (this flag is ignored if --apply is set)",
129+
Value: true,
130+
},
131+
&cli.BoolFlag{
132+
Name: "apply",
133+
Usage: "Immediately apply the upgraded pallet after staging it",
134+
},
135+
}
136+
123137
func makeUseSubcmds(versions Versions) []*cli.Command {
124138
const category = "Use the pallet"
125139
return append(
@@ -545,6 +559,12 @@ func makeModifyGitSubcmds(versions Versions) []*cli.Command {
545559
ArgsUsage: "[[pallet_path]@[version_query]]",
546560
Flags: slices.Concat(
547561
[]cli.Flag{
562+
&cli.BoolFlag{
563+
Name: "set-upgrade-query",
564+
Usage: "Remember the pallet path and version query used in this operation for " +
565+
"future clone/switch/upgrade operations",
566+
Value: true,
567+
},
548568
&cli.BoolFlag{
549569
Name: "force",
550570
Usage: "If a local pallet already exists, delete it to replace it with the specified" +

cmd/forklift/plt/pallets.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func switchAction(versions Versions) cli.ActionFunc {
117117
return err
118118
}
119119

120-
query, err := handlePalletQuery(workspace, c.Args().First())
120+
query, err := handlePalletQuery(workspace, c.Args().First(), c.Bool("set-upgrade-query"))
121121
if err != nil {
122122
return errors.Wrapf(err, "couldn't handle provided version query %s", c.Args().First())
123123
}
@@ -168,7 +168,7 @@ func ensureWorkspace(wpath string) (*forklift.FSWorkspace, error) {
168168
}
169169

170170
func handlePalletQuery(
171-
workspace *forklift.FSWorkspace, providedQuery string,
171+
workspace *forklift.FSWorkspace, providedQuery string, commitPalletQuery bool,
172172
) (forklift.GitRepoQuery, error) {
173173
query, loaded, provided, err := completePalletQuery(workspace, providedQuery)
174174
if err != nil {
@@ -181,7 +181,8 @@ func handlePalletQuery(
181181
if !provided.Complete() {
182182
fmt.Fprintf(
183183
os.Stderr,
184-
"Provided query %s was completed with stored query %s as %s!\n", provided, loaded, query,
184+
"Provided query %s was completed (based on stored query %s) as %s!\n",
185+
provided, loaded, query,
185186
)
186187
printed = true
187188
}
@@ -192,6 +193,14 @@ func handlePalletQuery(
192193
return query, nil
193194
}
194195

196+
if !commitPalletQuery {
197+
fmt.Fprintf(
198+
os.Stderr,
199+
"Using (but not saving) the path & version query: %s\n", query,
200+
)
201+
return query, nil
202+
}
203+
195204
if loaded == (forklift.GitRepoQuery{}) {
196205
fmt.Fprintf(
197206
os.Stderr,
@@ -427,7 +436,7 @@ func upgradeAction(versions Versions) cli.ActionFunc {
427436
return err
428437
}
429438

430-
query, err := handlePalletQuery(workspace, c.Args().First())
439+
query, err := handlePalletQuery(workspace, c.Args().First(), c.Bool("set-upgrade-query"))
431440
if err != nil {
432441
return errors.Wrapf(err, "couldn't handle provided version query %s", c.Args().First())
433442
}
@@ -656,7 +665,7 @@ func setUpgradeQueryAction(c *cli.Context) error {
656665
return err
657666
}
658667

659-
_, err = handlePalletQuery(workspace, c.Args().First())
668+
_, err = handlePalletQuery(workspace, c.Args().First(), true)
660669
if err != nil {
661670
return errors.Wrapf(err, "couldn't handle provided version query %s", c.Args().First())
662671
}
@@ -673,7 +682,7 @@ func cloneAction(versions Versions) cli.ActionFunc {
673682
return err
674683
}
675684

676-
query, err := handlePalletQuery(workspace, c.Args().First())
685+
query, err := handlePalletQuery(workspace, c.Args().First(), c.Bool("set-upgrade-query"))
677686
if err != nil {
678687
return errors.Wrapf(err, "couldn't handle provided version query %s", c.Args().First())
679688
}

internal/app/forklift/workspace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func (w *FSWorkspace) GetCurrentPalletUpgrades() (GitRepoQuery, error) {
224224
return loadGitRepoQuery(fsys, configCurrentPalletUpgradesFile)
225225
}
226226

227-
// CommitCurrentPalletUpgrades atomoically updates the current pallet upgrades file.
227+
// CommitCurrentPalletUpgrades atomically updates the current pallet upgrades file.
228228
// Warning: on non-Unix platforms, the update is not entirely atomic!
229229
func (w *FSWorkspace) CommitCurrentPalletUpgrades(query GitRepoQuery) error {
230230
// TODO: we might want to be less sloppy about read locks vs. write locks in the future. After

0 commit comments

Comments
 (0)