@p11-core/cli 0.0.8 → 0.0.9
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/dist/index.js +18 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3625,6 +3625,11 @@ async function main() {
|
|
|
3625
3625
|
return;
|
|
3626
3626
|
}
|
|
3627
3627
|
const command = process.argv[2];
|
|
3628
|
+
if (isVersionFlag(command)) {
|
|
3629
|
+
await warnIfUpdateAvailable({ force: true });
|
|
3630
|
+
console.log(packageJson.version);
|
|
3631
|
+
return;
|
|
3632
|
+
}
|
|
3628
3633
|
if (!isKnownTopLevelCommand(program2, command)) throw new Error(`Unknown command: ${command}`);
|
|
3629
3634
|
await program2.parseAsync(process.argv);
|
|
3630
3635
|
}
|
|
@@ -3632,7 +3637,9 @@ function createCliProgram(options = {}) {
|
|
|
3632
3637
|
const program2 = new Command();
|
|
3633
3638
|
const warnBeforeAction = options.warnIfUpdateAvailable ?? warnIfUpdateAvailable;
|
|
3634
3639
|
program2.name("p11").description("Share and inspect p11 document pages.");
|
|
3635
|
-
program2.
|
|
3640
|
+
program2.version(packageJson.version);
|
|
3641
|
+
program2.hook("preAction", async (_thisCommand, actionCommand) => {
|
|
3642
|
+
if (actionCommand.name() === "version") return;
|
|
3636
3643
|
await warnBeforeAction();
|
|
3637
3644
|
});
|
|
3638
3645
|
program2.addHelpText(
|
|
@@ -3655,6 +3662,10 @@ Environment:
|
|
|
3655
3662
|
await deleteDocument(target, normalizeDeleteOptions(options2));
|
|
3656
3663
|
});
|
|
3657
3664
|
allowLegacyParserBehavior(deleteCommand);
|
|
3665
|
+
program2.command("version").description("Print the p11 CLI version.").action(async () => {
|
|
3666
|
+
await warnBeforeAction({ force: true });
|
|
3667
|
+
console.log(packageJson.version);
|
|
3668
|
+
});
|
|
3658
3669
|
program2.command("history").description("List saved read/edit links.").option("--json", "Print saved history as JSON.").action(async (options2) => {
|
|
3659
3670
|
await history(normalizeHistoryOptions(options2));
|
|
3660
3671
|
});
|
|
@@ -3669,7 +3680,10 @@ Environment:
|
|
|
3669
3680
|
return program2;
|
|
3670
3681
|
}
|
|
3671
3682
|
function isKnownTopLevelCommand(program2, command) {
|
|
3672
|
-
return command === "--help" || command === "-h" || command === "help" || program2.commands.some((subcommand) => subcommand.name() === command);
|
|
3683
|
+
return command === "--help" || command === "-h" || isVersionFlag(command) || command === "help" || program2.commands.some((subcommand) => subcommand.name() === command);
|
|
3684
|
+
}
|
|
3685
|
+
function isVersionFlag(command) {
|
|
3686
|
+
return command === "--version" || command === "-V";
|
|
3673
3687
|
}
|
|
3674
3688
|
function allowLegacyParserBehavior(command) {
|
|
3675
3689
|
return command.allowUnknownOption().allowExcessArguments();
|
|
@@ -4417,12 +4431,12 @@ function validateAccessTarget(target, expected) {
|
|
|
4417
4431
|
function normalizeApiUrl(value) {
|
|
4418
4432
|
return value.endsWith("/") ? value.slice(0, -1) : value;
|
|
4419
4433
|
}
|
|
4420
|
-
async function warnIfUpdateAvailable() {
|
|
4434
|
+
async function warnIfUpdateAvailable(options = {}) {
|
|
4421
4435
|
if (process.env.P11_DISABLE_UPDATE_CHECK) return;
|
|
4422
4436
|
try {
|
|
4423
4437
|
const cachePath = updateCheckCachePath();
|
|
4424
4438
|
const checkedAt = await readUpdateCheckTime(cachePath);
|
|
4425
|
-
if (checkedAt && Date.now() - checkedAt.getTime() < updateCheckIntervalMs) return;
|
|
4439
|
+
if (!options.force && checkedAt && Date.now() - checkedAt.getTime() < updateCheckIntervalMs) return;
|
|
4426
4440
|
await writeUpdateCheckTime(cachePath);
|
|
4427
4441
|
const latestVersion = await fetchLatestVersion();
|
|
4428
4442
|
if (!latestVersion || !isNewerVersion(latestVersion, packageJson.version)) return;
|