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 {
handleBuild,
handleCreate,
handleUpdate,
handleUpgrade,
handleRestore,
handleSync,
} from "./cli/handlers.js"
import { handleMigrate } from "./cli/migrate-handler.js"
import {
handlePluginInstall as handleGitPluginInstall,
handlePluginInstallUnified,
handlePluginAdd,
handlePluginRemove,
handlePluginUpdate,
handlePluginRestore,
handlePluginList,
handlePluginEnable,
handlePluginDisable,
handlePluginConfig,
handlePluginCheck,
handlePluginPrune,
handlePluginResolve,
} from "./cli/plugin-git-handlers.js"
import {
CommonArgv,
BuildArgv,
CreateArgv,
SyncArgv,
PluginInstallArgv,
PluginUninstallArgv,
PluginSearchArgv,
} from "./cli/args.js"
import { CommonArgv, BuildArgv, CreateArgv, SyncArgv } from "./cli/args.js"
import { version } from "./cli/constants.js"
async function launchTui() {
@@ -83,14 +70,6 @@ yargs(hideBin(process.argv))
.command("create", "Initialize Quartz", CreateArgv, async (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) => {
await handleUpgrade(argv)
})
@@ -118,115 +97,162 @@ yargs(hideBin(process.argv))
"plugin [subcommand]",
"Manage Quartz plugins",
(yargs) => {
return yargs
.command("install", "Install plugins from quartz.lock.json", CommonArgv, async () => {
await handleGitPluginInstall()
})
.command(
"add <repos..>",
"Add plugins from Git repositories",
{
...CommonArgv,
name: {
string: true,
alias: ["as"],
describe: "Override the plugin name (for resolving conflicts with duplicate names)",
return (
yargs
.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",
},
},
subdir: {
string: true,
describe: "Subdirectory within the repository containing the plugin",
async (argv) => {
await handlePluginInstallUnified({
names: argv.names?.length ? argv.names : undefined,
fromConfig: argv.fromConfig,
latest: argv.latest,
clean: argv.clean,
dryRun: argv.dryRun,
})
},
},
async (argv) => {
await handlePluginAdd(argv.repos, { name: argv.name, subdir: argv.subdir })
},
)
.command("remove <names..>", "Remove installed plugins", CommonArgv, async (argv) => {
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 () => {
await handlePluginList()
})
.command(
"restore",
"Restore plugins from lockfile (exact versions)",
CommonArgv,
async () => {
await handlePluginRestore()
},
)
.command(
"enable <names..>",
"Enable plugins in quartz.config.yaml",
CommonArgv,
async (argv) => {
await handlePluginEnable(argv.names)
},
)
.command(
"disable <names..>",
"Disable plugins in quartz.config.yaml",
CommonArgv,
async (argv) => {
await handlePluginDisable(argv.names)
},
)
.command(
"config <name>",
"View or set plugin configuration",
{
...CommonArgv,
set: {
string: true,
describe: "Set a config value (key=value)",
)
.command(
"add <repos..>",
"Add plugins from Git repositories",
{
...CommonArgv,
name: {
string: true,
alias: ["as"],
describe: "Override the plugin name (for resolving conflicts with duplicate names)",
},
subdir: {
string: true,
describe: "Subdirectory within the repository containing the plugin",
},
},
},
async (argv) => {
await handlePluginConfig(argv.name, { set: argv.set })
},
)
.command("check", "Check for plugin updates", CommonArgv, async () => {
await handlePluginCheck()
})
.command(
"prune",
"Remove installed plugins no longer referenced in config",
{
...CommonArgv,
"dry-run": {
boolean: true,
default: false,
describe: "show what would be pruned without making changes",
async (argv) => {
await handlePluginAdd(argv.repos, {
name: argv.name,
subdir: argv.subdir,
})
},
},
async (argv) => {
await handlePluginPrune({ dryRun: argv.dryRun })
},
)
.command(
"resolve",
"Install plugins from config that are not yet in the lockfile",
{
...CommonArgv,
"dry-run": {
boolean: true,
default: false,
describe: "show what would be resolved without making changes",
)
.command("remove <names..>", "Remove installed plugins", CommonArgv, async (argv) => {
await handlePluginRemove(argv.names)
})
.command("list", "List all installed plugins", CommonArgv, async () => {
await handlePluginList()
})
.command(
"enable <names..>",
"Enable plugins in quartz.config.yaml",
CommonArgv,
async (argv) => {
await handlePluginEnable(argv.names)
},
},
async (argv) => {
await handlePluginResolve({ dryRun: argv.dryRun })
},
)
.demandCommand(0, "")
)
.command(
"disable <names..>",
"Disable plugins in quartz.config.yaml",
CommonArgv,
async (argv) => {
await handlePluginDisable(argv.names)
},
)
.command(
"config <name>",
"View or set plugin configuration",
{
...CommonArgv,
set: {
string: true,
describe: "Set a config value (key=value)",
},
},
async (argv) => {
await handlePluginConfig(argv.name, { set: argv.set })
},
)
.command(
"prune",
"Remove installed plugins no longer referenced in config",
{
...CommonArgv,
"dry-run": {
boolean: true,
default: false,
describe: "show what would be pruned without making changes",
},
},
async (argv) => {
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(
"resolve",
false,
{
...CommonArgv,
"dry-run": {
boolean: true,
default: false,
describe: "show what would be resolved without making changes",
},
},
async (argv) => {
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, "")
)
},
async (argv) => {
if (!argv._.includes("plugin") || argv._.length > 1) return

View File

@@ -26,7 +26,6 @@ import {
import {
handlePluginRestore,
handlePluginCheck,
handlePluginUpdate,
handlePluginResolve,
} from "./plugin-git-handlers.js"
import {
@@ -682,16 +681,6 @@ export async function handleUpgrade(argv) {
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`
* @param {*} argv arguments for `restore`

File diff suppressed because it is too large Load Diff