backupman 0.2.3 → 0.3.1

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 +30 -22
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -107,7 +107,7 @@ class BackupMan {
107
107
  await this.ensureDirs();
108
108
  const index = await this.loadIndex();
109
109
  if (!index.snapshots.length) {
110
- console.log("No snapshots yet. Use `backupman save \"message\"` first.");
110
+ console.log('No snapshots yet. Run: backupman save "message"');
111
111
  return null;
112
112
  }
113
113
 
@@ -121,37 +121,45 @@ class BackupMan {
121
121
  return { index, list };
122
122
  }
123
123
 
124
- async restore() {
125
- const loaded = await this.listSnapshots();
126
- if (!loaded) return;
127
- const { index } = loaded;
128
-
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
- }
134
-
135
- const id = Number.parseInt(answer, 10);
136
- if (Number.isNaN(id)) {
137
- console.log("Invalid id. Restore aborted.");
138
- return;
124
+ async chooseSnapshot() {
125
+ const data = await this.listSnapshots();
126
+ if (!data) return null;
127
+ const { index } = data;
128
+
129
+ while (true) {
130
+ const answer = (await this.prompt("Type snapshot id to restore (empty = cancel): ")).trim();
131
+ if (!answer) return null;
132
+ const id = Number.parseInt(answer, 10);
133
+ if (Number.isNaN(id)) {
134
+ console.log("Please enter a valid number.");
135
+ continue;
136
+ }
137
+ const picked = index.snapshots.find(s => s.id === id);
138
+ if (!picked) {
139
+ console.log("No snapshot with that id. Try again.");
140
+ continue;
141
+ }
142
+ return picked;
139
143
  }
144
+ }
140
145
 
141
- const snapshot = index.snapshots.find(s => s.id === id);
146
+ async restore() {
147
+ const snapshot = await this.chooseSnapshot();
142
148
  if (!snapshot) {
143
- console.log("Snapshot not found. Restore aborted.");
149
+ console.log("Restore cancelled.");
144
150
  return;
145
151
  }
146
152
 
147
153
  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();
154
+ console.log("You chose snapshot: " + this.formatSnapshot(snapshot));
155
+ const confirm = (await this.prompt("Restore this snapshot and overwrite current files? (y/n): ")).trim().toLowerCase();
150
156
  if (confirm !== "y" && confirm !== "yes") {
151
157
  console.log("Restore aborted.");
152
158
  return;
153
159
  }
154
160
 
161
+ await this.ensureDirs();
162
+
155
163
  console.log("Clearing current directory (except .backupman)...");
156
164
  await this.deleteEverythingExceptBackupDir();
157
165
 
@@ -167,8 +175,8 @@ function printUsage() {
167
175
  console.log("backupman - ultra-simple local snapshot tool");
168
176
  console.log("");
169
177
  console.log("Usage:");
170
- console.log(' backupman save "message" Save current directory as a snapshot');
171
- console.log(" backupman restore Restore from a snapshot");
178
+ console.log(' backupman save "message" Save current directory as a snapshot');
179
+ console.log(" backupman restore Restore from a snapshot");
172
180
  }
173
181
 
174
182
  async function main() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "backupman",
3
- "version": "0.2.3",
4
- "description": "Ultra-simple local snapshot versioning tool for chaotic devs and mischievous AIs.",
3
+ "version": "0.3.1",
4
+ "description": "Ultra-simple local snapshot tool for when your code (or your AI) goes off the rails.",
5
5
  "bin": {
6
6
  "backupman": "index.js"
7
7
  },