@catladder/cli 0.0.0-new-cli-52525b58 → 0.0.0-new-cli-51a5f8b1

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.
Files changed (72) hide show
  1. package/dist/bundles/catenv/index.js +103 -66
  2. package/dist/bundles/cli/index.js +43454 -43373
  3. package/dist/cli/src/adapters/baseContext.d.ts +2 -2
  4. package/dist/cli/src/adapters/baseContext.js +10 -1
  5. package/dist/cli/src/adapters/baseContext.js.map +1 -1
  6. package/dist/cli/src/catenv.js +4 -3
  7. package/dist/cli/src/catenv.js.map +1 -1
  8. package/dist/cli/src/cli.js +3 -3
  9. package/dist/cli/src/cli.js.map +1 -1
  10. package/dist/cli/src/commands/cloudSQL/commandRestoreDb.d.ts +2 -2
  11. package/dist/cli/src/commands/cloudSQL/commandRestoreDb.js +9 -9
  12. package/dist/cli/src/commands/cloudSQL/commandRestoreDb.js.map +1 -1
  13. package/dist/cli/src/commands/project/commandConfigSecrets.d.ts +1 -0
  14. package/dist/cli/src/commands/project/commandConfigSecrets.js +1 -0
  15. package/dist/cli/src/commands/project/commandConfigSecrets.js.map +1 -1
  16. package/dist/cli/src/commands/project/commandSetup.d.ts +1 -0
  17. package/dist/cli/src/commands/project/commandSetup.js +2 -1
  18. package/dist/cli/src/commands/project/commandSetup.js.map +1 -1
  19. package/dist/cli/src/completion.d.ts +2 -2
  20. package/dist/cli/src/completion.js +40 -6
  21. package/dist/cli/src/completion.js.map +1 -1
  22. package/dist/cli/src/core/types.d.ts +7 -2
  23. package/dist/cli/src/core/types.js.map +1 -1
  24. package/dist/pipeline/src/build/index.d.ts +2 -2
  25. package/dist/pipeline/src/build/index.js.map +1 -1
  26. package/dist/pipeline/src/build/node/buildJob.d.ts +3 -3
  27. package/dist/pipeline/src/build/node/buildJob.js +13 -12
  28. package/dist/pipeline/src/build/node/buildJob.js.map +1 -1
  29. package/dist/pipeline/src/build/node/cache.d.ts +3 -3
  30. package/dist/pipeline/src/build/node/cache.js +12 -9
  31. package/dist/pipeline/src/build/node/cache.js.map +1 -1
  32. package/dist/pipeline/src/build/node/index.d.ts +3 -3
  33. package/dist/pipeline/src/build/node/index.js +8 -6
  34. package/dist/pipeline/src/build/node/index.js.map +1 -1
  35. package/dist/pipeline/src/build/node/meteor.d.ts +1 -1
  36. package/dist/pipeline/src/build/node/meteor.js +8 -7
  37. package/dist/pipeline/src/build/node/meteor.js.map +1 -1
  38. package/dist/pipeline/src/build/node/testJob.d.ts +1 -1
  39. package/dist/pipeline/src/build/node/testJob.js +5 -5
  40. package/dist/pipeline/src/build/node/testJob.js.map +1 -1
  41. package/dist/pipeline/src/build/node/yarn.d.ts +2 -2
  42. package/dist/pipeline/src/build/node/yarn.js +10 -8
  43. package/dist/pipeline/src/build/node/yarn.js.map +1 -1
  44. package/dist/pipeline/src/constants.js +1 -1
  45. package/dist/pipeline/src/context/createComponentContext.js +3 -3
  46. package/dist/pipeline/src/context/createComponentContext.js.map +1 -1
  47. package/dist/pipeline/src/context/createWorkspaceContext.js +1 -1
  48. package/dist/pipeline/src/context/createWorkspaceContext.js.map +1 -1
  49. package/dist/pipeline/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js.map +1 -1
  50. package/dist/pipeline/src/deploy/custom/deployJob.d.ts +1 -1
  51. package/dist/pipeline/src/deploy/custom/deployJob.js +2 -2
  52. package/dist/pipeline/src/deploy/custom/deployJob.js.map +1 -1
  53. package/dist/pipeline/src/deploy/index.d.ts +1 -1
  54. package/dist/pipeline/src/pipeline/createAllJobs.js +4 -4
  55. package/dist/pipeline/src/pipeline/createAllJobs.js.map +1 -1
  56. package/dist/pipeline/src/pipeline/createJobsForComponent.d.ts +1 -1
  57. package/dist/pipeline/src/pipeline/createJobsForComponent.js +2 -3
  58. package/dist/pipeline/src/pipeline/createJobsForComponent.js.map +1 -1
  59. package/dist/pipeline/src/pipeline/createJobsForWorkspace.d.ts +1 -1
  60. package/dist/pipeline/src/pipeline/createJobsForWorkspace.js +2 -2
  61. package/dist/pipeline/src/pipeline/createJobsForWorkspace.js.map +1 -1
  62. package/dist/pipeline/src/types/context.d.ts +3 -3
  63. package/dist/tsconfig.tsbuildinfo +1 -1
  64. package/package.json +1 -1
  65. package/src/adapters/baseContext.ts +15 -2
  66. package/src/catenv.ts +15 -8
  67. package/src/cli.ts +7 -2
  68. package/src/commands/cloudSQL/commandRestoreDb.ts +9 -9
  69. package/src/commands/project/commandConfigSecrets.ts +1 -0
  70. package/src/commands/project/commandSetup.ts +6 -1
  71. package/src/completion.ts +43 -6
  72. package/src/core/types.ts +8 -2
