@invizi/cli 0.1.2 → 0.1.4

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 (2) hide show
  1. package/dist/invizi.js +16 -27
  2. package/package.json +1 -1
package/dist/invizi.js CHANGED
@@ -20,6 +20,9 @@ Run invizi --help after login for the remote command list.
20
20
  `);
21
21
  }
22
22
  async function executeProtocol(args, authHeader) {
23
+ // Handle --json flag: output structured result instead of text
24
+ const jsonMode = args.includes('--json');
25
+ const serverArgs = args.filter(a => a !== '--json');
23
26
  const apiUrl = getApiUrl();
24
27
  const res = await fetch(`${apiUrl}/cli/v1/execute`, {
25
28
  method: 'POST',
@@ -27,7 +30,7 @@ async function executeProtocol(args, authHeader) {
27
30
  'Content-Type': 'application/json',
28
31
  Authorization: authHeader,
29
32
  },
30
- body: JSON.stringify({ argv: args }),
33
+ body: JSON.stringify({ argv: serverArgs }),
31
34
  });
32
35
  if (res.status === 404) {
33
36
  return { handled: false, exitCode: 0 };
@@ -41,10 +44,14 @@ async function executeProtocol(args, authHeader) {
41
44
  console.error('Invalid protocol response from server');
42
45
  return { handled: true, exitCode: 1 };
43
46
  }
44
- if (typeof output.text === 'string' && output.text.length > 0) {
47
+ // --json flag: output structured result instead of text
48
+ if (jsonMode && output.result !== undefined) {
49
+ process.stdout.write(`${JSON.stringify(output.result, null, 2)}\n`);
50
+ }
51
+ else if (typeof output.text === 'string' && output.text.length > 0) {
45
52
  process.stdout.write(`${output.text}${output.text.endsWith('\n') ? '' : '\n'}`);
46
53
  }
47
- if (!output.text && output.result !== undefined) {
54
+ else if (output.result !== undefined) {
48
55
  process.stdout.write(`${JSON.stringify(output.result, null, 2)}\n`);
49
56
  }
50
57
  if (output.error?.message) {
@@ -96,34 +103,16 @@ async function executeRemote(args, options = {}) {
96
103
  export async function main(rawArgs = process.argv.slice(2)) {
97
104
  const args = rawArgs;
98
105
  const command = args[0];
99
- if (!command) {
106
+ if (!command || command === '--help' || command === '-h') {
100
107
  showLocalHelp();
101
- return 0;
102
- }
103
- if (command === '--help' || command === '-h') {
104
108
  const header = await getAuthorizationHeader();
105
- if (!header) {
106
- showLocalHelp();
107
- return 0;
108
- }
109
- try {
110
- await showRemoteHelp(header);
111
- return 0;
112
- }
113
- catch {
109
+ if (header) {
114
110
  try {
115
- const code = await executeRemote(['--help'], { quietNetworkError: true });
116
- if (code !== 0) {
117
- showLocalHelp();
118
- return 0;
119
- }
120
- return code;
121
- }
122
- catch {
123
- showLocalHelp();
124
- return 0;
111
+ await showRemoteHelp(header);
125
112
  }
113
+ catch { /* server unreachable — just show local */ }
126
114
  }
115
+ return 0;
127
116
  }
128
117
  if (command === 'auth')
129
118
  return auth(args.slice(1));
@@ -136,7 +125,7 @@ export async function main(rawArgs = process.argv.slice(2)) {
136
125
  console.log(`\nConfig path: ${getConfigPath()}`);
137
126
  return 0;
138
127
  }
139
- if (command === 'version') {
128
+ if (command === 'version' || command === '--version' || command === '-v') {
140
129
  const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
141
130
  console.log(`invizi-cli v${pkg.version || 'unknown'}`);
142
131
  return 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@invizi/cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Invizi CLI",
5
5
  "type": "module",
6
6
  "bin": {