Skip to content

Commit d28301f

Browse files
committed
feat: 🎸 add ability to introspect methods
1 parent 4b82e85 commit d28301f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

‎src/methods.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,33 @@ export const defineBuiltinRoutes = <Routes extends ObjectType<any>>(r: ObjectVal
3737
};
3838
},
3939
),
40+
41+
r(
42+
'.methods',
43+
t.Function(t.undef, t.Array(t.str)).options({
44+
title: 'List all CLI methods',
45+
description: 'Returns a list of all methods available in this CLI.',
46+
}),
47+
async (request, ctx) => {
48+
const list = (ctx as CliContext).cli.router.keys();
49+
return list;
50+
},
51+
),
52+
53+
r(
54+
'.method',
55+
t.Function(t.Object(
56+
t.prop('name', t.str)
57+
), t.any).options({
58+
title: 'Show method information',
59+
description: 'Returns JSON Type schema of the method.',
60+
}),
61+
async (request, ctx) => {
62+
const name = request.name;
63+
const method = (ctx as CliContext).cli.router.get(name);
64+
if (!method) throw new Error(`Unknown method "${name}"`);
65+
return method.type.getSchema();
66+
},
67+
),
4068
]);
4169
};

‎src/params/CliParamHelp.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Usage:
4141
${cmd} <method> '<json>'
4242
${cmd} <method> --<type><pointer>=<value>
4343
echo '<json>' | ${cmd} <method>
44+
${cmd} .methods
45+
${cmd} .method --s/name=<method>
4446
4547
Examples:
4648

0 commit comments

Comments
 (0)