@@ -21,12 +21,15 @@ const Commands = require('./lib/Commands');
2121require ( '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