backupman 0.2.3 → 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 +29 -33
  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,11 +103,9 @@ class BackupMan {
103
103
  return `#${snapshot.id} [${ts}] ${msg}`;
104
104
  }
105
105
 
106
- async listSnapshots() {
107
- await this.ensureDirs();
108
- const index = await this.loadIndex();
106
+ async chooseSnapshotById(index) {
109
107
  if (!index.snapshots.length) {
110
- console.log("No snapshots yet. Use `backupman save \"message\"` first.");
108
+ console.log("No snapshots yet. Run `backupman save \"message\"` first.");
111
109
  return null;
112
110
  }
113
111
 
@@ -118,44 +116,42 @@ class BackupMan {
118
116
  console.log(" " + this.formatSnapshot(s));
119
117
  });
120
118
  console.log("");
121
- return { index, list };
122
- }
123
119
 
124
- async restore() {
125
- const loaded = await this.listSnapshots();
126
- if (!loaded) return;
127
- const { index } = loaded;
120
+ while (true) {
121
+ const answer = (await this.prompt("Snapshot id to restore (empty = cancel): ")).trim();
122
+ if (!answer) return null;
128
123
 
129
- const answer = (await this.prompt("Type snapshot id to restore (empty = cancel): ")).trim();
130
- if (!answer) {
131
- console.log("Restore cancelled.");
132
- return;
133
- }
124
+ const n = Number.parseInt(answer, 10);
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
+ }
134
129
 
135
- const id = Number.parseInt(answer, 10);
136
- if (Number.isNaN(id)) {
137
- console.log("Invalid id. Restore aborted.");
138
- return;
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;
134
+ }
135
+
136
+ return target;
139
137
  }
138
+ }
140
139
 
141
- const snapshot = index.snapshots.find(s => s.id === id);
140
+ async restore() {
141
+ await this.ensureDirs();
142
+ const index = await this.loadIndex();
143
+ const snapshot = await this.chooseSnapshotById(index);
142
144
  if (!snapshot) {
143
- console.log("Snapshot not found. Restore aborted.");
145
+ console.log("Restore cancelled.");
144
146
  return;
145
147
  }
146
148
 
147
149
  console.log("");
148
- console.log(`You chose snapshot: ${this.formatSnapshot(snapshot)}`);
149
- const confirm = (await this.prompt("Restore this snapshot and overwrite current folder? (y/n): ")).trim().toLowerCase();
150
- if (confirm !== "y" && confirm !== "yes") {
151
- console.log("Restore aborted.");
152
- return;
153
- }
154
-
150
+ console.log("Restoring snapshot: " + this.formatSnapshot(snapshot));
155
151
  console.log("Clearing current directory (except .backupman)...");
156
152
  await this.deleteEverythingExceptBackupDir();
157
153
 
158
- console.log("Restoring snapshot files...");
154
+ console.log("Restoring files from snapshot...");
159
155
  const srcSnapshotDir = path.join(this.snapshotsDir, String(snapshot.id));
160
156
  await this.copyDir(srcSnapshotDir, this.rootDir);
161
157
 
@@ -167,8 +163,8 @@ function printUsage() {
167
163
  console.log("backupman - ultra-simple local snapshot tool");
168
164
  console.log("");
169
165
  console.log("Usage:");
170
- console.log(' backupman save "message" Save current directory as a snapshot');
171
- console.log(" backupman restore Restore from a snapshot");
166
+ console.log(' backupman save "message"');
167
+ console.log(" backupman restore");
172
168
  }
173
169
 
174
170
  async function main() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backupman",
3
- "version": "0.2.3",
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"