cli-macro 1.1.2 → 1.1.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.
- package/index.js +16 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -36,6 +36,7 @@ if (command === "new" || command === "n") {
|
|
|
36
36
|
console.error("Filename required for new command.");
|
|
37
37
|
process.exit(1);
|
|
38
38
|
}
|
|
39
|
+
console.log("\n");
|
|
39
40
|
const lines = [];
|
|
40
41
|
while (true) {
|
|
41
42
|
const index = lines.length + 1;
|
|
@@ -83,28 +84,34 @@ if (command === "new" || command === "n") {
|
|
|
83
84
|
const lines = fs.existsSync(filepath)
|
|
84
85
|
? fs.readFileSync(filepath, "utf-8").split(/\r?\n/)
|
|
85
86
|
: [];
|
|
87
|
+
const original = lines.slice();
|
|
88
|
+
let modified = false;
|
|
86
89
|
|
|
87
90
|
while (true) {
|
|
88
|
-
console.log(
|
|
91
|
+
console.log("\n");
|
|
89
92
|
if (lines.length === 0) {
|
|
90
93
|
console.log("(empty file)");
|
|
91
94
|
} else {
|
|
92
95
|
lines.forEach((line, index) => {
|
|
93
|
-
|
|
96
|
+
const padding = " ".repeat(6 - String(index + 1).length);
|
|
97
|
+
console.log(`${padding}${index + 1}| ${line}`);
|
|
94
98
|
});
|
|
95
99
|
}
|
|
96
100
|
|
|
101
|
+
console.log("\n");
|
|
97
102
|
const action = prompt("[a]ppend [r]eplace [d]elete [s]ave [q]uit > ").trim().toLowerCase();
|
|
98
103
|
if (action === "a") {
|
|
99
104
|
const newLine = prompt("Append line: ");
|
|
100
105
|
if (newLine !== "") {
|
|
101
106
|
lines.push(newLine);
|
|
107
|
+
modified = true;
|
|
102
108
|
}
|
|
103
109
|
} else if (action === "r") {
|
|
104
110
|
const lineNumber = Number(prompt("Replace line number: "));
|
|
105
111
|
if (Number.isInteger(lineNumber) && lineNumber >= 1 && lineNumber <= lines.length) {
|
|
106
112
|
const newText = prompt("New text: ");
|
|
107
113
|
lines[lineNumber - 1] = newText;
|
|
114
|
+
modified = true;
|
|
108
115
|
} else {
|
|
109
116
|
console.log("Please enter a valid line number.");
|
|
110
117
|
}
|
|
@@ -112,15 +119,20 @@ if (command === "new" || command === "n") {
|
|
|
112
119
|
const lineNumber = Number(prompt("Delete line number: "));
|
|
113
120
|
if (Number.isInteger(lineNumber) && lineNumber >= 1 && lineNumber <= lines.length) {
|
|
114
121
|
lines.splice(lineNumber - 1, 1);
|
|
122
|
+
modified = true;
|
|
115
123
|
} else {
|
|
116
124
|
console.log("Please enter a valid line number.");
|
|
117
125
|
}
|
|
118
126
|
} else if (action === "s") {
|
|
119
127
|
fs.writeFileSync(filepath, lines.join("\n"));
|
|
120
128
|
console.log(`${path.basename(filepath)} was saved`);
|
|
129
|
+
modified = false;
|
|
121
130
|
break;
|
|
122
131
|
} else if (action === "q") {
|
|
123
|
-
|
|
132
|
+
// 무조건 저장하고 종료
|
|
133
|
+
fs.writeFileSync(filepath, lines.join("\n"));
|
|
134
|
+
console.log(`${path.basename(filepath)} was saved`);
|
|
135
|
+
modified = false;
|
|
124
136
|
break;
|
|
125
137
|
} else {
|
|
126
138
|
console.log("Unknown command. Try again.");
|
|
@@ -139,7 +151,7 @@ if (command === "new" || command === "n") {
|
|
|
139
151
|
}
|
|
140
152
|
fs.unlinkSync(filepath);
|
|
141
153
|
console.log(`${path.basename(filepath)} was deleted`);
|
|
142
|
-
} else if (command === "list" || command === "
|
|
154
|
+
} else if (command === "list" || command === "l") {
|
|
143
155
|
// 파일 목록 보기 기능 (.clim 파일만)
|
|
144
156
|
const files = fs.readdirSync(dataDir).filter(file => {
|
|
145
157
|
const fullPath = path.join(dataDir, file);
|