MCPcopy Create free account
hub / github.com/acode/cli / EndpointsCreateCommand

Class EndpointsCreateCommand

cli/commands/endpoints/create.js:36–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36class EndpointsCreateCommand extends Command {
37
38 constructor() {
39
40 super('endpoints', 'create');
41
42 }
43
44 help() {
45
46 return {
47 description: 'Creates a new endpoint for a service',
48 args: [
49 'name',
50 'description',
51 'param_1',
52 'param_2',
53 '...',
54 'param_n'
55 ],
56 flags: {
57 'n': 'New directory: Create as a __main__.js file, with the name representing the directory'
58 },
59 vflags: {
60 'new': 'New directory: Create as a __main__.js file, with the name representing the directory'
61 }
62 };
63
64 }
65
66 async run(params, callback) {
67
68 let functionName = params.args[0] || '';
69 let functionDescription = params.args[1] || '';
70 let functionParams = params.args.slice(2) || [];
71 let newDir = !!(params.flags.n || params.vflags['new'] || false);
72
73 if (!fs.existsSync('package.json') && !fs.existsSync('stdlib.json')) {
74 return callback(new Error('Not in valid Autocode directory'));
75 }
76
77 let questions = [];
78
79 functionName || questions.push({
80 name: 'functionName',
81 type: 'input',
82 default: '',
83 message: 'Endpoint name'
84 });
85
86 let promptResult = await inquirer.prompt(questions);
87
88 functionName = functionName || promptResult.functionName;
89
90 if (!functionName.split('/').pop().match(/^[A-Z]/i)) {
91 return callback(new Error(`Invalid function name: ${functionName}`));
92 }
93

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected