@contextual-io/cli 0.2.1 → 0.3.0

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.
package/README.md CHANGED
@@ -20,7 +20,7 @@ $ npm install -g @contextual-io/cli
20
20
  $ ctxl COMMAND
21
21
  running command...
22
22
  $ ctxl (--version)
23
- @contextual-io/cli/0.2.1 linux-x64 node-v25.2.1
23
+ @contextual-io/cli/0.3.0 linux-x64 node-v25.2.1
24
24
  $ ctxl --help [COMMAND]
25
25
  USAGE
26
26
  $ ctxl COMMAND
@@ -29,7 +29,8 @@ USAGE
29
29
  <!-- usagestop -->
30
30
  # Commands
31
31
  <!-- commands -->
32
- * [`ctxl config`](#ctxl-config)
32
+ * [`ctxl autocomplete [SHELL]`](#ctxl-autocomplete-shell)
33
+ * [`ctxl config <COMMAND>`](#ctxl-config-command)
33
34
  * [`ctxl config add CONFIG-ID`](#ctxl-config-add-config-id)
34
35
  * [`ctxl config current`](#ctxl-config-current)
35
36
  * [`ctxl config delete CONFIG-ID`](#ctxl-config-delete-config-id)
@@ -38,7 +39,7 @@ USAGE
38
39
  * [`ctxl config login`](#ctxl-config-login)
39
40
  * [`ctxl config use CONFIG-ID`](#ctxl-config-use-config-id)
40
41
  * [`ctxl help [COMMAND]`](#ctxl-help-command)
41
- * [`ctxl records`](#ctxl-records)
42
+ * [`ctxl records <COMMAND>`](#ctxl-records-command)
42
43
  * [`ctxl records add [URI]`](#ctxl-records-add-uri)
43
44
  * [`ctxl records create [URI]`](#ctxl-records-create-uri)
44
45
  * [`ctxl records delete [URI]`](#ctxl-records-delete-uri)
@@ -48,13 +49,44 @@ USAGE
48
49
  * [`ctxl records query [URI]`](#ctxl-records-query-uri)
49
50
  * [`ctxl records replace [URI]`](#ctxl-records-replace-uri)
50
51
 
51
- ## `ctxl config`
52
+ ## `ctxl autocomplete [SHELL]`
53
+
54
+ Display autocomplete installation instructions.
55
+
56
+ ```
57
+ USAGE
58
+ $ ctxl autocomplete [SHELL] [-r]
59
+
60
+ ARGUMENTS
61
+ [SHELL] (zsh|bash|powershell) Shell type
62
+
63
+ FLAGS
64
+ -r, --refresh-cache Refresh cache (ignores displaying instructions)
65
+
66
+ DESCRIPTION
67
+ Display autocomplete installation instructions.
68
+
69
+ EXAMPLES
70
+ $ ctxl autocomplete
71
+
72
+ $ ctxl autocomplete bash
73
+
74
+ $ ctxl autocomplete zsh
75
+
76
+ $ ctxl autocomplete powershell
77
+
78
+ $ ctxl autocomplete --refresh-cache
79
+ ```
80
+
81
+ _See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v3.2.39/src/commands/autocomplete/index.ts)_
82
+
83
+ ## `ctxl config <COMMAND>`
52
84
 
53
85
  manage configs
54
86
 
55
87
  ```
56
88
  USAGE
57
- $ ctxl config
89
+ $ ctxl config <COMMAND>
58
90
 
59
91
  DESCRIPTION
60
92
  manage configs
@@ -213,13 +245,13 @@ DESCRIPTION
213
245
 
214
246
  _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.36/src/commands/help.ts)_
215
247
 
216
- ## `ctxl records`
248
+ ## `ctxl records <COMMAND>`
217
249
 
218
250
  manage records
219
251
 
220
252
  ```
221
253
  USAGE
222
- $ ctxl records
254
+ $ ctxl records <COMMAND>
223
255
 
224
256
  DESCRIPTION
225
257
  manage records
package/dist/base.d.ts CHANGED
@@ -25,9 +25,10 @@ export declare abstract class BaseConfigCommand<T extends typeof Command> extend
25
25
  protected userConfig: CommandConfig;
26
26
  protected catch(err: Error & {
27
27
  exitCode?: number;
28
- }): Promise<unknown>;
28
+ }): Promise<void>;
29
29
  protected finally(_: Error | undefined): Promise<unknown>;
30
30
  init(): Promise<void>;
31
+ protected showHelp(argv?: string[]): Promise<void>;
31
32
  }
32
33
  export declare abstract class BaseCommand<T extends typeof Command> extends BaseConfigCommand<T> {
33
34
  static baseFlags: {
package/dist/base.js CHANGED
@@ -1,7 +1,10 @@
1
- import { Command, Flags } from "@oclif/core";
1
+ import { Command, Flags, loadHelpClass } from "@oclif/core";
2
+ // eslint-disable-next-line unicorn/import-style
3
+ import { chalkStderr } from "chalk";
2
4
  import fetch from "cross-fetch";
3
5
  import fs from "node:fs";
4
6
  import path from "node:path";
7
+ import { z, ZodError } from "zod";
5
8
  import { HttpError } from "./models/errors.js";
6
9
  import { UserConfig } from "./models/user-config.js";
7
10
  import { rehydrateToken } from "./utils/auth.js";
@@ -97,9 +100,23 @@ export class BaseConfigCommand extends Command {
97
100
  flags;
98
101
  userConfig;
99
102
  async catch(err) {
100
- // add any custom logic to handle errors from the command
101
- // or simply return the parent class error handling
102
- return super.catch(err);
103
+ const exitCode = err.exitCode ?? process.exitCode ?? 1;
104
+ if (this.jsonEnabled()) {
105
+ this.logJson(this.toErrorJson(err));
106
+ }
107
+ else {
108
+ if (!err.message)
109
+ throw err;
110
+ let { message } = err;
111
+ if (err instanceof ZodError) {
112
+ const flattened = z.flattenError(err);
113
+ message = flattened.formErrors.join("\n");
114
+ }
115
+ this.logToStderr(chalkStderr.red(chalkStderr.bold(" Error: ") + message));
116
+ this.logToStderr();
117
+ await this.showHelp();
118
+ }
119
+ this.exit(exitCode);
103
120
  }
104
121
  async finally(_) {
105
122
  // called after run and catch regardless of whether or not the command errored
@@ -118,6 +135,13 @@ export class BaseConfigCommand extends Command {
118
135
  this.args = args;
119
136
  this.userConfig = new CommandConfig(this.config.configDir);
120
137
  }
138
+ async showHelp(argv) {
139
+ const toShow = argv ?? this.id ? [this.id] : undefined;
140
+ if (!toShow)
141
+ return;
142
+ const help = new (await loadHelpClass(this.config))(this.config);
143
+ await help.showHelp(toShow);
144
+ }
121
145
  }
122
146
  export class BaseCommand extends BaseConfigCommand {
123
147
  // define flags that can be inherited by any command that extends BaseCommand
@@ -4,5 +4,6 @@ export default class Config extends BaseConfigCommand<typeof Config> {
4
4
  static description: string;
5
5
  static examples: never[];
6
6
  static flags: {};
7
+ static usage: string[];
7
8
  run(): Promise<void>;
8
9
  }
@@ -1,11 +1,13 @@
1
- import { loadHelpClass } from "@oclif/core";
2
1
  import { BaseConfigCommand } from "../../base.js";
3
2
  export default class Config extends BaseConfigCommand {
4
3
  static args = {};
5
4
  static description = "manage configs";
6
5
  static examples = [];
7
6
  static flags = {};
7
+ static usage = [
8
+ "<%= command.id %> <COMMAND>",
9
+ ];
8
10
  async run() {
9
- await new (await loadHelpClass(this.config))(this.config).showHelp([Config.id]);
11
+ await this.showHelp();
10
12
  }
11
13
  }
@@ -4,5 +4,6 @@ export default class Records extends BaseConfigCommand<typeof Records> {
4
4
  static description: string;
5
5
  static examples: never[];
6
6
  static flags: {};
7
+ static usage: string[];
7
8
  run(): Promise<void>;
8
9
  }
@@ -1,11 +1,13 @@
1
- import { loadHelpClass } from "@oclif/core";
2
1
  import { BaseConfigCommand } from "../../base.js";
3
2
  export default class Records extends BaseConfigCommand {
4
3
  static args = {};
5
4
  static description = "manage records";
6
5
  static examples = [];
7
6
  static flags = {};
7
+ static usage = [
8
+ "<%= command.id %> <COMMAND>",
9
+ ];
8
10
  async run() {
9
- await new (await loadHelpClass(this.config))(this.config).showHelp([Records.id]);
11
+ await this.showHelp();
10
12
  }
11
13
  }
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- export const Uri = z.string().regex(/^native-object:[a-z0-9-]+(\/.+)?/);
2
+ export const Uri = z.string().regex(/^native-object:[a-z0-9-]+(\/.+)?/, { error: "URI must match one of the following formats: 'native-object:<type-id>' or 'native-object:<type-id>/<instance-id>'" });
3
3
  export const parseUri = (uri) => {
4
4
  const parsed = Uri.parse(uri);
5
5
  const [type, id] = parsed.replace(/^native-object:/, "").split("/");
@@ -166,6 +166,9 @@
166
166
  "pluginName": "@contextual-io/cli",
167
167
  "pluginType": "core",
168
168
  "strict": true,
169
+ "usage": [
170
+ "<%= command.id %> <COMMAND>"
171
+ ],
169
172
  "enableJsonFlag": false,
170
173
  "isESM": true,
171
174
  "relativePath": [
@@ -452,6 +455,9 @@
452
455
  "pluginName": "@contextual-io/cli",
453
456
  "pluginType": "core",
454
457
  "strict": true,
458
+ "usage": [
459
+ "<%= command.id %> <COMMAND>"
460
+ ],
455
461
  "enableJsonFlag": false,
456
462
  "isESM": true,
457
463
  "relativePath": [
@@ -753,5 +759,5 @@
753
759
  ]
754
760
  }
755
761
  },
756
- "version": "0.2.1"
762
+ "version": "0.3.0"
757
763
  }
package/package.json CHANGED
@@ -1,14 +1,16 @@
1
1
  {
2
2
  "name": "@contextual-io/cli",
3
3
  "description": "Contextual CLI",
4
- "version": "0.2.1",
4
+ "version": "0.3.0",
5
5
  "author": "Nasser Oloumi",
6
6
  "bin": {
7
7
  "ctxl": "./bin/run.js"
8
8
  },
9
9
  "dependencies": {
10
10
  "@oclif/core": "^4",
11
+ "@oclif/plugin-autocomplete": "^3.2.39",
11
12
  "@oclif/plugin-help": "^6",
13
+ "@oclif/plugin-not-found": "^3.2.73",
12
14
  "@oclif/table": "^0.5.1",
13
15
  "chalk": "^5.6.2",
14
16
  "cross-fetch": "^4.1.0",
@@ -56,7 +58,9 @@
56
58
  "dirname": "ctxl",
57
59
  "commands": "./dist/commands",
58
60
  "plugins": [
59
- "@oclif/plugin-help"
61
+ "@oclif/plugin-help",
62
+ "@oclif/plugin-not-found",
63
+ "@oclif/plugin-autocomplete"
60
64
  ],
61
65
  "topicSeparator": " ",
62
66
  "topics": {