Skip to content

Commit 0b2538b

Browse files
committed
feat(update): add global update support (-g)
- add support for 'vix update -g @namespace/name' - reuse install -g logic for global updates - update help command with global mode usage - clarify project vs global behavior global update now works without vix.lock
1 parent 412a163 commit 0b2538b

File tree

1 file changed

+52
-21
lines changed

1 file changed

+52
-21
lines changed

src/commands/UpdateCommand.cpp

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ namespace vix::commands
3939
bool jsonOutput{false};
4040
bool installAfter{false};
4141
std::vector<std::string> rawTargets;
42+
bool globalMode{false};
43+
std::string globalSpec;
4244
};
4345

4446
struct PkgSpec
@@ -170,6 +172,14 @@ namespace vix::commands
170172
{
171173
opt.installAfter = true;
172174
}
175+
else if (arg == "-g" || arg == "--global")
176+
{
177+
opt.globalMode = true;
178+
}
179+
else if (opt.globalMode && opt.globalSpec.empty())
180+
{
181+
opt.globalSpec = arg;
182+
}
173183
else if (arg == "-h" || arg == "--help")
174184
{
175185
return UpdateCommand::help();
@@ -324,6 +334,24 @@ namespace vix::commands
324334
return parseRc;
325335
}
326336

337+
// ============================================
338+
// GLOBAL UPDATE MODE
339+
// ============================================
340+
if (opt.globalMode)
341+
{
342+
if (opt.globalSpec.empty())
343+
{
344+
vix::cli::util::err_line(std::cerr, "missing package spec");
345+
vix::cli::util::warn_line(std::cerr, "Example: vix update -g @gk/jwt");
346+
return 1;
347+
}
348+
349+
vix::cli::util::section(std::cout, "Update global package");
350+
351+
// reuse install logic
352+
return InstallCommand::run({"-g", opt.globalSpec});
353+
}
354+
327355
json lock = read_lock_or_throw();
328356

329357
int targetRc = 0;
@@ -471,47 +499,50 @@ namespace vix::commands
471499
{
472500
std::cout
473501
<< "vix update (alias: up)\n"
474-
<< "Update project dependencies to newer versions.\n\n"
502+
<< "Update project or global packages to newer versions.\n\n"
475503

476504
<< "Usage\n"
477505
<< " vix update\n"
478506
<< " vix up\n"
479507
<< " vix update [@]namespace/name[@version]\n"
480508
<< " vix up [@]namespace/name[@version]\n"
481-
<< " vix update [@]namespace/name[@version] [@]namespace/name[@version]\n"
482-
<< " vix up [@]namespace/name[@version] [@]namespace/name[@version]\n"
483509
<< " vix update [options]\n"
484-
<< " vix up [options]\n\n"
510+
<< " vix up [options]\n"
511+
<< " vix update -g [@]namespace/name[@version]\n\n"
485512

486513
<< "Options\n"
487-
<< " --dry-run Show what would be updated without changing vix.lock\n"
488-
<< " --json Print machine-readable JSON output\n"
489-
<< " --install Run 'vix install' after update\n"
490-
<< " -h, --help Show this help message\n\n"
514+
<< " -g, --global Update a global package\n"
515+
<< " --dry-run Show what would be updated without changing vix.lock\n"
516+
<< " --json Print machine-readable JSON output\n"
517+
<< " --install Run 'vix install' after update\n"
518+
<< " -h, --help Show this help message\n\n"
491519

492520
<< "Examples\n"
493521
<< " vix update\n"
494-
<< " vix up\n"
495522
<< " vix update gk/jwt\n"
496-
<< " vix up gk/jwt\n"
497523
<< " vix update @gk/jwt\n"
498-
<< " vix up @gk/jwt\n"
499524
<< " vix update gk/jwt@1.0.0\n"
500-
<< " vix up @gk/jwt@1.x.x\n"
501525
<< " vix update gk/jwt gk/pdf --install\n"
502-
<< " vix up --dry-run\n"
503-
<< " vix up @gk/jwt --json\n\n"
526+
<< " vix update --dry-run\n"
527+
<< " vix update @gk/jwt --json\n"
528+
<< " vix update -g @gk/jwt\n\n"
504529

505530
<< "What happens\n"
506-
<< " • Reads dependencies from vix.lock\n"
507-
<< " • Updates all packages, or only selected targets\n"
508-
<< " • Accepts the same package spec syntax as 'vix add'\n"
509-
<< " • Reuses the normal add flow to rewrite vix.lock\n"
510-
<< " • Optionally runs 'vix install' at the end\n\n"
531+
<< " • Project mode:\n"
532+
<< " - Reads dependencies from vix.lock\n"
533+
<< " - Updates selected or all packages\n"
534+
<< " - Rewrites vix.lock using the add flow\n"
535+
<< " - Optionally runs 'vix install'\n"
536+
<< "\n"
537+
<< " • Global mode (-g):\n"
538+
<< " - Resolves the latest version from the registry\n"
539+
<< " - Reinstalls the package globally\n"
540+
<< " - Reuses 'vix install -g' logic\n\n"
511541

512542
<< "Notes\n"
513-
<< " • This may upgrade major versions\n"
514-
<< " • A target must already exist in vix.lock\n";
543+
<< " • May upgrade major versions\n"
544+
<< " • Global update does not use vix.lock\n"
545+
<< " • A project dependency must already exist in vix.lock\n";
515546

516547
return 0;
517548
}

0 commit comments

Comments
 (0)