backupman 0.1.0 → 0.1.3

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