package/package.json CHANGED
@@ -53,7 +53,7 @@
53
53
  }
54
54
  ],
55
55
  "license": "MIT",
56
- "version": "0.0.0-new-cli-52525b58",
56
+ "version": "0.0.0-new-cli-51a5f8b1",
57
57
  "scripts": {
58
58
  "lint": "eslint \"src/**/*.ts\"",
59
59
  "lint:fix": "eslint \"src/**/*.ts\" --fix",
@@ -4,6 +4,7 @@ import type {
4
4
  InputDef,
5
5
  InputResultType,
6
6
  InputsSchema,
7
+ OptionalInput,
7
8
  } from "../core/types";
8
9
 
9
10
  /**
@@ -32,7 +33,7 @@ export abstract class BaseContext<TInputs extends InputsSchema>
32
33
 
33
34
  get<K extends keyof TInputs & string>(
34
35
  name: K,
35
- ): Promise<InputResultType<TInputs[K]>> {
36
+ ): Promise<OptionalInput<TInputs[K]>> {
36
37
  if (!this.cache.has(name)) {
37
38
  const spec = this.command.inputs[name];
38
39
  if (!spec) {
@@ -42,7 +43,19 @@ export abstract class BaseContext<TInputs extends InputsSchema>
42
43
  ),
43
44
  );
44
45
  }
45
- this.cache.set(name, this.resolveInput(name, spec));
46
+ // For optional inputs (required: false), catch MissingInputError
47
+ // and return undefined instead of prompting
48
+ if (spec.required === false) {
49
+ this.cache.set(
50
+ name,
51
+ this.resolveInput(name, spec).catch((err) => {
52
+ if (err?.name === "MissingInputError") return undefined;
53
+ throw err;
54
+ }),
55
+ );
56
+ } else {
57
+ this.cache.set(name, this.resolveInput(name, spec));
58
+ }
46
59
  }
47
60
  return this.cache.get(name)!;
48
61
  }
package/src/catenv.ts CHANGED
@@ -11,13 +11,20 @@ program
11
11
  .version(packageInfos.version)
12
12
  .argument("[envComponent]", "env or env:component")
13
13
  .option("-v, --verbose", "verbose output")
14
- .action((envComponent: string | undefined, opts: { verbose?: boolean }) => {
15
- catenv(envComponent ? parseChoice(envComponent) : null, {
16
- verbose: opts.verbose ?? false,
17
- }).then(() => {
18
- // we have to exit manually, because we have some file watches
19
- process.exit();
20
- });
21
- });
14
+ .option("-p, --print-variables", "print variables")
15
+ .action(
16
+ (
17
+ envComponent: string | undefined,
18
+ opts: { verbose?: boolean; printVariables?: boolean },
19
+ ) => {
20
+ catenv(envComponent ? parseChoice(envComponent) : null, {
21
+ verbose: opts.verbose ?? false,
22
+ printVariables: opts.printVariables ?? false,
23
+ }).then(() => {
24
+ // we have to exit manually, because we have some file watches
25
+ process.exit();
26
+ });
27
+ },
28
+ );
22
29
 
23
30
  program.parse();
package/src/cli.ts CHANGED
@@ -188,8 +188,13 @@ const completionCmd = program
188
188
  completionCmd
189
189
  .command("zsh")
190
190
  .description("output zsh completion script")
191
- .action(() => {
192
- const binaryName = process.argv[1].split("/").pop() ?? "catladder";
191
+ .option(
192
+ "--command <cmd>",
193
+ "command used to invoke the CLI (e.g. 'yarn catladder')",
194
+ )
195
+ .action((opts: { command?: string }) => {
196
+ const binaryName =
197
+ opts.command ?? process.argv[1].split("/").pop() ?? "catladder";
193
198
  console.log(generateZshCompletionScript(binaryName));
194
199
  });
195
200
 
@@ -8,7 +8,7 @@ export const commandRestoreDb = defineCommand({
8
8
  description: "restore a db from one source to another target",
9
9
  group: "cloudSQL",
10
10
  inputs: {
11
- sourceInstance: {
11
+ source: {
12
12
  type: "string",
13
13
  message: "Source instance (connection string or 'local')? 🤔 ",
14
14
  },
@@ -24,7 +24,7 @@ export const commandRestoreDb = defineCommand({
24
24
  },
25
25
  sourcePassword: { type: "string", message: "Source Password? 🤔 " },
26
26
  sourceDbName: { type: "string", message: "Source DB name? 🤔 " },
27
- targetInstance: {
27
+ target: {
28
28
  type: "string",
29
29
  message: "Target INSTANCE (connection string or 'local')? 🤔 ",
30
30
  },
@@ -42,19 +42,19 @@ export const commandRestoreDb = defineCommand({
42
42
  targetDbName: { type: "string", message: "Target DB name? 🤔 " },
43
43
  },
44
44
  execute: async (ctx) => {
45
- const sourceInstance = await ctx.get("sourceInstance");
45
+ const source = await ctx.get("source");
46
46
 
47
47
  let sourceProxy: CloudSqlBackgroundProxy;
48
48
  let targetProxy: CloudSqlBackgroundProxy;
49
49
  let sourcePort: number;
50
50
  let targetPort: number;
51
51
 
52
- if (sourceInstance === "local") {
52
+ if (source === "local") {
53
53
  sourcePort = await ctx.get("sourceLocalPort");
54
54
  } else {
55
55
  sourcePort = 54399;
56
56
  sourceProxy = await startCloudSqlProxyInBackground({
57
- instanceName: sourceInstance,
57
+ instanceName: source,
58
58
  localPort: sourcePort,
59
59
  });
60
60
  }
@@ -63,14 +63,14 @@ export const commandRestoreDb = defineCommand({
63
63
  const sourcePassword = await ctx.get("sourcePassword");
64
64
  const sourceDbName = await ctx.get("sourceDbName");
65
65
 
66
- const targetInstance = await ctx.get("targetInstance");
66
+ const target = await ctx.get("target");
67
67
 
68
- if (targetInstance === "local") {
68
+ if (target === "local") {
69
69
  targetPort = await ctx.get("targetLocalPort");
70
70
  } else {
71
71
  targetPort = 54499;
72
72
  targetProxy = await startCloudSqlProxyInBackground({
73
- instanceName: targetInstance,
73
+ instanceName: target,
74
74
  localPort: targetPort,
75
75
  });
76
76
  }
@@ -80,7 +80,7 @@ export const commandRestoreDb = defineCommand({
80
80
  const targetDbName = await ctx.get("targetDbName");
81
81
 
82
82
  const shouldContinue = await ctx.confirm(
83
- `This will drop ${targetInstance}/${targetDbName} and replace it with ${sourceInstance}/${sourceDbName}. Continue? 🤔 `,
83
+ `This will drop ${target}/${targetDbName} and replace it with ${source}/${sourceDbName}. Continue? 🤔 `,
84
84
  );
85
85
  if (!shouldContinue) {
86
86
  return;
@@ -15,6 +15,7 @@ export const commandConfigSecrets = defineCommand({
15
15
  type: "string",
16
16
  message: "environment:component",
17
17
  positional: true,
18
+ required: false,
18
19
  choices: async () => envAndComponents(),
19
20
  },
20
21
  },
@@ -7,7 +7,12 @@ export const commandSetup = defineCommand({
7
7
  "Initializes all environments and creates required resources, service accounts, etc.",
8
8
  group: "project",
9
9
  inputs: {
10
- component: { type: "string", message: "component name", positional: true },
10
+ component: {
11
+ type: "string",
12
+ message: "component name",
13
+ positional: true,
14
+ required: false,
15
+ },
11
16
  },
12
17
  execute: async (ctx) => {
13
18
  const component = await ctx.get("component");
package/src/completion.ts CHANGED
@@ -142,11 +142,15 @@ async function resolveChoicesForCompletion(
142
142
 
143
143
  /**
144
144
  * Generate the zsh completion script.
145
- * The user adds `eval "$(catladder completion zsh)"` to their .zshrc.
145
+ * Supports both direct invocation (`catladder`) and prefixed (`yarn catladder`).
146
146
  */
147
- export function generateZshCompletionScript(binaryName: string): string {
148
- const funcName = binaryName.replace(/-/g, "_");
149
- return `
147
+ export function generateZshCompletionScript(command: string): string {
148
+ const parts = command.split(" ");
149
+ const funcName = command.replace(/[- ]/g, "_");
150
+
151
+ if (parts.length === 1) {
152
+ // Direct binary: catladder
153
+ return `
150
154
  ###-begin-${funcName}-completions-###
151
155
  _${funcName}_completions() {
152
156
  local -a completions
@@ -156,14 +160,47 @@ _${funcName}_completions() {
156
160
  local -a cmd_words=(\${words:1:$((CURRENT-2))})
157
161
 
158
162
  # Call the CLI's __complete command
159
- completions=(\${(f)"$(${binaryName} __complete -- "\${cmd_words[*]}" "$current_word" 2>/dev/null)"})
163
+ completions=(\${(f)"$(${command} __complete -- "\${cmd_words[*]}" "$current_word" 2>/dev/null)"})
164
+
165
+ if [[ \${#completions[@]} -gt 0 ]]; then
166
+ compadd -a completions
167
+ fi
168
+ }
169
+
170
+ compdef _${funcName}_completions ${command}
171
+ ###-end-${funcName}-completions-###
172
+ `.trim();
173
+ }
174
+
175
+ // Multi-word command (e.g., "yarn catladder")
176
+ // Register on the first word (e.g., "yarn") but only activate
177
+ // when the subcommand matches (e.g., "catladder")
178
+ const prefix = parts[0];
179
+ const subcommand = parts.slice(1).join(" ");
180
+ const skipWords = parts.length; // how many words to skip before CLI args
181
+
182
+ return `
183
+ ###-begin-${funcName}-completions-###
184
+ _${funcName}_completions() {
185
+ # Only activate when subcommand is "${subcommand}"
186
+ if [[ $CURRENT -le ${skipWords} ]] || [[ "\${words[2,${skipWords}]}" != "${subcommand}" ]]; then
187
+ return
188
+ fi
189
+
190
+ local -a completions
191
+ local current_word="\${words[$CURRENT]}"
192
+
193
+ # Words after "${command}", excluding the current word being completed
194
+ local -a cmd_words=(\${words:${skipWords}:$((CURRENT-${skipWords}-1))})
195
+
196
+ completions=(\${(f)"$(${command} __complete -- "\${cmd_words[*]}" "$current_word" 2>/dev/null)"})
160
197
 
161
198
  if [[ \${#completions[@]} -gt 0 ]]; then
162
199
  compadd -a completions
163
200
  fi
164
201
  }
165
202
 
166
- compdef _${funcName}_completions ${binaryName}
203
+ compdef _${funcName}_completions ${prefix}
167
204
  ###-end-${funcName}-completions-###
168
205
  `.trim();
169
206
  }
package/src/core/types.ts CHANGED
@@ -103,13 +103,19 @@ export interface CommandContext<TInputs extends InputsSchema> extends IO {
103
103
  * Consume a declared input by name.
104
104
  * - Compile error if `name` is not in TInputs
105
105
  * - Return type matches the input's type (string, number, boolean, string[])
106
- * - Resolution: pre-supplied value > choices function + interactive prompt > default > throw
106
+ * - If `required: false`, returns `undefined` when not provided (no prompt)
107
+ * - Otherwise: pre-supplied value > choices function + interactive prompt > default > throw
107
108
  */
108
109
  get<K extends keyof TInputs & string>(
109
110
  name: K,
110
- ): Promise<InputResultType<TInputs[K]>>;
111
+ ): Promise<OptionalInput<TInputs[K]>>;
111
112
  }
112
113
 
114
+ /** If the input has `required: false`, the result can be undefined */
115
+ export type OptionalInput<T extends InputDef> = T extends { required: false }
116
+ ? InputResultType<T> | undefined
117
+ : InputResultType<T>;
118
+
113
119
  // ─── Command Definition ──────────────────────────────────────────────
114
120
 
115
121
  export interface CommandDef<TInputs extends InputsSchema = InputsSchema> {