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,115 +97,162 @@ 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..]",
.command( "Install plugins from lockfile or config",
"add <repos..>", {
"Add plugins from Git repositories", ...CommonArgv,
{ "from-config": {
...CommonArgv, boolean: true,
name: { default: false,
string: true, describe: "install plugins referenced in quartz.config.yaml instead of lockfile",
alias: ["as"], },
describe: "Override the plugin name (for resolving conflicts with duplicate names)", 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: { async (argv) => {
string: true, await handlePluginInstallUnified({
describe: "Subdirectory within the repository containing the plugin", names: argv.names?.length ? argv.names : undefined,
fromConfig: argv.fromConfig,
latest: argv.latest,
clean: argv.clean,
dryRun: argv.dryRun,
})
}, },
}, )
async (argv) => { .command(
await handlePluginAdd(argv.repos, { name: argv.name, subdir: argv.subdir }) "add <repos..>",
}, "Add plugins from Git repositories",
) {
.command("remove <names..>", "Remove installed plugins", CommonArgv, async (argv) => { ...CommonArgv,
await handlePluginRemove(argv.names) name: {
}) string: true,
.command( alias: ["as"],
"update [names..]", describe: "Override the plugin name (for resolving conflicts with duplicate names)",
"Update installed plugins to latest version", },
CommonArgv, subdir: {
async (argv) => { string: true,
await handlePluginUpdate(argv.names) describe: "Subdirectory within the repository containing the plugin",
}, },
)
.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)",
}, },
}, async (argv) => {
async (argv) => { await handlePluginAdd(argv.repos, {
await handlePluginConfig(argv.name, { set: argv.set }) name: argv.name,
}, subdir: argv.subdir,
) })
.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) => { .command("remove <names..>", "Remove installed plugins", CommonArgv, async (argv) => {
await handlePluginPrune({ dryRun: argv.dryRun }) await handlePluginRemove(argv.names)
}, })
) .command("list", "List all installed plugins", CommonArgv, async () => {
.command( await handlePluginList()
"resolve", })
"Install plugins from config that are not yet in the lockfile", .command(
{ "enable <names..>",
...CommonArgv, "Enable plugins in quartz.config.yaml",
"dry-run": { CommonArgv,
boolean: true, async (argv) => {
default: false, await handlePluginEnable(argv.names)
describe: "show what would be resolved without making changes",
}, },
}, )
async (argv) => { .command(
await handlePluginResolve({ dryRun: argv.dryRun }) "disable <names..>",
}, "Disable plugins in quartz.config.yaml",
) CommonArgv,
.demandCommand(0, "") 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) => { 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