@indah_sekar/os-t 1.0.2 → 1.0.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/bin/cli.js +26 -16
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -57,7 +57,7 @@ function listCommands(osFilter, categoryFilter, searchQuery) {
|
|
|
57
57
|
continue;
|
|
58
58
|
}
|
|
59
59
|
const categories = commands[os];
|
|
60
|
-
let
|
|
60
|
+
let allCmds = [];
|
|
61
61
|
for (const cat of categories) {
|
|
62
62
|
if (
|
|
63
63
|
categoryFilter &&
|
|
@@ -75,19 +75,15 @@ function listCommands(osFilter, categoryFilter, searchQuery) {
|
|
|
75
75
|
c.command.toLowerCase().includes(q),
|
|
76
76
|
);
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
for (const cmd of cmds) {
|
|
88
|
-
console.log(` ${cmd.name.padEnd(maxNameLen)} ${cmd.description}`);
|
|
89
|
-
total++;
|
|
90
|
-
}
|
|
78
|
+
allCmds.push(...cmds);
|
|
79
|
+
}
|
|
80
|
+
if (allCmds.length === 0) continue;
|
|
81
|
+
const maxNameLen = Math.max(...allCmds.map((c) => c.name.length), 4);
|
|
82
|
+
console.log(`\n ${os}`);
|
|
83
|
+
console.log(` ${"name".padEnd(maxNameLen)} description`);
|
|
84
|
+
for (const cmd of allCmds) {
|
|
85
|
+
console.log(` ${cmd.name.padEnd(maxNameLen)} ${cmd.description}`);
|
|
86
|
+
total++;
|
|
91
87
|
}
|
|
92
88
|
}
|
|
93
89
|
console.log(`\n Total: ${total} command(s)`);
|
|
@@ -158,6 +154,16 @@ function printResults(results) {
|
|
|
158
154
|
console.log(`\n Found: ${results.length} command(s)`);
|
|
159
155
|
}
|
|
160
156
|
|
|
157
|
+
function executeCommand(cmd, os) {
|
|
158
|
+
const finalCmd = prepareCommand(cmd, os);
|
|
159
|
+
console.log(`\n Executing: $ ${finalCmd}\n`);
|
|
160
|
+
try {
|
|
161
|
+
execSync(finalCmd, { stdio: "inherit", shell: true });
|
|
162
|
+
} catch {
|
|
163
|
+
// execSync throws on non-zero exit, already printed by inherit
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
161
167
|
function main() {
|
|
162
168
|
if (args.includes("--help") || args.includes("-h") || args.length === 0) {
|
|
163
169
|
printHelp();
|
|
@@ -222,7 +228,9 @@ function main() {
|
|
|
222
228
|
return;
|
|
223
229
|
}
|
|
224
230
|
printResults(filtered);
|
|
225
|
-
if (
|
|
231
|
+
if (filtered.length === 1) {
|
|
232
|
+
executeCommand(filtered[0].command, filtered[0].os);
|
|
233
|
+
} else if (shouldCopy) {
|
|
226
234
|
const cmdToSend = prepareCommand(filtered[0].command, filtered[0].os);
|
|
227
235
|
const copied = copyToClipboard(cmdToSend);
|
|
228
236
|
if (copied) {
|
|
@@ -235,7 +243,9 @@ function main() {
|
|
|
235
243
|
}
|
|
236
244
|
} else {
|
|
237
245
|
printResults(results);
|
|
238
|
-
if (
|
|
246
|
+
if (results.length === 1) {
|
|
247
|
+
executeCommand(results[0].command, results[0].os);
|
|
248
|
+
} else if (shouldCopy) {
|
|
239
249
|
const cmdToSend = prepareCommand(results[0].command, results[0].os);
|
|
240
250
|
const copied = copyToClipboard(cmdToSend);
|
|
241
251
|
if (copied) {
|