viza 1.8.21 → 1.8.23

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.
@@ -1,6 +1,17 @@
1
+ export function getGlobalOptions() {
2
+ return [
3
+ { flags: "--status", description: "Show status only (no execution)" },
4
+ { flags: "--remove-log", description: "Remove execution logs after completion" },
5
+ { flags: "--self-hosted", description: "Use self-hosted runner (viza-builder)" }
6
+ ];
7
+ }
1
8
  export function registerGlobalOptions(program) {
2
- program
3
- .option("--status", "Show status only (no execution)")
4
- .option("--remove-log", "Remove execution logs after completion", false)
5
- .option("--self-hosted", "Use self-hosted runner (viza-builder)", false);
9
+ for (const opt of getGlobalOptions()) {
10
+ if (opt.defaultValue !== undefined) {
11
+ program.option(opt.flags, opt.description, opt.defaultValue);
12
+ }
13
+ else {
14
+ program.option(opt.flags, opt.description);
15
+ }
16
+ }
6
17
  }
@@ -1,6 +1,6 @@
1
1
  import { Command } from "commander";
2
2
  import { getCliVersion } from "../core/version.js";
3
- import { registerGlobalOptions } from "./options.js";
3
+ import { registerGlobalOptions, getGlobalOptions } from "./options.js";
4
4
  import { loadDescriptors } from "../commands/loadDescriptors.js";
5
5
  import { buildCommandTree } from "../core/commandRegistry.js";
6
6
  import { renderHint } from "../core/renderHint.js";
@@ -9,6 +9,7 @@ import { renderHint } from "../core/renderHint.js";
9
9
  */
10
10
  export async function createProgram() {
11
11
  const program = new Command();
12
+ program.enablePositionalOptions();
12
13
  program
13
14
  .name("viza")
14
15
  .description("Viza Command Line Interface")
@@ -61,8 +62,44 @@ export async function createProgram() {
61
62
  sub.description(node.description || "");
62
63
  parent.addCommand(sub);
63
64
  }
65
+ // Bind global CLI options to every command (Commander does not inherit options)
66
+ for (const opt of getGlobalOptions()) {
67
+ // avoid duplicate flags on the same command
68
+ const already = sub.options?.some((o) => o.flags === opt.flags);
69
+ if (!already) {
70
+ if (opt.defaultValue !== undefined) {
71
+ sub.option(opt.flags, opt.description, opt.defaultValue);
72
+ }
73
+ else {
74
+ sub.option(opt.flags, opt.description);
75
+ }
76
+ }
77
+ }
78
+ // Bind CLI options from descriptor (local options)
79
+ if (node.options?.length) {
80
+ for (const opt of node.options) {
81
+ const already = sub.options?.some((o) => o.flags === opt.flags);
82
+ if (!already) {
83
+ if (opt.defaultValue !== undefined) {
84
+ sub.option(opt.flags, opt.description, opt.defaultValue);
85
+ }
86
+ else {
87
+ sub.option(opt.flags, opt.description);
88
+ }
89
+ }
90
+ }
91
+ }
64
92
  if (node.run) {
65
- sub.action(node.run);
93
+ sub.action(async (...args) => {
94
+ const cmd = args[args.length - 1];
95
+ const selfOpts = typeof cmd?.opts === "function" ? cmd.opts() : {};
96
+ const parentOpts = typeof cmd?.parent?.opts === "function" ? cmd.parent.opts() : {};
97
+ const opts = {
98
+ ...parentOpts,
99
+ ...selfOpts
100
+ };
101
+ await node.run(opts);
102
+ });
66
103
  }
67
104
  if (node.children?.length) {
68
105
  walk(node.children, sub);
@@ -3,6 +3,12 @@ import { loginAwsCommand } from "./aws.js";
3
3
  const descriptor = {
4
4
  command: "login aws",
5
5
  description: "Login to AWS",
6
+ options: [
7
+ {
8
+ flags: "--ssm",
9
+ description: "Login using SSM flow"
10
+ }
11
+ ],
6
12
  run: loginAwsCommand
7
13
  };
8
14
  registerCommand(descriptor);
@@ -0,0 +1,9 @@
1
+ import { registerCommand } from "../../core/commandRegistry.js";
2
+ import { whoamiCommand } from "./index.js";
3
+ const descriptor = {
4
+ command: "whoami",
5
+ description: "Display current user information and team memberships",
6
+ run: whoamiCommand
7
+ };
8
+ registerCommand(descriptor);
9
+ export default descriptor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viza",
3
- "version": "1.8.21",
3
+ "version": "1.8.23",
4
4
  "type": "module",
5
5
  "description": "Viza unified command line interface",
6
6
  "bin": {