1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | 'use strict';
|
17 |
|
18 | const Logger = require('@accordproject/concerto-core').Logger;
|
19 | const Commands = require('./lib/commands');
|
20 |
|
21 | require('yargs')
|
22 | .scriptName('cicero')
|
23 | .usage('$0 <cmd> [args]')
|
24 | .demandCommand(1, '# Please specify a command')
|
25 | .recommendCommands()
|
26 | .strict()
|
27 | .command('parse', 'parse a contract text', (yargs) => {
|
28 | yargs.option('template', {
|
29 | describe: 'path to the template',
|
30 | type: 'string'
|
31 | });
|
32 | yargs.option('sample', {
|
33 | describe: 'path to the contract text',
|
34 | type: 'string'
|
35 | });
|
36 | yargs.option('output', {
|
37 | describe: 'path to the output file',
|
38 | type: 'string'
|
39 | });
|
40 | yargs.option('currentTime', {
|
41 | describe: 'set current time',
|
42 | type: 'string',
|
43 | default: null
|
44 | });
|
45 | yargs.option('warnings', {
|
46 | describe: 'print warnings',
|
47 | type: 'boolean',
|
48 | default: false
|
49 | });
|
50 | }, (argv) => {
|
51 | if (argv.verbose) {
|
52 | Logger.info(`parse sample ${argv.sample} for template ${argv.template}`);
|
53 | }
|
54 |
|
55 | try {
|
56 | argv = Commands.validateParseArgs(argv);
|
57 | const options = {
|
58 | warnings: argv.warnings,
|
59 | };
|
60 | return Commands.parse(argv.template, argv.sample, argv.output, argv.currentTime, options)
|
61 | .then((result) => {
|
62 | if(result) {Logger.info(JSON.stringify(result));}
|
63 | })
|
64 | .catch((err) => {
|
65 | Logger.error(err.message);
|
66 | });
|
67 | } catch (err){
|
68 | Logger.error(err.message);
|
69 | return;
|
70 | }
|
71 | })
|
72 | .command('draft', 'create contract text from data', (yargs) => {
|
73 | yargs.option('template', {
|
74 | describe: 'path to the template',
|
75 | type: 'string'
|
76 | });
|
77 | yargs.option('data', {
|
78 | describe: 'path to the contract data',
|
79 | type: 'string'
|
80 | });
|
81 | yargs.option('output', {
|
82 | describe: 'path to the output file',
|
83 | type: 'string'
|
84 | });
|
85 | yargs.option('currentTime', {
|
86 | describe: 'set current time',
|
87 | type: 'string',
|
88 | default: null
|
89 | });
|
90 | yargs.option('wrapVariables', {
|
91 | describe: 'wrap variables as XML tags',
|
92 | type: 'boolean',
|
93 | default: false
|
94 | });
|
95 | yargs.option('format', {
|
96 | describe: 'target format',
|
97 | type: 'string'
|
98 | });
|
99 | yargs.option('unquoteVariables', {
|
100 | describe: 'remove variables quoting',
|
101 | type: 'boolean',
|
102 | default: false
|
103 | });
|
104 | yargs.option('warnings', {
|
105 | describe: 'print warnings',
|
106 | type: 'boolean',
|
107 | default: false
|
108 | });
|
109 | }, (argv) => {
|
110 | if (argv.verbose) {
|
111 | Logger.info(`create contract from data ${argv.data} for template ${argv.template}`);
|
112 | }
|
113 |
|
114 | try {
|
115 | argv = Commands.validateDraftArgs(argv);
|
116 | const options = {
|
117 | wrapVariables: argv.wrapVariables,
|
118 | unquoteVariables: argv.unquoteVariables,
|
119 | warnings: argv.warnings,
|
120 | format: argv.format,
|
121 | };
|
122 | return Commands.draft(argv.template, argv.data, argv.output, argv.currentTime, options)
|
123 | .then((result) => {
|
124 | if(result) {Logger.info(result);}
|
125 | })
|
126 | .catch((err) => {
|
127 | Logger.error(err.message);
|
128 | });
|
129 | } catch (err){
|
130 | Logger.error(err.message);
|
131 | return;
|
132 | }
|
133 | })
|
134 | .command('normalize', 'normalize markdown (parse & redraft)', (yargs) => {
|
135 | yargs.option('template', {
|
136 | describe: 'path to the template',
|
137 | type: 'string'
|
138 | });
|
139 | yargs.option('sample', {
|
140 | describe: 'path to the contract text',
|
141 | type: 'string'
|
142 | });
|
143 | yargs.option('overwrite', {
|
144 | describe: 'overwrite the contract text',
|
145 | type: 'boolean',
|
146 | default: false
|
147 | });
|
148 | yargs.option('output', {
|
149 | describe: 'path to the output file',
|
150 | type: 'string'
|
151 | });
|
152 | yargs.option('currentTime', {
|
153 | describe: 'set current time',
|
154 | type: 'string',
|
155 | default: null
|
156 | });
|
157 | yargs.option('warnings', {
|
158 | describe: 'print warnings',
|
159 | type: 'boolean',
|
160 | default: false
|
161 | });
|
162 | yargs.option('wrapVariables', {
|
163 | describe: 'wrap variables as XML tags',
|
164 | type: 'boolean',
|
165 | default: false
|
166 | });
|
167 | yargs.option('format', {
|
168 | describe: 'target format',
|
169 | type: 'string'
|
170 | });
|
171 | yargs.option('unquoteVariables', {
|
172 | describe: 'remove variables quoting',
|
173 | type: 'boolean',
|
174 | default: false
|
175 | });
|
176 | }, (argv) => {
|
177 | if (argv.verbose) {
|
178 | Logger.info(`parse sample and re-create sample ${argv.sample} for template ${argv.template}`);
|
179 | }
|
180 |
|
181 | try {
|
182 | argv = Commands.validateNormalizeArgs(argv);
|
183 | const options = {
|
184 | wrapVariables: argv.wrapVariables,
|
185 | unquoteVariables: argv.unquoteVariables,
|
186 | warnings: argv.warnings,
|
187 | format: argv.format,
|
188 | };
|
189 | return Commands.normalize(argv.template, argv.sample, argv.overwrite, argv.output, argv.currentTime, options)
|
190 | .then((result) => {
|
191 | if(result) {Logger.info(result);}
|
192 | })
|
193 | .catch((err) => {
|
194 | Logger.error(err.message);
|
195 | });
|
196 | } catch (err){
|
197 | Logger.error(err.message);
|
198 | return;
|
199 | }
|
200 | })
|
201 | .command('trigger', 'send a request to the contract', (yargs) => {
|
202 | yargs.option('template', {
|
203 | describe: 'path to the template',
|
204 | type: 'string'
|
205 | });
|
206 | yargs.option('sample', {
|
207 | describe: 'path to the contract text',
|
208 | type: 'string'
|
209 | });
|
210 | yargs.option('request', {
|
211 | describe: 'path to the JSON request',
|
212 | type: 'string'
|
213 | }).array('request');
|
214 | yargs.option('state', {
|
215 | describe: 'path to the JSON state',
|
216 | type: 'string'
|
217 | });
|
218 | yargs.option('currentTime', {
|
219 | describe: 'set current time',
|
220 | type: 'string',
|
221 | default: null
|
222 | });
|
223 | yargs.option('warnings', {
|
224 | describe: 'print warnings',
|
225 | type: 'boolean',
|
226 | default: false
|
227 | });
|
228 | }, (argv) => {
|
229 |
|
230 | try {
|
231 | argv = Commands.validateTriggerArgs(argv);
|
232 | const options = {
|
233 | warnings: argv.warnings,
|
234 | };
|
235 | return Commands.trigger(argv.template, argv.sample, argv.request, argv.state, argv.currentTime, options)
|
236 | .then((result) => {
|
237 | if(result) {Logger.info(JSON.stringify(result));}
|
238 | })
|
239 | .catch((err) => {
|
240 | Logger.error(err.message);
|
241 | });
|
242 | } catch (err){
|
243 | Logger.error(err.message);
|
244 | }
|
245 | })
|
246 | .command('invoke', 'invoke a clause of the contract', (yargs) => {
|
247 | yargs.option('template', {
|
248 | describe: 'path to the template',
|
249 | type: 'string'
|
250 | });
|
251 | yargs.option('sample', {
|
252 | describe: 'path to the contract text',
|
253 | type: 'string'
|
254 | });
|
255 | yargs.option('clauseName', {
|
256 | describe: 'the name of the clause to invoke',
|
257 | type: 'string'
|
258 | });
|
259 | yargs.option('params', {
|
260 | describe: 'path to the parameters',
|
261 | type: 'string'
|
262 | });
|
263 | yargs.option('state', {
|
264 | describe: 'path to the JSON state',
|
265 | type: 'string'
|
266 | });
|
267 | yargs.option('currentTime', {
|
268 | describe: 'set current time',
|
269 | type: 'string',
|
270 | default: null
|
271 | });
|
272 | yargs.option('warnings', {
|
273 | describe: 'print warnings',
|
274 | type: 'boolean',
|
275 | default: false
|
276 | });
|
277 | }, (argv) => {
|
278 | try {
|
279 | argv = Commands.validateInvokeArgs(argv);
|
280 | const options = {
|
281 | warnings: argv.warnings,
|
282 | };
|
283 | return Commands.invoke(argv.template, argv.sample, argv.clauseName, argv.params, argv.state, argv.currentTime, options)
|
284 | .then((result) => {
|
285 | if(result) {Logger.info(JSON.stringify(result));}
|
286 | })
|
287 | .catch((err) => {
|
288 | Logger.error(err.message);
|
289 | });
|
290 | } catch (err){
|
291 | Logger.error(err.message);
|
292 | }
|
293 | })
|
294 | .command('initialize', 'initialize a clause', (yargs) => {
|
295 | yargs.option('template', {
|
296 | describe: 'path to the template',
|
297 | type: 'string'
|
298 | });
|
299 | yargs.option('sample', {
|
300 | describe: 'path to the contract text',
|
301 | type: 'string'
|
302 | });
|
303 | yargs.option('currentTime', {
|
304 | describe: 'initialize with this current time',
|
305 | type: 'string',
|
306 | default: null
|
307 | });
|
308 | yargs.option('warnings', {
|
309 | describe: 'print warnings',
|
310 | type: 'boolean',
|
311 | default: false
|
312 | });
|
313 | }, (argv) => {
|
314 |
|
315 | try {
|
316 | argv = Commands.validateInitializeArgs(argv);
|
317 | const options = {
|
318 | warnings: argv.warnings,
|
319 | };
|
320 | return Commands.initialize(argv.template, argv.sample, argv.currentTime, options)
|
321 | .then((result) => {
|
322 | if(result) {Logger.info(JSON.stringify(result));}
|
323 | })
|
324 | .catch((err) => {
|
325 | Logger.error(err.message);
|
326 | });
|
327 | } catch (err){
|
328 | Logger.error(err.message);
|
329 | }
|
330 | })
|
331 | .command('archive', 'create a template archive', (yargs) => {
|
332 | yargs.option('template', {
|
333 | describe: 'path to the template',
|
334 | type: 'string'
|
335 | });
|
336 | yargs.option('target', {
|
337 | describe: 'the target language of the archive',
|
338 | type: 'string',
|
339 | default: 'ergo'
|
340 | });
|
341 | yargs.option('output', {
|
342 | describe: 'file name for new archive',
|
343 | type: 'string',
|
344 | default: null
|
345 | });
|
346 | yargs.option('warnings', {
|
347 | describe: 'print warnings',
|
348 | type: 'boolean',
|
349 | default: false
|
350 | });
|
351 | }, (argv) => {
|
352 | if (argv.verbose) {
|
353 | Logger.info(`create an archive for ${argv.template}`);
|
354 | }
|
355 |
|
356 | try {
|
357 | argv = Commands.validateArchiveArgs(argv);
|
358 | const options = {
|
359 | warnings: argv.warnings,
|
360 | };
|
361 | return Commands.archive(argv.template, argv.target, argv.output, options)
|
362 | .catch((err) => {
|
363 | Logger.error(err.message);
|
364 | });
|
365 | } catch (err){
|
366 | Logger.error(err.message);
|
367 | return;
|
368 | }
|
369 | })
|
370 | .command('compile', 'generate code for a target platform', (yargs) => {
|
371 | yargs.option('template', {
|
372 | describe: 'path to the template',
|
373 | type: 'string'
|
374 | });
|
375 | yargs.option('target', {
|
376 | describe: 'target of the code generation',
|
377 | type: 'string',
|
378 | default: 'JSONSchema'
|
379 | });
|
380 | yargs.option('output', {
|
381 | describe: 'path to the output directory',
|
382 | type: 'string',
|
383 | default: './output/'
|
384 | });
|
385 | yargs.option('warnings', {
|
386 | describe: 'print warnings',
|
387 | type: 'boolean',
|
388 | default: false
|
389 | });
|
390 | }, (argv) => {
|
391 | if (argv.verbose) {
|
392 | Logger.info(`compile template ${argv.template} for target ${argv.target}`);
|
393 | }
|
394 |
|
395 | try {
|
396 | argv = Commands.validateTriggerArgs(argv);
|
397 | const options = {
|
398 | warnings: argv.warnings,
|
399 | };
|
400 | return Commands.compile(argv.template, argv.target, argv.output, options)
|
401 | .then((result) => {
|
402 | Logger.info('Completed.');
|
403 | })
|
404 | .catch((err) => {
|
405 | Logger.error(err.message + ' ' + JSON.stringify(err));
|
406 | });
|
407 | } catch (err){
|
408 | Logger.error(err.message);
|
409 | return;
|
410 | }
|
411 | })
|
412 | .command('get', 'save local copies of external dependencies', (yargs) => {
|
413 | yargs.option('template', {
|
414 | describe: 'path to the template',
|
415 | type: 'string'
|
416 | });
|
417 | yargs.option('output', {
|
418 | describe: 'output directory path',
|
419 | type: 'string'
|
420 | });
|
421 | }, (argv) => {
|
422 | if (argv.verbose) {
|
423 | Logger.info(`saving external models into directory: ${argv.output}`);
|
424 | }
|
425 |
|
426 | try {
|
427 | argv = Commands.validateGetArgs(argv);
|
428 | return Commands.get(argv.template, argv.output)
|
429 | .then((result) => {
|
430 | Logger.info(result);
|
431 | })
|
432 | .catch((err) => {
|
433 | Logger.error(err.message);
|
434 | });
|
435 | } catch (err){
|
436 | Logger.error(err.message);
|
437 | return;
|
438 | }
|
439 | })
|
440 | .option('verbose', {
|
441 | alias: 'v',
|
442 | default: false
|
443 | })
|
444 | .help()
|
445 | .argv; |
\ | No newline at end of file |