backupman 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +27 -27
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -24,7 +24,7 @@ class BackupMan {
24
24
  throw new Error("Corrupted index");
25
25
  }
26
26
  return parsed;
27
- } catch (err) {
27
+ } catch {
28
28
  return { lastId: 0, snapshots: [] };
29
29
  }
30
30
  }
@@ -64,7 +64,7 @@ class BackupMan {
64
64
  }
65
65
  }
66
66
 
67
- async prompt(question) {
67
+ prompt(question) {
68
68
  const rl = readline.createInterface({
69
69
  input: process.stdin,
70
70
  output: process.stdout
@@ -103,9 +103,9 @@ class BackupMan {
103
103
  return `#${snapshot.id} [${ts}] ${msg}`;
104
104
  }
105
105
 
106
- async chooseSnapshot(index) {
106
+ async chooseSnapshotById(index) {
107
107
  if (!index.snapshots.length) {
108
- console.log("No snapshots yet. Use `backupman save \"message\"` first.");
108
+ console.log("No snapshots yet. Run `backupman save \"message\"` first.");
109
109
  return null;
110
110
  }
111
111
 
@@ -118,52 +118,52 @@ class BackupMan {
118
118
  console.log("");
119
119
 
120
120
  while (true) {
121
- const answer = (await this.prompt("Type snapshot id to restore (empty = cancel): ")).trim();
122
- if (!answer) {
123
- return null;
124
- }
121
+ const answer = (await this.prompt("Snapshot id to restore (empty = cancel): ")).trim();
122
+ if (!answer) return null;
123
+
125
124
  const n = Number.parseInt(answer, 10);
126
- if (!Number.isNaN(n)) {
127
- const found = list.find(s => s.id === n);
128
- if (found) return found;
125
+ if (Number.isNaN(n)) {
126
+ console.log("Please enter a numeric id (e.g. 1, 2, 3) or press Enter to cancel.");
127
+ continue;
128
+ }
129
+
130
+ const target = index.snapshots.find(s => s.id === n);
131
+ if (!target) {
132
+ console.log("No snapshot with that id. Check the list above and try again.");
133
+ continue;
129
134
  }
130
- console.log("Invalid id. Please type an existing snapshot id or press Enter to cancel.");
135
+
136
+ return target;
131
137
  }
132
138
  }
133
139
 
134
140
  async restore() {
135
141
  await this.ensureDirs();
136
142
  const index = await this.loadIndex();
137
- const snapshot = await this.chooseSnapshot(index);
143
+ const snapshot = await this.chooseSnapshotById(index);
138
144
  if (!snapshot) {
139
145
  console.log("Restore cancelled.");
140
146
  return;
141
147
  }
142
148
 
143
149
  console.log("");
144
- console.log("You chose: " + this.formatSnapshot(snapshot));
145
- const confirm = (await this.prompt("Overwrite current files with this snapshot? [y/n]: ")).trim().toLowerCase();
146
- if (confirm !== "y" && confirm !== "yes") {
147
- console.log("Restore aborted.");
148
- return;
149
- }
150
-
151
- console.log("Clearing current directory...");
150
+ console.log("Restoring snapshot: " + this.formatSnapshot(snapshot));
151
+ console.log("Clearing current directory (except .backupman)...");
152
152
  await this.deleteEverythingExceptBackupDir();
153
153
 
154
- console.log("Restoring snapshot files...");
154
+ console.log("Restoring files from snapshot...");
155
155
  const srcSnapshotDir = path.join(this.snapshotsDir, String(snapshot.id));
156
156
  await this.copyDir(srcSnapshotDir, this.rootDir);
157
157
 
158
- console.log("Done. Restored snapshot #" + snapshot.id + ".");
158
+ console.log(`Done. Restored snapshot #${snapshot.id}.`);
159
159
  }
160
160
  }
161
161
 
162
162
  function printUsage() {
163
163
  console.log("backupman - ultra-simple local snapshot tool");
164
164
  console.log("");
165
- console.log("Commands:");
166
- console.log(" backupman save \"message\"");
165
+ console.log("Usage:");
166
+ console.log(' backupman save "message"');
167
167
  console.log(" backupman restore");
168
168
  }
169
169
 
@@ -187,7 +187,7 @@ async function main() {
187
187
  }
188
188
  }
189
189
  const id = await manager.createSnapshot(message.trim());
190
- console.log("Saved snapshot #" + id + ".");
190
+ console.log(`Saved snapshot #${id}.`);
191
191
  return;
192
192
  }
193
193
 
@@ -196,7 +196,7 @@ async function main() {
196
196
  return;
197
197
  }
198
198
 
199
- console.error("Unknown command: " + command);
199
+ console.error(`Unknown command: ${command}`);
200
200
  printUsage();
201
201
  process.exit(1);
202
202
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backupman",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Ultra-simple local snapshot versioning tool for chaotic devs and mischievous AIs.",
5
5
  "bin": {
6
6
  "backupman": "index.js"