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)