Skip to content

Commit a3a31cc

Browse files
committed
feature(CLI) Align command line with other Accord Project CLIs
Signed-off-by: Jerome Simeon <[email protected]>
1 parent 655a285 commit a3a31cc

File tree

4 files changed

+413
-58
lines changed

4 files changed

+413
-58
lines changed

packages/markdown-cli/README.md

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,37 @@ npm install -g @accordproject/markdown-cli
1010

1111
## Usage
1212

13+
The command-line is called `markus` and offers the following commands:
14+
15+
```
16+
markus <cmd> [args]
17+
18+
Commands:
19+
markus parse parse and transform sample markdown
20+
markus draft create markdown text from data
21+
markus redraft parse a sample markdown and re-create it
22+
23+
Options:
24+
--version Show version number [boolean]
25+
--verbose, -v [default: false]
26+
--help Show help [boolean]
27+
```
28+
29+
### Parse from Markdown
30+
31+
The `parse` command lets you parse markdown and create a document object model from it.
32+
1333
```
1434
markus parse
1535
1636
parse and transform sample markdown
1737
1838
Options:
1939
--version Show version number [boolean]
20-
--verbose, -v [default: false]
40+
--verbose, -v verbose output [boolean] [default: false]
2141
--help Show help [boolean]
22-
--sample path to the clause text [string]
23-
--out path to the output file [string]
42+
--sample path to the markdown text [string]
43+
--output path to the output file [string]
2444
--roundtrip roundtrip [boolean] [default: false]
2545
--cicero further transform to CiceroMark [boolean] [default: false]
2646
--slate further transform to Slate DOM [boolean] [default: false]
@@ -29,6 +49,48 @@ Options:
2949
--noIndex do not index ordered lists [boolean] [default: false]
3050
```
3151

52+
### Generate text from data
53+
54+
The `draft` command lets you take a document object model and generate markdown text from it.
55+
56+
```
57+
markus draft
58+
59+
create markdown text from data
60+
61+
Options:
62+
--version Show version number [boolean]
63+
--verbose, -v verbose output [boolean] [default: false]
64+
--help Show help [boolean]
65+
--data path to the data [string]
66+
--output path to the output file [string]
67+
--cicero further transform to CiceroMark [boolean] [default: false]
68+
--slate further transform to Slate DOM [boolean] [default: false]
69+
--noWrap do not wrap variables as XML tags [boolean] [default: false]
70+
--noIndex do not index ordered lists [boolean] [default: false]
71+
```
72+
73+
### Re-generate text
74+
75+
The `redraft` command lets you parse markdown and re-generate it after parsing.
76+
77+
```
78+
markus redraft
79+
80+
parse a sample markdown and re-create it
81+
82+
Options:
83+
--version Show version number [boolean]
84+
--verbose, -v verbose output [boolean] [default: false]
85+
--help Show help [boolean]
86+
--sample path to the markdown text [string]
87+
--output path to the output file [string]
88+
--cicero further transform to CiceroMark [boolean] [default: false]
89+
--slate further transform to Slate DOM [boolean] [default: false]
90+
--noWrap do not wrap variables as XML tags [boolean] [default: false]
91+
--noIndex do not index ordered lists [boolean] [default: false]
92+
```
93+
3294
## License <a name="license"></a>
3395
Accord Project source code files are made available under the Apache License, Version 2.0 (Apache-2.0), located in the LICENSE file. Accord Project documentation files are made available under the Creative Commons Attribution 4.0 International License (CC-BY-4.0), available at http://creativecommons.org/licenses/by/4.0/.
3496

packages/markdown-cli/index.js

