From 17e5b6c861b8bd31d8bef8b28cae7951c046d374 Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Tue, 10 Nov 2026 21:34:41 -0700 Subject: [PATCH] Back up each name given to the interactive backup command Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + COMMANDS.md | 2 +- USER_GUIDE.md | 2 +- .../backup/BackupCommandLineRunner.java | 14 +++++---- .../backup/BackupCommandLineRunnerTest.java | 29 ++++++++++++++++++- 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2752cba..f2f9bdb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed +- The interactive `backup` command now backs up each name it is given, so `backup octocat github` backs up `octocat` and then `github`, as the command line does, instead of looking up the single name `octocat github` on GitHub and failing. A name that fails is reported and the others are still backed up; the command still counts as one backup run for usage reporting, and its usage hint reads `Usage: backup [user/org2] ...` - A scheduled daemon backup no longer stops partway when one user or organization fails with an unchecked exception (such as a `GHException` from github-api while listing repositories): the failure is logged as an error like any other, the remaining users and organizations are still backed up, and the run is still logged and reported as completed. Previously only an `IOException` was handled, so the rest of that run was skipped until the next interval - A backup that reaches the GitHub rate limit no longer looks hung: the GitHub client has always waited silently for the limit to reset, for up to an hour, and now a notice on standard error says so first, with the expected reset time, and suggests `GITHUB_TOKEN` when running anonymously. The waiting itself is unchanged and is documented in `USER_GUIDE.md` and `COMMANDS.md` - `GITHUB_TOKEN` is no longer dropped when the startup check fails for a reason unrelated to the token: only a `401` now prints `Invalid or expired GITHUB_TOKEN` and falls back to anonymous access, while any other failure, such as a network failure, a GitHub error or a `403` from `GET /user`, prints `Could not verify GITHUB_TOKEN` and keeps the token, so a brief outage at startup no longer leaves a daemon limited to 60 requests per hour until it is restarted diff --git a/COMMANDS.md b/COMMANDS.md index ffdae74..fcf5582 100644 --- a/COMMANDS.md +++ b/COMMANDS.md @@ -48,7 +48,7 @@ Once in interactive mode, the following commands are available at the `>` prompt | Command | Description | |---------|-------------| -| `backup ` | Back up all public repositories for the given GitHub user or organization | +| `backup [user/org2] ...` | Back up all public repositories for each GitHub user or organization given, one after another. Names are separated by spaces or tabs; one that fails is reported and the rest are still backed up | | `status` | Display the backup directory path and a summary of all backed-up repositories | | `help` | Show the list of available interactive commands | | `exit` | Exit interactive mode and terminate the application | diff --git a/USER_GUIDE.md b/USER_GUIDE.md index 57ea1ad..7c83544 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -109,7 +109,7 @@ Available interactive commands: | Command | Description | |---------|-------------| -| `backup ` | Back up all public repositories for the specified user or organization | +| `backup [user/org2] ...` | Back up all public repositories for each specified user or organization, as on the command line (for example, `backup octocat github`) | | `status` | Show the backup directory, number of users/organizations, and a list of all backed up repositories | | `help` | Show the list of available interactive commands | | `exit` | Quit the interactive session | diff --git a/src/main/java/com/github/backup/BackupCommandLineRunner.java b/src/main/java/com/github/backup/BackupCommandLineRunner.java index ff5956f..55c9a78 100644 --- a/src/main/java/com/github/backup/BackupCommandLineRunner.java +++ b/src/main/java/com/github/backup/BackupCommandLineRunner.java @@ -139,13 +139,15 @@ private void runInteractiveMode() { case "backup": if (parts.length < 2) { System.out.println("Error: Please specify a user or organization"); - System.out.println("Usage: backup "); + System.out.println("Usage: backup [user/org2] ..."); } else { - String userOrOrg = parts[1].trim(); - try { - backupService.backupUserRepositories(userOrOrg); - } catch (Exception e) { - System.err.println("Error backing up " + userOrOrg + ": " + e.getMessage()); + // Several names are backed up one after another, as on the command line + for (String userOrOrg : parts[1].trim().split("\\s+")) { + try { + backupService.backupUserRepositories(userOrOrg); + } catch (Exception e) { + System.err.println("Error backing up " + userOrOrg + ": " + e.getMessage()); + } } usageReporting.backupCompleted(); } diff --git a/src/test/java/com/github/backup/BackupCommandLineRunnerTest.java b/src/test/java/com/github/backup/BackupCommandLineRunnerTest.java index 542c453..6a43a5d 100644 --- a/src/test/java/com/github/backup/BackupCommandLineRunnerTest.java +++ b/src/test/java/com/github/backup/BackupCommandLineRunnerTest.java @@ -321,6 +321,33 @@ void testRun_InteractiveMode_BackupArgumentIsTrimmed() throws Exception { verify(backupService).backupUserRepositories("octocat"); } + @Test + void testRun_InteractiveMode_BackupSeveralNames_EachBackedUpSeparately() throws Exception { + provideInput("backup octocat github\texit-user\nexit\n"); + + runner.run("-i"); + + verify(backupService).backupUserRepositories("octocat"); + verify(backupService).backupUserRepositories("github"); + verify(backupService).backupUserRepositories("exit-user"); + verify(backupService, never()).backupUserRepositories("octocat github\texit-user"); + // One command is one backup run, however many names it lists + verify(usageReporting, times(1)).backupCompleted(); + } + + @Test + void testRun_InteractiveMode_BackupSeveralNames_FailureDoesNotStopTheOthers() throws Exception { + doThrow(new IOException("Test exception")) + .when(backupService).backupUserRepositories("erroruser"); + provideInput("backup erroruser gooduser\nexit\n"); + + runner.run("-i"); + + assertTrue(stderr().contains("Error backing up erroruser: Test exception")); + verify(backupService).backupUserRepositories("gooduser"); + verify(usageReporting, times(1)).backupCompleted(); + } + @Test void testRun_InteractiveMode_BackupWithoutTarget() throws Exception { provideInput("backup\nexit\n"); @@ -328,7 +355,7 @@ void testRun_InteractiveMode_BackupWithoutTarget() throws Exception { runner.run("-i"); assertTrue(stdout().contains("Error: Please specify a user or organization")); - assertTrue(stdout().contains("Usage: backup ")); + assertTrue(stdout().contains("Usage: backup [user/org2] ...")); verifyNoInteractions(backupService, usageReporting); }