backupman 0.1.0 → 0.1.2

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 +17 -10
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  const fs = require("fs");
3
3
  const path = require("path");
4
4
  const readline = require("readline");
@@ -100,7 +100,7 @@ class BackupMan {
100
100
  formatSnapshot(snapshot) {
101
101
  const ts = snapshot.createdAt || "";
102
102
  const msg = snapshot.message || "";
103
- return `#${snapshot.id} [${ts}] ${msg}`;
103
+ return `[#${snapshot.id}] [${ts}] ${msg}`;
104
104
  }
105
105
 
106
106
  async chooseSnapshot(index) {
@@ -110,23 +110,27 @@ class BackupMan {
110
110
  }
111
111
 
112
112
  const list = [...index.snapshots].sort((a, b) => b.id - a.id);
113
+
113
114
  console.log("");
114
115
  console.log("Available snapshots (newest first):");
115
- list.forEach((s, i) => {
116
- console.log(` [${i + 1}] ${this.formatSnapshot(s)}`);
116
+ list.forEach(s => {
117
+ console.log(" " + this.formatSnapshot(s));
117
118
  });
118
119
  console.log("");
119
120
 
120
121
  while (true) {
121
- const answer = (await this.prompt("Select snapshot number to restore (empty = cancel): ")).trim();
122
+ const answer = (await this.prompt("Enter snapshot id to restore (e.g. 2, empty = cancel): ")).trim();
122
123
  if (!answer) {
123
124
  return null;
124
125
  }
125
126
  const n = Number.parseInt(answer, 10);
126
- if (!Number.isNaN(n) && n >= 1 && n <= list.length) {
127
- return list[n - 1];
127
+ if (!Number.isNaN(n)) {
128
+ const found = list.find(s => s.id === n);
129
+ if (found) {
130
+ return found;
131
+ }
128
132
  }
129
- console.log("Invalid choice. Please enter a valid number or press Enter to cancel.");
133
+ console.log("Invalid id. Please enter an existing snapshot id or press Enter to cancel.");
130
134
  }
131
135
  }
132
136
 
@@ -140,13 +144,16 @@ class BackupMan {
140
144
  }
141
145
 
142
146
  console.log("");
143
- console.log(`You chose snapshot: ${this.formatSnapshot(snapshot)}`);
144
- const confirm = (await this.prompt("Overwrite current files with this snapshot? (y/N): ")).trim().toLowerCase();
147
+ console.log(`You chose snapshot ${this.formatSnapshot(snapshot)}`);
148
+ const confirm = (await this.prompt("Create an auto-backup of current state and overwrite files? (y/N): ")).trim().toLowerCase();
145
149
  if (confirm !== "y" && confirm !== "yes") {
146
150
  console.log("Restore aborted.");
147
151
  return;
148
152
  }
149
153
 
154
+ console.log("Creating auto-backup of current state...");
155
+ await this.createSnapshot(`[auto] before restore from #${snapshot.id}`);
156
+
150
157
  console.log("Clearing current directory (except .backupman)...");
151
158
  await this.deleteEverythingExceptBackupDir();
152
159
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
- {
1
+ {
2
2
  "name": "backupman",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Ultra-simple local snapshot versioning tool for chaotic devs and mischievous AIs.",
5
5
  "bin": {
6
6
  "backupman": "index.js"
@@ -19,4 +19,4 @@
19
19
  "author": "",
20
20
  "license": "MIT",
21
21
  "dependencies": {}
22
- }
22
+ }