Skip to content

Commit 06f112d

Browse files
Yes
1 parent 45a5c6e commit 06f112d

5 files changed

Lines changed: 66 additions & 33 deletions

File tree

index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const HELP = `justinstall <github-url|website-url|file-url|local-file> [options]
3636
\t --update [package] Update all packages or specific package
3737
\t --uninstall <name> Uninstall a previously installed package
3838
\t --list List installed packages
39+
\t --yes Answer yes to all prompts
3940
\t -h, --help Show this help
4041
4142
\tExamples:
@@ -83,13 +84,14 @@ const handleUpdateCommand = async (flags, args) => {
8384
log.warn(
8485
`Unable to verify current version for ${flags.updatePackage}. Will reinstall to ensure freshness.`
8586
);
86-
if (await confirm(`Proceed to reinstall ${flags.updatePackage}?`)) {
87+
if (await confirm(`Proceed to reinstall ${flags.updatePackage}?`, "y", flags.yes)) {
8788
await performUpdate(
8889
{
8990
name: flags.updatePackage,
9091
source: updateInfo.source,
9192
},
92-
customFilePath
93+
customFilePath,
94+
flags.yes
9395
);
9496
}
9597
return;
@@ -105,8 +107,8 @@ const handleUpdateCommand = async (flags, args) => {
105107
log.log(
106108
`Update available for ${flags.updatePackage}: ${updateInfo.reason}`
107109
);
108-
if (await confirm(`Proceed with update?`)) {
109-
await performUpdate(updateInfo, customFilePath);
110+
if (await confirm(`Proceed with update?`, "y", flags.yes)) {
111+
await performUpdate(updateInfo, customFilePath, flags.yes);
110112
}
111113
} else {
112114
// Update all packages
@@ -123,11 +125,11 @@ const handleUpdateCommand = async (flags, args) => {
123125
log.log(` ${update.name}: ${update.reason}`);
124126
}
125127

126-
if (await confirm(`Update all ${updates.length} package(s)?`)) {
128+
if (await confirm(`Update all ${updates.length} package(s)?`, "y", flags.yes)) {
127129
for (const update of updates) {
128130
if (update.canUpdate) {
129131
try {
130-
await performUpdate(update);
132+
await performUpdate(update, null, flags.yes);
131133
} catch (error) {
132134
log.error(`Failed to update ${update.name}: ${error.message}`);
133135
}
@@ -157,7 +159,7 @@ const main = async () => {
157159
if (!name) {
158160
throw new Error("--uninstall requires a package name");
159161
}
160-
await performUninstall(name);
162+
await performUninstall(name, flags.yes);
161163
return;
162164
}
163165

@@ -173,7 +175,7 @@ const main = async () => {
173175
if (repos && repos.length > 0) {
174176
const log = createLogger();
175177
if (
176-
await confirm(`Install the first result (${repos[0].full_name})?`)
178+
await confirm(`Install the first result (${repos[0].full_name})?`, "y", flags.yes)
177179
) {
178180
await performInstallation([repos[0].full_name]);
179181
} else {
@@ -199,7 +201,7 @@ const main = async () => {
199201

200202
if (flags.first) {
201203
const repo = await findFirstRepository(flags.first);
202-
await performInstallation([repo.full_name]);
204+
await performInstallation([repo.full_name], false, flags.yes);
203205
return;
204206
}
205207

@@ -208,7 +210,7 @@ const main = async () => {
208210
return;
209211
}
210212

211-
await performInstallation(remainingArgs);
213+
await performInstallation(remainingArgs, false, flags.yes);
212214
};
213215

214216
// Main execution

lib/installer.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const SCRIPT_PREVIEW_CONFIG = {
5555

5656
let tmpdir;
5757

58-
const performInstallation = async (args, isUpdate = false) => {
58+
const performInstallation = async (args, isUpdate = false, yesFlag = false) => {
5959
const log = createLogger();
6060

6161
if (args.length === 0) {
@@ -131,6 +131,8 @@ const performInstallation = async (args, isUpdate = false) => {
131131
`Ok to ${isUpdate ? "update" : "install"} ${selected.name} (${fileSize(
132132
selected.size,
133133
)})?`,
134+
"y",
135+
yesFlag
134136
);
135137

136138
if (!shouldInstall) {
@@ -385,6 +387,8 @@ const handleSingleScript = async (script, log) => {
385387

386388
const shouldRun = await confirm(
387389
"Run this edited install script (y) or continue to regular installation (n)?",
390+
"y",
391+
yesFlag
388392
);
389393

390394
if (shouldRun) return editedScript;
@@ -421,13 +425,16 @@ const handleMultipleScripts = async (installScripts, log) => {
421425
const scriptChoice = await promptChoice(
422426
`Which script would you like to edit? (1-${installScripts.length}): `,
423427
installScripts.length,
428+
yesFlag
424429
);
425430
const scriptToEdit = installScripts[scriptChoice - 1];
426431
const editedScript = await editScriptInEditor(scriptToEdit);
427432
displayScriptPreview(editedScript, log);
428433

429434
const shouldRun = await confirm(
430435
"Run this edited install script (y) or choose a different one (n)?",
436+
"y",
437+
yesFlag
431438
);
432439

433440
if (shouldRun) return editedScript;
@@ -440,6 +447,8 @@ const handleMultipleScripts = async (installScripts, log) => {
440447

441448
const shouldRun = await confirm(
442449
"Run this install script (y) or choose a different one (n)?",
450+
"y",
451+
yesFlag
443452
);
444453

445454
if (shouldRun) return script;
@@ -518,7 +527,7 @@ const handleGitHubSource = async (source, platformInfo, capabilities, log) => {
518527
if (installerScript) {
519528
log.debug(`Found installer script: ${installerScript.name}`);
520529

521-
if (await confirm(`Run install script? ${installerScript.name}`)) {
530+
if (await confirm(`Run install script? ${installerScript.name}`, "y", yesFlag)) {
522531
const scriptPath = path.join(tmpdir, "installer.sh");
523532
const { size } = await downloadFromUrl(
524533
installerScript.browser_download_url,
@@ -652,7 +661,7 @@ const installSelected = async (selected, downloadPath, log) => {
652661

653662
if (appFile) {
654663
log.log(`Installing .app bundle: ${appFile}`);
655-
destinations = await installApp(appFile, mountDir, checkPath, log);
664+
destinations = await installApp(appFile, mountDir, checkPath, log, null, yesFlag);
656665
binariesList = [appFile];
657666

658667
// Ask to open app
@@ -668,14 +677,15 @@ const installSelected = async (selected, downloadPath, log) => {
668677
log.log(
669678
"No .app or .pkg found in DMG, trying to install executables",
670679
);
671-
const selectedBinaries = await selectBinaries(dmgBinaries, selected.name, log);
680+
const selectedBinaries = await selectBinaries(dmgBinaries, selected.name, log, yesFlag);
672681
destinations = await installBinaries(
673682
selectedBinaries,
674683
mountDir,
675684
selected.name,
676685
checkPath,
677686
log,
678687
true, // isMountedVolume = true
688+
yesFlag
679689
);
680690
binariesList = selectedBinaries.map((bin) => path.basename(bin));
681691
} else {
@@ -700,10 +710,12 @@ const installSelected = async (selected, downloadPath, log) => {
700710
path.dirname(downloadPath),
701711
checkPath,
702712
log,
713+
null,
714+
yesFlag
703715
);
704716
binariesList = [selected.name];
705-
// Ask to open app
706-
if (await confirm(`Open app ${path.basename(destinations[0])}?`)) {
717+
// Ask to open app
718+
if (await confirm(`Open app ${path.basename(destinations[0])}?`, "y", yesFlag)) {
707719
execSync(`open -n ${JSON.stringify(destinations[0])}`);
708720
}
709721
break;
@@ -737,28 +749,32 @@ const installSelected = async (selected, downloadPath, log) => {
737749
selected.name,
738750
checkPath,
739751
log,
752+
false,
753+
yesFlag
740754
);
741755

742756
if (packageResult) {
743757
// Use the package installation result
744758
installationMethod = packageResult.method;
745759
destinations = packageResult.destinations;
746760
binariesList = packageResult.binaries;
747-
if (installationMethod === "archive_app") {
761+
if (installationMethod === "archive_app") {
748762
// Ask to open app
749-
if (await confirm(`Open app ${path.basename(destinations[0])}?`)) {
763+
if (await confirm(`Open app ${path.basename(destinations[0])}?`, "y", yesFlag)) {
750764
execSync(`open -n ${JSON.stringify(destinations[0])}`);
751765
}
752766
}
753767
} else {
754768
// Fall back to regular binary installation
755-
const selectedBinaries = await selectBinaries(extractedBinaries, selected.name, log);
769+
const selectedBinaries = await selectBinaries(extractedBinaries, selected.name, log, yesFlag);
756770
destinations = await installBinaries(
757771
selectedBinaries,
758772
outputDir,
759773
selected.name,
760774
checkPath,
761775
log,
776+
false,
777+
yesFlag
762778
);
763779
binariesList = selectedBinaries.map((bin) => path.basename(bin));
764780
}

lib/installers.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ const getBinaries = (dir) => {
308308
* @param {Object} logger - Logger instance
309309
* @returns {Promise<string[]>} Selected binaries
310310
*/
311-
const selectBinaries = async (binaries, packageName, logger = null) => {
311+
const selectBinaries = async (binaries, packageName, logger = null, yesFlag = false) => {
312312
if (binaries.length <= 1) {
313313
return binaries;
314314
}
@@ -351,7 +351,7 @@ const selectBinaries = async (binaries, packageName, logger = null) => {
351351
output: process.stdout,
352352
});
353353

354-
const choice = await new Promise((resolve) => {
354+
const choice = yesFlag ? '1' : await new Promise((resolve) => {
355355
rli.question(`Enter binary number to install (1-${binariesToChoose.length}), or 'all' for all: `, (ans) => {
356356
rli.close();
357357
resolve(ans.trim().toLowerCase());
@@ -478,7 +478,7 @@ const processExtractedPackages = async (
478478
return null; // No packages found
479479
};
480480

481-
const installApp = async (appPath, outputDir, checkPathFn, logger = null) => {
481+
const installApp = async (appPath, outputDir, checkPathFn, logger = null, yesFlag = false) => {
482482
const original = path.basename(appPath);
483483
const cleanedBase = extractName({ name: original }) || original.replace(/\.app$/i, "");
484484
const cleaned = cleanedBase.replace(/\.app$/i, "");
@@ -583,7 +583,8 @@ const installBinaries = async (
583583
selectedName,
584584
checkPathFn,
585585
logger = null,
586-
isMountedVolume = false
586+
isMountedVolume = false,
587+
yesFlag = false
587588
) => {
588589
const destinations = [];
589590

@@ -592,7 +593,7 @@ const installBinaries = async (
592593
const cleanName = extractName({ name: selectedName });
593594
const dest = path.join(os.homedir(), ".local", "bin", cleanName);
594595

595-
await checkPathFn(dest);
596+
await checkPathFn(dest, yesFlag);
596597

597598
// Don't try to chmod files on mounted volumes (like DMGs)
598599
if (!isMountedVolume) {

lib/updater.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ const checkSmartUrlUpdate = async (installation, forceCheck) => {
191191
};
192192
};
193193

194-
const performUpdate = async (updateInfo, customFilePath = null) => {
194+
const performUpdate = async (updateInfo, customFilePath = null, yesFlag = false) => {
195195
const log = createLogger();
196196
const { name } = updateInfo;
197197

@@ -215,7 +215,7 @@ const performUpdate = async (updateInfo, customFilePath = null) => {
215215
const { performInstallation } = require("./installer");
216216

217217
try {
218-
await performInstallation(originalArgs, true); // isUpdate = true
218+
await performInstallation(originalArgs, true, yesFlag); // isUpdate = true
219219

220220
// After successful update, refresh the installation record with new version info
221221
if (updateInfo.newTag) {
@@ -287,7 +287,7 @@ const getPathSize = (p) => {
287287
return 0;
288288
};
289289

290-
const performUninstall = async (packageName) => {
290+
const performUninstall = async (packageName, yesFlag = false) => {
291291
const log = createLogger();
292292
const config = loadConfig();
293293
const installation = config.find((item) => item.name === packageName);
@@ -315,7 +315,7 @@ const performUninstall = async (packageName) => {
315315
const { fileSize, confirm } = require("./utils");
316316
const pretty = fileSize(totalBytes, true, 1);
317317
log.log(`Uninstalling ${packageName} (${pretty})`);
318-
if (!(await confirm(`Proceed to uninstall ${packageName}?`))) {
318+
if (!(await confirm(`Proceed to uninstall ${packageName}?`, "y", yesFlag))) {
319319
throw new Error("Uninstall canceled by user");
320320
}
321321

lib/utils.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ const createLogger = (level = LOG_LEVELS.LOG) => ({
5858
console.warn(`${colors.fg.yellow}${message}${colors.reset}`),
5959
});
6060

61-
const confirm = (question, defaultAnswer = "y") => {
61+
const confirm = (question, defaultAnswer = "y", yesFlag = false) => {
62+
if (yesFlag) {
63+
return Promise.resolve(true);
64+
}
65+
6266
return new Promise((resolve) => {
6367
const rli = readline.createInterface({
6468
input: process.stdin,
@@ -80,11 +84,15 @@ const confirm = (question, defaultAnswer = "y") => {
8084
});
8185
};
8286

83-
const promptChoice = (question, maxChoice) => {
87+
const promptChoice = (question, maxChoice, yesFlag = false) => {
8488
if (maxChoice < 1) {
8589
throw new Error("maxChoice must be at least 1");
8690
}
8791

92+
if (yesFlag) {
93+
return Promise.resolve(1); // Return first choice by default
94+
}
95+
8896
return new Promise((resolve) => {
8997
const askQuestion = () => {
9098
const rli = readline.createInterface({
@@ -112,11 +120,15 @@ const promptChoice = (question, maxChoice) => {
112120
});
113121
};
114122

115-
const promptChoiceWithEdit = (question, maxChoice, allowEdit = false) => {
123+
const promptChoiceWithEdit = (question, maxChoice, allowEdit = false, yesFlag = false) => {
116124
if (maxChoice < 1) {
117125
throw new Error("maxChoice must be at least 1");
118126
}
119127

128+
if (yesFlag) {
129+
return Promise.resolve(1); // Return first choice by default
130+
}
131+
120132
return new Promise((resolve) => {
121133
const askQuestion = () => {
122134
const rli = readline.createInterface({
@@ -228,9 +240,9 @@ const createLink = (text, url) => {
228240
return [OSC, "8", SEP, SEP, url, BEL, text, OSC, "8", SEP, SEP, BEL].join("");
229241
};
230242

231-
const checkPath = async (p) => {
243+
const checkPath = async (p, yesFlag = false) => {
232244
if (fs.existsSync(p)) {
233-
if (!(await confirm(`Overwrite ${p}?`))) {
245+
if (!(await confirm(`Overwrite ${p}?`, "y", yesFlag))) {
234246
throw new Error("Aborted overwrite of file " + p);
235247
} else {
236248
try {
@@ -299,6 +311,8 @@ const parseFlags = (args) => {
299311
} else {
300312
throw new Error("--first requires a search query");
301313
}
314+
} else if (flagName === "yes") {
315+
flags.yes = true;
302316
}
303317
} else if (arg.startsWith("-")) {
304318
const shortFlags = arg.substring(1);

0 commit comments

Comments
 (0)