From a0e20833a5e4e38b09dd9661cf140a8385d02a86 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 18 Jan 2026 14:16:14 +0000 Subject: [PATCH] Restore --name flag for project selection in snapshots command Added the `--name` flag to the `snapshots` command to allow users to specify a project name explicitly, particularly useful when running in headless mode (directly from the store directory). This overrides or sets the project name for listing snapshots. Updated integration tests to verify this functionality. --- integration_test.go | 10 ++++++---- main.go | 13 +++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/integration_test.go b/integration_test.go index 0ba03c7..cd158dc 100644 --- a/integration_test.go +++ b/integration_test.go @@ -205,10 +205,12 @@ func TestIntegration(t *testing.T) { // Actually, `FindBackupRoot` supports "proj/timestamp". // But `snapshots` command calls `BackupRoots()` which lists `searchDir`. // If we want to list snapshots for a project headless: - // We can't currently without config. - // We might need to add back `--name` flag later? - // OR: `backup-cli` should maybe auto-discover projects? - // Let's stick to what we have: + // We use the --name flag. + out = run(storeDir, "--store", storeDir, "snapshots", "--name", projectName) + if !strings.Contains(out, snapshot1) { + t.Errorf("Snapshots with --name flag failed to list snapshot %s. Output: %s", snapshot1, out) + } + // Try `restore` with explicit project path "integration-test-proj/". targetRestore := filepath.Join(tempDir, "restore_from_store") diff --git a/main.go b/main.go index 5cfe17a..76761e6 100644 --- a/main.go +++ b/main.go @@ -121,8 +121,14 @@ func main() { Name: "snapshots", Aliases: []string{"snapshot", "list"}, Usage: "List backup snapshots", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "name", + Usage: "Project name (for headless mode)", + }, + }, Action: func(c *cli.Context) error { - return runSnapshots(b) + return runSnapshots(b, c.String("name")) }, }, { @@ -316,7 +322,10 @@ func main() { } } -func runSnapshots(b *internal.Backup) error { +func runSnapshots(b *internal.Backup, projectName string) error { + if projectName != "" { + b.ProjectName = projectName + } roots, err := b.BackupRoots() if err != nil { return fmt.Errorf("failed to list backups: %w", err)