Lines changed: 124 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ const Commands = require('./lib/Commands');
2121
require('yargs')
2222
.scriptName('markus')
2323
.usage('$0 <cmd> [args]')
24+
.demandCommand(1, '# Please specify a command')
25+
.recommendCommands()
26+
.strict()
2427
.command('parse', 'parse and transform sample markdown', (yargs) => {
2528
yargs.option('sample', {
26-
describe: 'path to the clause text',
29+
describe: 'path to the markdown text',
2730
type: 'string'
2831
});
29-
yargs.option('out', {
32+
yargs.option('output', {
3033
describe: 'path to the output file',
3134
type: 'string'
3235
});
@@ -80,7 +83,125 @@ require('yargs')
8083
options.noWrap = argv.noWrap;
8184
options.noIndex = argv.noIndex;
8285
options.verbose = argv.verbose;
83-
return Commands.parse(argv.sample, argv.out, options)
86+
return Commands.parse(argv.sample, argv.output, options)
87+
.then((result) => {
88+
if(result) {Logger.info('\n'+result);}
89+
})
90+
.catch((err) => {
91+
Logger.error(err.message);
92+
});
93+
} catch (err){
94+
Logger.error(err.message);
95+
return;
96+
}
97+
})
98+
.command('draft', 'create markdown text from data', (yargs) => {
99+
yargs.option('data', {
100+
describe: 'path to the data',
101+
type: 'string'
102+
});
103+
yargs.option('output', {
104+
describe: 'path to the output file',
105+
type: 'string'
106+
});
107+
yargs.option('cicero', {
108+
describe: 'further transform to CiceroMark',
109+
type: 'boolean',
110+
default: false
111+
});
112+
yargs.option('slate', {
113+
describe: 'further transform to Slate DOM',
114+
type: 'boolean',
115+
default: false
116+
});
117+
yargs.option('noWrap', {
118+
describe: 'do not wrap variables as XML tags',
119+
type: 'boolean',
120+
default: false
121+
});
122+
yargs.option('noIndex', {
123+
describe: 'do not index ordered lists',
124+
type: 'boolean',
125+
default: false
126+
});
127+
yargs.option('verbose', {
128+
describe: 'verbose output',
129+
type: 'boolean',
130+
default: false
131+
});
132+
}, (argv) => {
133+
if (argv.verbose) {
134+
Logger.info(`draft sample markdown from ${argv.data}`);
135+
}
136+
137+
try {
138+
argv = Commands.validateDraftArgs(argv);
139+
const options = {};
140+
options.cicero = argv.cicero;
141+
options.slate = argv.slate;
142+
options.noWrap = argv.noWrap;
143+
options.noIndex = argv.noIndex;
144+
options.verbose = argv.verbose;
145+
return Commands.draft(argv.data, argv.output, options)
146+
.then((result) => {
147+
if(result) {Logger.info('\n'+result);}
148+
})
149+
.catch((err) => {
150+
Logger.error(err.message);
151+
});
152+
} catch (err){
153+
Logger.error(err.message);
154+
return;
155+
}
156+
})
157+
.command('redraft', 'parse a sample markdown and re-create it', (yargs) => {
158+
yargs.option('sample', {
159+
describe: 'path to the markdown text',
160+
type: 'string'
161+
});
162+
yargs.option('output', {
163+
describe: 'path to the output file',
164+
type: 'string'
165+
});
166+
yargs.option('cicero', {
167+
describe: 'further transform to CiceroMark',
168+
type: 'boolean',
169+
default: false
170+
});
171+
yargs.option('slate', {
172+
describe: 'further transform to Slate DOM',
173+
type: 'boolean',
174+
default: false
175+
});
176+
yargs.option('noWrap', {
177+
describe: 'do not wrap variables as XML tags',
178+
type: 'boolean',
179+
default: false
180+
});
181+
yargs.option('noIndex', {
182+
describe: 'do not index ordered lists',
183+
type: 'boolean',
184+
default: false
185+
});
186+
yargs.option('verbose', {
187+
describe: 'verbose output',
188+
type: 'boolean',
189+
default: false
190+
});
191+
}, (argv) => {
192+
if (argv.verbose) {
193+
Logger.info(`parse and re-create sample ${argv.sample} markdown`);
194+
}
195+
196+
try {
197+
argv = Commands.validateRedraftArgs(argv);
198+
const options = {};
199+
options.cicero = argv.cicero;
200+
options.slate = argv.slate;
201+
options.noWrap = argv.noWrap;
202+
options.noIndex = argv.noIndex;
203+
options.verbose = argv.verbose;
204+
return Commands.redraft(argv.sample, argv.output, options)
84205
.then((result) => {
85206
if(result) {Logger.info('\n'+result);}
86207
})

0 commit comments

Comments
 (0)