refactor: simplified CLI options

This commit is contained in:
saberzero1
2026-03-31 18:50:27 +02:00
parent 704484d6a5
commit db2cc6abca
3 changed files with 729 additions and 602 deletions

View File

@@ -4,35 +4,22 @@ import { hideBin } from "yargs/helpers"
import { import {
handleBuild, handleBuild,
handleCreate, handleCreate,
handleUpdate,
handleUpgrade, handleUpgrade,
handleRestore, handleRestore,
handleSync, handleSync,
} from "./cli/handlers.js" } from "./cli/handlers.js"
import { handleMigrate } from "./cli/migrate-handler.js" import { handleMigrate } from "./cli/migrate-handler.js"
import { import {
handlePluginInstall as handleGitPluginInstall, handlePluginInstallUnified,
handlePluginAdd, handlePluginAdd,
handlePluginRemove, handlePluginRemove,
handlePluginUpdate,
handlePluginRestore,
handlePluginList, handlePluginList,
handlePluginEnable, handlePluginEnable,
handlePluginDisable, handlePluginDisable,
handlePluginConfig, handlePluginConfig,
handlePluginCheck,
handlePluginPrune, handlePluginPrune,
handlePluginResolve,
} from "./cli/plugin-git-handlers.js" } from "./cli/plugin-git-handlers.js"
import { import { CommonArgv, BuildArgv, CreateArgv, SyncArgv } from "./cli/args.js"
CommonArgv,
BuildArgv,
CreateArgv,
SyncArgv,
PluginInstallArgv,
PluginUninstallArgv,
PluginSearchArgv,
} from "./cli/args.js"
import { version } from "./cli/constants.js" import { version } from "./cli/constants.js"
async function launchTui() { async function launchTui() {
@@ -83,14 +70,6 @@ yargs(hideBin(process.argv))
.command("create", "Initialize Quartz", CreateArgv, async (argv) => { .command("create", "Initialize Quartz", CreateArgv, async (argv) => {
await handleCreate(argv) await handleCreate(argv)
}) })
.command(
"update [names..]",
"Update installed plugins to latest version",
CommonArgv,
async (argv) => {
await handleUpdate(argv)
},
)
.command("upgrade", "Upgrade Quartz to the latest version", CommonArgv, async (argv) => { .command("upgrade", "Upgrade Quartz to the latest version", CommonArgv, async (argv) => {
await handleUpgrade(argv) await handleUpgrade(argv)
}) })
@@ -118,10 +97,44 @@ yargs(hideBin(process.argv))
"plugin [subcommand]", "plugin [subcommand]",
"Manage Quartz plugins", "Manage Quartz plugins",
(yargs) => { (yargs) => {
return yargs return (
.command("install", "Install plugins from quartz.lock.json", CommonArgv, async () => { yargs
await handleGitPluginInstall() .command(
"install [names..]",
"Install plugins from lockfile or config",
{
...CommonArgv,
"from-config": {
boolean: true,
default: false,
describe: "install plugins referenced in quartz.config.yaml instead of lockfile",
},
latest: {
boolean: true,
default: false,
describe: "fetch latest version from remote instead of pinned lockfile commit",
},
clean: {
boolean: true,
default: false,
describe: "skip plugins whose directory already exists",
},
"dry-run": {
boolean: true,
default: false,
describe: "show what would happen without making changes",
},
},
async (argv) => {
await handlePluginInstallUnified({
names: argv.names?.length ? argv.names : undefined,
fromConfig: argv.fromConfig,
latest: argv.latest,
clean: argv.clean,
dryRun: argv.dryRun,
}) })
},
)
.command( .command(
"add <repos..>", "add <repos..>",
"Add plugins from Git repositories", "Add plugins from Git repositories",
@@ -138,31 +151,18 @@ yargs(hideBin(process.argv))
}, },
}, },
async (argv) => { async (argv) => {
await handlePluginAdd(argv.repos, { name: argv.name, subdir: argv.subdir }) await handlePluginAdd(argv.repos, {
name: argv.name,
subdir: argv.subdir,
})
}, },
) )
.command("remove <names..>", "Remove installed plugins", CommonArgv, async (argv) => { .command("remove <names..>", "Remove installed plugins", CommonArgv, async (argv) => {
await handlePluginRemove(argv.names) await handlePluginRemove(argv.names)
}) })
.command(
"update [names..]",
"Update installed plugins to latest version",
CommonArgv,
async (argv) => {
await handlePluginUpdate(argv.names)
},
)
.command("list", "List all installed plugins", CommonArgv, async () => { .command("list", "List all installed plugins", CommonArgv, async () => {
await handlePluginList() await handlePluginList()
}) })
.command(
"restore",
"Restore plugins from lockfile (exact versions)",
CommonArgv,
async () => {
await handlePluginRestore()
},
)
.command( .command(
"enable <names..>", "enable <names..>",
"Enable plugins in quartz.config.yaml", "Enable plugins in quartz.config.yaml",
@@ -193,9 +193,6 @@ yargs(hideBin(process.argv))
await handlePluginConfig(argv.name, { set: argv.set }) await handlePluginConfig(argv.name, { set: argv.set })
}, },
) )
.command("check", "Check for plugin updates", CommonArgv, async () => {
await handlePluginCheck()
})
.command( .command(
"prune", "prune",
"Remove installed plugins no longer referenced in config", "Remove installed plugins no longer referenced in config",
@@ -211,9 +208,31 @@ yargs(hideBin(process.argv))
await handlePluginPrune({ dryRun: argv.dryRun }) await handlePluginPrune({ dryRun: argv.dryRun })
}, },
) )
// Hidden deprecated aliases
.command("restore", false, CommonArgv, async () => {
console.log(
"\x1b[33m⚠ 'plugin restore' is deprecated. Use 'plugin install --clean' instead.\x1b[0m",
)
await handlePluginInstallUnified({ clean: true })
})
.command("update [names..]", false, CommonArgv, async (argv) => {
console.log(
"\x1b[33m⚠ 'plugin update' is deprecated. Use 'plugin install --latest' instead.\x1b[0m",
)
await handlePluginInstallUnified({
names: argv.names?.length ? argv.names : undefined,
latest: true,
})
})
.command("check", false, CommonArgv, async () => {
console.log(
"\x1b[33m⚠ 'plugin check' is deprecated. Use 'plugin install --latest --dry-run' instead.\x1b[0m",
)
await handlePluginInstallUnified({ latest: true, dryRun: true })
})
.command( .command(
"resolve", "resolve",
"Install plugins from config that are not yet in the lockfile", false,
{ {
...CommonArgv, ...CommonArgv,
"dry-run": { "dry-run": {
@@ -223,10 +242,17 @@ yargs(hideBin(process.argv))
}, },
}, },
async (argv) => { async (argv) => {
await handlePluginResolve({ dryRun: argv.dryRun }) console.log(
"\x1b[33m⚠ 'plugin resolve' is deprecated. Use 'plugin install --from-config' instead.\x1b[0m",
)
await handlePluginInstallUnified({
fromConfig: true,
dryRun: argv.dryRun,
})
}, },
) )
.demandCommand(0, "") .demandCommand(0, "")
)
}, },
async (argv) => { async (argv) => {
if (!argv._.includes("plugin") || argv._.length > 1) return if (!argv._.includes("plugin") || argv._.length > 1) return

View File

@@ -26,7 +26,6 @@ import {
import { import {
handlePluginRestore, handlePluginRestore,
handlePluginCheck, handlePluginCheck,
handlePluginUpdate,
handlePluginResolve, handlePluginResolve,
} from "./plugin-git-handlers.js" } from "./plugin-git-handlers.js"
import { import {
@@ -682,16 +681,6 @@ export async function handleUpgrade(argv) {
console.log(styleText("green", "Done!")) console.log(styleText("green", "Done!"))
} }
/**
* Handles `npx quartz update`
* Shortcut for `npx quartz plugin update` — updates all installed plugins.
* @param {*} argv arguments for `update`
*/
export async function handleUpdate(argv) {
console.log(`\n${styleText(["bgGreen", "black"], ` Quartz v${version} `)} \n`)
await handlePluginUpdate(argv.names)
}
/** /**
* Handles `npx quartz restore` * Handles `npx quartz restore`
* @param {*} argv arguments for `restore` * @param {*} argv arguments for `restore`

File diff suppressed because it is too large Load Diff