apigrip 0.5.3 → 0.6.1

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/cli/index.js CHANGED
@@ -2,6 +2,87 @@
2
2
  import yargs from 'yargs';
3
3
  import { hideBin } from 'yargs/helpers';
4
4
 
5
+ const METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'];
6
+
7
+ // Intercept --get-yargs-completions before yargs to provide dynamic completions
8
+ const rawArgs = process.argv.slice(2);
9
+ const compIdx = rawArgs.indexOf('--get-yargs-completions');
10
+ if (compIdx !== -1) {
11
+ const args = rawArgs.slice(compIdx + 1); // [apigrip, cmd, ...rest]
12
+ const cmd = args[1] || '';
13
+ const prevArg = args[args.length - 2] || '';
14
+ const cmdsWithMethod = ['send', 'curl', 'show', 'last'];
15
+ let handled = false;
16
+
17
+ try {
18
+ // --project <TAB> → bookmarked project names
19
+ if (prevArg === '--project') {
20
+ const { loadProjects } = await import('../core/projects-store.js');
21
+ const projects = loadProjects();
22
+ projects.forEach(p => console.log(p.name));
23
+ handled = true;
24
+ }
25
+
26
+ // -e / --env <TAB> → environment names
27
+ if (!handled && (prevArg === '--env' || prevArg === '-e')) {
28
+ const { findProjectForDir } = await import('../core/projects-store.js');
29
+ const match = findProjectForDir(process.cwd());
30
+ if (match) {
31
+ const { loadEnvironments } = await import('../core/env-resolver.js');
32
+ const envData = loadEnvironments(match.path);
33
+ Object.keys(envData.environments || {}).forEach(n => console.log(n));
34
+ }
35
+ handled = true;
36
+ }
37
+
38
+ // --tag <TAB> → tag names from spec
39
+ if (!handled && prevArg === '--tag') {
40
+ const { findProjectForDir } = await import('../core/projects-store.js');
41
+ const { discoverSpec } = await import('../core/spec-discovery.js');
42
+ const { parseSpec, extractEndpoints } = await import('../core/spec-parser.js');
43
+ const match = findProjectForDir(process.cwd());
44
+ const result = match ? await discoverSpec(match.path) : await discoverSpec(process.cwd());
45
+ const specPath = result?.specPath || result;
46
+ if (specPath) {
47
+ const spec = await parseSpec(specPath);
48
+ const endpoints = extractEndpoints(spec);
49
+ const tags = new Set();
50
+ endpoints.forEach(e => (e.tags || []).forEach(t => tags.add(t)));
51
+ tags.forEach(t => console.log(t));
52
+ }
53
+ handled = true;
54
+ }
55
+
56
+ // Commands with <method> <path>: complete methods, then endpoint paths
57
+ if (!handled && cmdsWithMethod.includes(cmd)) {
58
+ const positionals = args.slice(2).filter(a => !a.startsWith('-'));
59
+ if (positionals.length <= 1) {
60
+ METHODS.forEach(m => console.log(m));
61
+ handled = true;
62
+ } else if (positionals.length === 2) {
63
+ const { findProjectForDir } = await import('../core/projects-store.js');
64
+ const { discoverSpec } = await import('../core/spec-discovery.js');
65
+ const { parseSpec, extractEndpoints } = await import('../core/spec-parser.js');
66
+ const match = findProjectForDir(process.cwd());
67
+ const result = match ? await discoverSpec(match.path) : await discoverSpec(process.cwd());
68
+ const specPath = result?.specPath || result;
69
+ if (specPath) {
70
+ const spec = await parseSpec(specPath);
71
+ const endpoints = extractEndpoints(spec);
72
+ const method = positionals[0]?.toUpperCase();
73
+ const filtered = method ? endpoints.filter(e => e.method === method) : endpoints;
74
+ filtered.forEach(e => console.log(e.path));
75
+ }
76
+ handled = true;
77
+ }
78
+ }
79
+ } catch {
80
+ // Silently fall through to yargs defaults
81
+ }
82
+
83
+ if (handled) process.exit(0);
84
+ }
85
+
5
86
  // Register commands
6
87
  const cli = yargs(hideBin(process.argv))
7
88
  .scriptName('apigrip')
@@ -130,17 +211,19 @@ const cli = yargs(hideBin(process.argv))
130
211
  }, (argv) => {
131
212
  const shell = argv.shell || (process.env.SHELL || '').split('/').pop() || 'bash';
132
213
  if (shell === 'zsh') {
133
- console.log(`#compdef apigrip
134
-
135
- _apigrip() {
136
- local completions
214
+ console.log(`_apigrip() {
215
+ local -a completions
137
216
  completions=("\${(@f)$(apigrip --get-yargs-completions "\${words[@]}" 2>/dev/null)}")
138
- compadd -a completions
217
+ local -a stripped
218
+ local c
219
+ for c in "\${completions[@]}"; do
220
+ stripped+=("\${c%%:*}")
221
+ done
222
+ compadd -a stripped
139
223
  }
140
224
 
141
- _apigrip`);
225
+ compdef _apigrip apigrip`);
142
226
  } else {
143
- // Let yargs generate bash completions by re-running with --get-yargs-completions
144
227
  console.log(`###-begin-apigrip-completions-###
145
228
  _apigrip_yargs_completions()
146
229
  {
@@ -1,9 +1,14 @@
1
1
  #compdef apigrip
2
2
 
3
3
  _apigrip() {
4
- local completions
4
+ local -a completions
5
5
  completions=("${(@f)$(apigrip --get-yargs-completions "${words[@]}" 2>/dev/null)}")
6
- compadd -a completions
6
+ local -a stripped
7
+ local c
8
+ for c in "${completions[@]}"; do
9
+ stripped+=("${c%%:*}")
10
+ done
11
+ compadd -a stripped
7
12
  }
8
13
 
9
14
  _apigrip
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apigrip",
3
- "version": "0.5.3",
3
+ "version": "0.6.1",
4
4
  "description": "A spec-first, read-only OpenAPI client for developers",
5
5
  "type": "module",
6
6
  "main": "./lib/index.cjs",
@@ -21,7 +21,8 @@
21
21
  "mcp/",
22
22
  "server/",
23
23
  "client/dist/",
24
- "completions/"
24
+ "completions/",
25
+ "README.md"
25
26
  ],
26
27
  "scripts": {
27
28
  "start": "node cli/index.js serve",