1 |
|
2 | # ArguMints
|
3 | ![argumints!](argumints_logo.jpg)
|
4 |
|
5 |
|
6 | [GitHub](http://github.com/decoded4620/argumints)
|
7 |
|
8 | ![travis!](https://travis-ci.org/decoded4620/argumints.svg?branch=master)
|
9 |
|
10 | A Powerful Command Line Arguments Preprocessor and Data Mining Tool
|
11 |
|
12 | ## Benefits
|
13 | ### CLI
|
14 | - argv
|
15 | - opt
|
16 | - flags
|
17 | - argc
|
18 | - keyValue
|
19 |
|
20 | ### Data Conversion
|
21 | - convert cli input (argv or keyValue) into JS primitives automatically.
|
22 |
|
23 | ### Data Mining
|
24 | - Supports JSON input (in either argv or keyValue formats) which are converted into deep JS Objects, that you can mine.
|
25 | - aggregate file content using the '@' file marker
|
26 | - search argument input using regular expression arguments
|
27 |
|
28 | ### Robustness
|
29 | - Uses Underscore JS for mining and copying / filtering / selection techniques.
|
30 |
|
31 | ## Usage
|
32 |
|
33 |
|
34 | #### Default ArguMints Instance
|
35 |
|
36 | ```js
|
37 |
|
38 | var myArgs = require('argumints').myArguMints;
|
39 |
|
40 | ```
|
41 |
|
42 | #### Roll your own instance
|
43 | ```js
|
44 |
|
45 | var lib = require('argumints');
|
46 | var myArgs = new lib.ArguMints();
|
47 | ```
|
48 |
|
49 | \- or \-
|
50 |
|
51 | ```js
|
52 |
|
53 | // the one liner
|
54 | var myArgs = new require('argumints').ArguMints();
|
55 |
|
56 | ```
|
57 | ### Basic Examples
|
58 | NOTE: Examples all from test materials included with ArguMints package!
|
59 | #### Options, Flags, and Argv
|
60 | ```js
|
61 |
|
62 | // cmd line equivalent
|
63 | // C:\argumints> node argumints-test.js -xzfv --option arg0 arg1
|
64 | // NOTE: verbose is true here because failing a check for an option will
|
65 | // revert to checking for the corresponding flag (usign first char of option name)
|
66 | myArgs.retort(["-xz", "--op1","--op2", "arg0", "arg1"]);
|
67 | console.log(myArgs.opt("op1")); // true
|
68 | console.log(myArgs.opt("op2")); // true
|
69 | console.log(myArgs.flag("x")); // true
|
70 | console.log(myArgs.flag("z")); // true
|
71 | console.log(myArgs.argv(0)); // arg0
|
72 | console.log(myArgs.argv(1)); // arg1
|
73 | console.log(myArgs.argc()); // 2
|
74 |
|
75 | ```
|
76 |
|
77 | #### The Key=Value Store
|
78 | ```js
|
79 |
|
80 | // cmd line equivalent
|
81 | // C:\argumints> node argumints-test.js x=2 y=3
|
82 | myArgs.retort(["x=2","y=3"]);
|
83 |
|
84 | console.log(myArgs.keyValue("x"));
|
85 | console.log(myArgs.keyValue("y"));
|
86 |
|
87 | ```
|
88 | ### Advanced Examples
|
89 |
|
90 | #### Text File Expansion
|
91 |
|
92 | ```js
|
93 |
|
94 | // cmd line equivalent
|
95 | // C:\argumints> node argumints-test.js @test/testargs2.json
|
96 | myArgs.retort(["@test/test.txt"]);
|
97 |
|
98 | console.log(myArgs.argv(0)); // output the text file content
|
99 | ```
|
100 |
|
101 | Test Materials:
|
102 |
|
103 | * [test.txt](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/test.txt)
|
104 |
|
105 | #### JSON Expansion in line
|
106 | JSON File Expansion works like regular File Expansion, with the additional benefit of grafting the resulting
|
107 | JSON Data into either the keyStore, or onto the argv list after expansion, depending on how you structured the
|
108 | input ArguMint (see what I did there??).
|
109 | ```js
|
110 |
|
111 | // Ex. 1
|
112 | // cmd line equivalent
|
113 | // C:\argumints> node argumints-test.js '{\"aProperty\":\"testValue\"}'
|
114 | myArgs.retort(["{\"aProperty\":\"testValue\"}"]);
|
115 | console.log(myArgs.keyValue("aProperty")); // testValue
|
116 |
|
117 | // Ex. 2
|
118 | myArgs.retort(["key=\"{\"aProperty\":\"testValue\"}\""]);
|
119 | console.log(myArgs.keyValue("key").aProperty); // testValue
|
120 |
|
121 | // Ex. 3
|
122 | // cmd line equivalent
|
123 | // C:\argumints> node argumints-test.js [1,2,3,4]
|
124 | myArgs.retort(["[1,2,3,4]"]);
|
125 | console.log(myArgs.argv(0)[2]); // 3
|
126 |
|
127 | ```
|
128 |
|
129 | #### JSON File Expansion
|
130 |
|
131 | ```js
|
132 |
|
133 | // cmd line equivalent
|
134 | // C:\argumints> node argumints-test.js @test/testargs1.json
|
135 | myArgs.retort(["@test/testargs1.json"]);
|
136 |
|
137 | console.log(myArgs.keyValue("aNumber")); // 1
|
138 | console.log(myArgs.keyValue("aBool")); // true
|
139 | console.log(myArgs.keyValue("anArray")[2]); // buckle
|
140 | console.log(myArgs.keyValue("anObject").prop); // aProperty
|
141 | console.log(myArgs.keyValue("nullValue")); // null
|
142 |
|
143 | ```
|
144 |
|
145 | Test Materials:
|
146 |
|
147 | * [testargs1.json](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/testargs1.json)
|
148 |
|
149 | #### Recursive JSON File Expansion
|
150 | ```js
|
151 |
|
152 | // cmd line equivalent
|
153 | // C:\argumints> node argumints-test.js @test/testargs2.json
|
154 | myArgs.retort(["@test/testargs2.json"]);
|
155 |
|
156 | console.log(myArgs.keyValue("fromFile1"));
|
157 | console.log(myArgs.keyValue("fromFile2"));
|
158 |
|
159 | ```
|
160 | Test Materials:
|
161 |
|
162 | * [testargs2.json](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/testargs2.json)
|
163 | * [test.txt](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/test.txt)
|
164 | * [test2.txt](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/test2.txt)
|
165 |
|
166 | #### Recursive JSON File Expansion and Mining (Advanced)
|
167 | ```js
|
168 |
|
169 | // cmd line equivalent
|
170 | // C:\argumints> node argumints-test.js @test/testargs3.json
|
171 | myArgs.retort(["@test/testargs3.json"]);
|
172 |
|
173 | console.log(myArgs.keyValue("testArgs1"));
|
174 | console.log(myArgs.keyValue("testArgs2"));
|
175 |
|
176 | // dig in to the values...
|
177 | console.log(myArgs.keyValue("testArgs1").aNumber);
|
178 | console.log(myArgs.keyValue("testArgs1").anArray[4]);
|
179 | console.log(myArgs.keyValue("testArgs2").fromFile1);
|
180 | console.log(myArgs.keyValue("testArgs2").fromFile2);
|
181 |
|
182 | ```
|
183 |
|
184 | Test Materials: - all files below were loaded because of templatization starting with testargs3.json
|
185 |
|
186 | * [testargs1.json](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/testargs1.json)
|
187 | * [testargs2.json](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/testargs2.json)
|
188 | * [testargs3.json](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/testargs3.json)
|
189 | * [test.txt](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/test.txt)
|
190 | * [test2.txt](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/test.txt)
|
191 |
|
192 | ### Bulk File Expansion
|
193 | #### Expansion in Array
|
194 | ```js
|
195 |
|
196 | ArguMints.verbose = true;
|
197 | // append some more 'command line' args.
|
198 | myArgs.retort([["@test/test.txt","@test/testargs1.json" /*[,nextFile...]*/]]);
|
199 |
|
200 | //results
|
201 | //test.txt contents loaded into the first array slot.
|
202 | //testargs1.json contents loaded, expanded into a JSON object
|
203 | // and placed into the second array slot.
|
204 | // the resulting array is placed in the first slot of
|
205 | // Argumints.commandTable.argList
|
206 | // (since it has no key=value) format, and is not a flag.
|
207 |
|
208 | ```
|
209 |
|
210 | Test Materials:
|
211 |
|
212 | * [test.txt](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/test.txt)
|
213 | * [testargs1.json](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/testargs1.json)
|
214 |
|
215 | #### Expansion as a Key=Value store
|
216 | ```js
|
217 |
|
218 | ArguMints.verbose = true;
|
219 | // append some more 'command line' args.
|
220 | myArgs.retort(["x=@test/test.txt","y=@test/testargs1.json"]);
|
221 |
|
222 | //results
|
223 | //test.txt contents are stored in the command table with key 'x'.
|
224 | //testargs1.json contents are expanded into a JSON Object, and stored
|
225 | // in the command table with key 'y'
|
226 |
|
227 | ```
|
228 |
|
229 | Test Materials:
|
230 |
|
231 | * [test.txt](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/test.txt)
|
232 | * [testargs1.json](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/testargs1.json)
|
233 |
|
234 | ### Circular Expansion Protection
|
235 | If you accidentally circularly reference files during an expansion chain, you'll get an exception as show below. This avoids infinite loops and stack overflows when doing really crazy things with ArguMints.
|
236 |
|
237 | ```js
|
238 |
|
239 | ArguMints.verbose = true;
|
240 | myArgs.retort(["x=@test/testarg_infinite.txt"]);
|
241 |
|
242 | //results
|
243 | // file refers to itself by having its contents be a valid url expansion, pointing to its own url.
|
244 | // an ArguMintsException is thrown due to Circular Expansion detection.
|
245 | // Each Argument is individually protected against circular expansion, so you CAN refer to the same file twice, as long as
|
246 | // its under different argument expansions.
|
247 |
|
248 | ```
|
249 |
|
250 | Test Materials:
|
251 | * [testarg_infinite.txt](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/testarg_infinite.txt)
|
252 |
|
253 | #### Notes on File Expansion
|
254 | Files are expanded using the '@' character to denote resource location. This is either an absolute or relative local resource. And can be a Windows or Linux Path. Windows paths that have Spaces in the name must be surrounded by quotes!
|
255 |
|
256 | The Following Formats are acceptable.
|
257 |
|
258 | "@C:\Program Files\Blah"
|
259 | "@Program Files\Blah"
|
260 | @..\another\place\for\file.txt
|
261 | @my/file/is/relative.txt
|
262 | @/abs/linux/path/or/root/of/curr/win/drive
|
263 | @\root\of\curr\win\drive
|
264 | @relative\win\path
|
265 |
|
266 | File contents can be in JSON format, which means their content will be expanded into a JavaScript object. Any properties of said object that are of String type, and follow the file expansion nomenclature will also be expanded. Circular Expansion is not allowed.
|
267 |
|
268 | ## Regular Expressions
|
269 |
|
270 |
|
271 | using '--minty-match-argv' option we perform aggregate data mining and data gathering.
|
272 |
|
273 | NOTE: Regular expressions must be surrounded by \`\` backticks to alert ArguMints that this is indeed treated as RegEx (and not a file path like /hey/g).
|
274 |
|
275 | ### CLI
|
276 |
|
277 | ```js
|
278 |
|
279 | // match all instances of the substring 'ord' or 'famil' within the two textfiles provided.
|
280 | // matches are cumulative.
|
281 | myArgs.retort(
|
282 | [
|
283 | "--minty-match-argv",
|
284 | "@test/testMatcher.txt", "@test/testMatcher2.txt",
|
285 | "/([A-Za-z0-9]*(ord)[A-Za-z]*)|(famil[A-Za-z0-9]*)/igm" // <--- NOTE Backticks around RegExp
|
286 | ] // not rendering in markdown js sections.
|
287 | // But they're there!!
|
288 | );
|
289 |
|
290 | console.log(myArgs.matches());
|
291 |
|
292 | // result
|
293 | /*
|
294 | [ 'ord',
|
295 | 'word',
|
296 | 'ordinal',
|
297 | 'ordinary',
|
298 | 'ordered',
|
299 | 'ordained',
|
300 | 'ford',
|
301 | 'Nordic',
|
302 | 'family',
|
303 | 'Family',
|
304 | 'families',
|
305 | 'Familiar',
|
306 | 'FaMiLy',
|
307 | 'FaMiLiAr'
|
308 | ]
|
309 | */
|
310 |
|
311 | ```
|
312 | Test Materials:
|
313 | * [testMatcher.txt](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/testMatcher.txt)
|
314 | * [testMatcher2.txt](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/testMatcher2.txt)
|
315 |
|
316 | ### From File
|
317 | You can save a regExp in a file and readily use it as a JavaScript RegExp() object.
|
318 | ```js
|
319 |
|
320 | // cmd line argumints-test.js --minty-match-argv @test/testMatcher.txt @test/testMatcher2.txt @test/regExpOrd.txt
|
321 | myArgs.retort(["--minty-match-argv","@test/regExpOrd.txt", "@test/testMatcher.txt", "@test/testMatcher2.txt"]);
|
322 | console.log(myArgs.matches());
|
323 |
|
324 | ```
|
325 |
|
326 | Test Materials:
|
327 |
|
328 | * [testMatcher.txt](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/testMatcher.txt)
|
329 | * [testMatcher2.txt](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/testMatcher2.txt)
|
330 | * [regExpOrd.txt](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/regExpOrd.txt)
|
331 |
|
332 | ####OR USING KEY VALUE STORE
|
333 | ```js
|
334 |
|
335 | // cmd line argumints-test.js --minty-match-kv @test/regExp.txt @test/testMatcher.txt @test/testMatcher2.txt
|
336 | myArgs.retort(["--minty-match-kv", "search=This is an email: myemail@address.com", "exp=@test/regExp.txt"]);
|
337 | console.log(myArgs.matches());
|
338 |
|
339 | // use the reg ex again and again!
|
340 | var regExp = myArgs.keyValue("exp");
|
341 | console.log("this is my email: myemail@address.com ok?".match(regExp)); //['myemail@address.com']
|
342 |
|
343 | ```
|
344 |
|
345 | Test Materials:
|
346 |
|
347 | * [testMatcher.txt](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/testMatcher.txt)
|
348 | * [testMatcher2.txt](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/testMatcher2.txt)
|
349 | * [regExp.txt](https://npm-cdn.herokuapp.com/argumints@1.2.40/test/regExp.txt)
|
350 |
|
351 |
|
352 |
|
353 | ### The Options {} Object:
|
354 |
|
355 | You may pass an `options` object to `ArguMints` so it will understand how to `retort` to your input.
|
356 | Below are the default values used by `ArguMints` should none be passed in. Also, the `myArguMints` object
|
357 | ```js
|
358 |
|
359 | var options = {
|
360 | treatBoolStringsAsBoolean:true, // argv of "true/false" are converted to boolean
|
361 | treatNullStringsAsNull:true, // argv of "null" converted to null
|
362 | treatRegExStringsAsRegEx:true, // argv of "/*.*/g" converted to RegEx("*.*","g");
|
363 | treatNumberStringsAsNumbers:true, // argv of "1" converted to Number(1)
|
364 | treatUndefinedStringsAsUndefined:true, // argv of "undefined" converted to undefined
|
365 | enableArgFileLoading:true, // argv of @filename.txt will load contents of filename.txt (if true) otherwise, no change is made to value.
|
366 | ignoreJson:false // ignore json formatting and return the literal string value.
|
367 | };
|
368 |
|
369 |
|
370 |
|
371 |
|
372 | ```
|
373 |
|
374 |
|
375 | ### Requirements
|
376 |
|
377 | Node
|
378 |
|
379 | ### Installation
|
380 |
|
381 | ```
|
382 | npm install argumints
|
383 | ```
|
384 |
|
385 | ## API
|
386 |
|
387 | ### Methods
|
388 |
|
389 | #### .retort(arrayOfArgs=null, onStartCb=null, onArgExpandCb=null)
|
390 |
|
391 |
|
392 | Immediately analyzes the input arguments to the current running node process, as well as the additional `arrayOfArgs` passed in.
|
393 |
|
394 | ##### params
|
395 | `arrayOfArgs1` - an Array of 'string' values that will be expanded, or `null`
|
396 |
|
397 | `onStartCb` - a `function` with signature `function(userAgs)` or `null`. If specified, the function will be called upon starting the retort, after gathering the input arguments.
|
398 |
|
399 | `onArgExpandCb` - a `function` with signature `function(argVal, expandedVal, idx, cnt)` or `null`. If specified, the function will be called upon the processing of each individual argument in `arrayOfArgs` allowing you to act after each one. The arguments for the function are the original argument, the expanded value, the current argument `idx`, and,the count of arguments.
|
400 |
|
401 | You Can call `retort()` multiple times, with an array of arguments, or with no arguments. Arguments will be treated the same as if they were passed in via command line.
|
402 |
|
403 |
|
404 |
|
405 | ```js
|
406 |
|
407 | myArgs.retort([1,2,3], onStart, onRetortEach);
|
408 |
|
409 | function onStart(args){
|
410 | console.log("there are: " + args.length + " input args"); // 3
|
411 | }
|
412 | function onRetortEach(arg, exp, idx, cnt){
|
413 | console.log(arg + "=>" + exp + ", is last one? " + (idx == cnt-1));
|
414 | }
|
415 |
|
416 | ```
|
417 |
|
418 | ### getUserArgs()
|
419 | Returns all arguments passed in originally by the user (prior to expansion)
|
420 |
|
421 | ```js
|
422 |
|
423 | // node argumints-test.js arg1 arg2 --opt1 --opt2 -fxzy key1=val1 key2=val2
|
424 | console.log(myArgs.retort().getUserArgs());
|
425 | //output is [arg1, arg2, --opt1, --opt2, -fxzy, key1=val1, key2=val2]
|
426 |
|
427 | ```
|
428 |
|
429 | ### getScriptArgs()
|
430 | Returns the script arguments which are either of length 1 or 2, depending on where you are running code from (node command line or windows command line via node executable).
|
431 |
|
432 | ```js
|
433 |
|
434 | // node argumints-test.js arg1 arg2 --opt1 --opt2 key1=val1 key2=val2
|
435 | console.log(myArgs.retort().getScriptArgs());
|
436 | //output is [C:\path\to\node.exe, C:\path\to\script.js]
|
437 | // OR [C:\path\to\node.exe] when running in Node Command Line.
|
438 |
|
439 | ```
|
440 | ### .argc()
|
441 | Returns the number of positional user arguments.
|
442 |
|
443 | #### .argv(atIndex=null)
|
444 | Returns the ordered argument passed into the Node Script at the specified index, or all items if the index is not specified.
|
445 |
|
446 | ```js
|
447 |
|
448 | // node argumints-test.js helpMe! thank you -fx --opt1
|
449 | console.log(myArgs.retort().argv(1)); // output: helpMe!
|
450 |
|
451 | // get them all
|
452 | console.log(myArgs.retort().argv()); // output: [helpMe!,thank,you]
|
453 | ```
|
454 |
|
455 | #### .opt(optName)
|
456 | Returns true if the option at `optName` was set
|
457 | If no `optName` is specified, a copy of the internal _opt table is returned for inspection.
|
458 | ```js
|
459 |
|
460 | // argumints-test --verbose
|
461 | console.log(myArgs.retort().opt("verbose")); // output: true
|
462 |
|
463 | // get them all
|
464 | console.log(myArgs.retort().opt()); // output: {verbose:true}
|
465 | ```
|
466 |
|
467 | In addition to using `opt` as a check, you can specify some 'built in' options
|
468 | to enhance the minty flavour of `ArguMints`.
|
469 |
|
470 | ##### Built in options
|
471 |
|
472 | The Following Options will change the internal behavior of ArguMints
|
473 | * `--minty-match-argv`
|
474 | * `--minty-match-kv`
|
475 | * `--minty-dump`
|
476 | * `--minty-append-dup-keys`
|
477 | * `--minty-op-add`
|
478 | * `--minty-op-sub`
|
479 | * `--minty-op-div`
|
480 | * `--minty-op-mul`
|
481 | * `--minty-op-sqrt`
|
482 | * `--minty-op-sqr`
|
483 | * `--minty-op-ln`
|
484 | * `--minty-no-cache`
|
485 | * `--minty-verbose`
|
486 | * `--minty-clear-opts`
|
487 | * `--minty-clear-flags`
|
488 |
|
489 | ###### --minty-match-argv
|
490 | setting this option will match all ordered arguments which aren't RegularExpressions against all ordered arguments which are regular expressions, and aggregate the matches. This is useful when spanning multiple files for patterns (i.e. email addresses, etc).
|
491 |
|
492 | ```js
|
493 |
|
494 | // the first two positional arguments are files containing text blobs.
|
495 | // the third positional argument is a text file containing a regular expression which
|
496 | // will expand to a RegExp instance, and match against the content of the files.
|
497 | myArgs.retort(["--minty-match-argv","@test/testMatcher.txt","@test/testMatcher2.txt", "@test/regExpOrd.txt"]);
|
498 | var matches = myArgs.matches();
|
499 | ```
|
500 | ###### --minty-match-kv
|
501 | much like minty-match-argv, except this iterates through keyStore values rather than positional arguments.
|
502 | you must only set one of these two keys, they are mutually exclusive.
|
503 | ```js
|
504 |
|
505 | myArgs.retort(["--minty-match-kv","file1=@test/testMatcher.txt","file2=@test/testMatcher2.txt", "searchRegExp=@test/regExpOrd.txt"]);
|
506 | var matches = myArgs.matches();
|
507 |
|
508 | ```
|
509 |
|
510 | ##### --minty-dump
|
511 | Once retort completes, a minty-dump (of the commandTableData) will be displayed on console. smells great...
|
512 |
|
513 |
|
514 | ##### --minty-append-dup-keys
|
515 | If the same `key` is set as a `keyValue` across one (or multiple) calls to `retort()`, the results are aggregated.
|
516 | This only works for Array (pushes or concatenates), Number (adds unless otherwise specified) and String types (concatenates)
|
517 |
|
518 | ```js
|
519 |
|
520 | // node .\argumints-test.js --minty-append-dup-keys "key1=some text" "key1=, more text" "key1=, even more" --minty-dump
|
521 | myArgs.retort(["--minty-append-dup-keys", "key1=some text", "key1=", more text", "key1=", even more"]);
|
522 | console.log(myArgs.keyValue('key1');
|
523 |
|
524 | //output: some text, more text, even more
|
525 |
|
526 |
|
527 | // -- OR --
|
528 |
|
529 | myArgs.retort(["--minty-append-dup-keys", "key1=2","key1=2","key1=6"]);
|
530 |
|
531 | console.log(myArgs.keyValue('key1'));
|
532 | //output: 10
|
533 |
|
534 |
|
535 | // -- OR --
|
536 |
|
537 | myArgs.retort(["--minty-append-dup-keys", "key1=221","key1=B","key1= Baker Street"]);
|
538 | myArgs.keyValue('key1')); // output: 221B Baker Street
|
539 | // -- OR --
|
540 |
|
541 | myArgs.retort(["--minty-append-dup-keys", "key1=0x000000","key1=0xFFF000","key2=0x000FFF"]);
|
542 | console.log(myArgs.keyValue('key1') == myArgs.keyValue('key2')); // output: true
|
543 |
|
544 | ```
|
545 | Mutually Exclusive Operation Modifiers
|
546 |
|
547 | ###### --minty-op-add
|
548 | Use this with `--minty-append-dup-keys`, this will decide the current operation to be performed. this is enabled by default unless another type is specified.
|
549 |
|
550 | ###### --minty-op-div
|
551 | Uses a divide operation when `--minty-append-dup-keys` is set.
|
552 |
|
553 | ###### --minty-op-sub
|
554 | Uses a subtract operation when `--minty-append-dup-keys` is set.
|
555 |
|
556 | ###### --minty-op-mul
|
557 | Uses a multiply operation when `--minty-append-dup-keys` is set.
|
558 |
|
559 | ###### --minty-op-sqrt
|
560 | Uses a square root operation when `--minty-append-dup-keys` is set.
|
561 |
|
562 | ###### --minty-op-sqr
|
563 | Uses a square operation when `--minty-append-dup-keys` is set.
|
564 |
|
565 | ###### --minty-op-ln
|
566 | Uses a natural log operation when `--minty-append-dup-keys` is set.
|
567 |
|
568 | ###### --minty-op-tan
|
569 | Uses a tangent `(Math.tan(argAt))` operation`--minty-append-dup-keys` is set.
|
570 |
|
571 | ###### --minty-op-atan
|
572 | Uses a tangent `(Math.atan(argAt))` operation`--minty-append-dup-keys` is set.
|
573 |
|
574 | ###### --minty-op-sin
|
575 | Uses a tangent `(Math.sin(argAt))` operation`--minty-append-dup-keys` is set.
|
576 |
|
577 | ###### --minty-op-cos
|
578 | Uses a tangent `(Math.cos(argAt))` operation`--minty-append-dup-keys` is set.
|
579 |
|
580 | ###### --minty-op-exp
|
581 | Agreggates `(Math.exp(argAt))` or `e^x` operations on a key if set one or more times and `--minty-append-dup-keys` is set.
|
582 |
|
583 |
|
584 | ##### --minty-no-cache
|
585 | File contents are not cached. Normally expanding a file will cache the file content, so further expansions in arguments using the
|
586 | same file will be faster. However, if your script modifies the file between retorts, or even while retorting, you can set this option to force it to reload upon each expansion request
|
587 |
|
588 | ```js
|
589 |
|
590 | myArgs.retort(["--minty-no-cache", "@test/test1.txt", "key1="@test/test1.txt", "key2="@test/test1.txt"]);
|
591 | //result: test1.txt is reloaded 3 times
|
592 |
|
593 | ```
|
594 |
|
595 | ##### --minty-clear-opts and --minty-clear-flags
|
596 | This allows you to change how minty works during a retort. For example, within the expansion callback (3rd parameter)
|
597 | if this is set, your flags/options are wiped clean and the next
|
598 | iteration will result in different behavior. Further more, you can
|
599 | push or insert arguments into minty as it is retorting as long
|
600 | as they are inserted after the current processing point.
|
601 |
|
602 | ```js
|
603 |
|
604 | myArgs.retort(["--minty-clear-opts", "--opt"], null, function(a,e,i,c){
|
605 | // opts are now clear
|
606 | myArgs.insertArg("--minty-clear-opts");
|
607 | myArgs.pushArg("--opt2");
|
608 | });
|
609 |
|
610 |
|
611 | ```
|
612 |
|
613 | #### .flag(flagName=undefined)
|
614 | returns true if a flag by name is enabled. Flag names are a single character.
|
615 | If no flagName is passed, a copy of the internal _opt table is returned for inspection.
|
616 | ```js
|
617 |
|
618 | // argumints-test --verbose
|
619 | console.log(myArgs.retort().matches()); // true
|
620 |
|
621 | ```
|
622 | #### .keyValue(key=undefined)
|
623 | Returns the value stored under `key` in the keyStore. The Key Store is populated using the format `key=value` when passing in arguments. you can also specify files, i.e. `key=@test/test.txt`
|
624 | If no `key` is specified, a copy of the entire keyStore is returned for your inspection.
|
625 |
|
626 | ```js
|
627 |
|
628 | // argumints-test x=2
|
629 | console.log(myArgs.retort().keyValue("x")); // 2
|
630 |
|
631 | ```
|
632 | #### .matches(start=-1,end=-1)
|
633 | Returns any matches after a retort with a regular expression and having --minty-match-argv or --minty-match-kv enagbled.
|
634 | if `start` or `end` are specified, it will return a 'slice' of the matches contained within.
|
635 |
|
636 | ```js
|
637 |
|
638 | // argumints-test --minty-verbose --minty-match-argv @test/testMatcher2.txt @test/regExpOrd.txt
|
639 | console.log(myArgs.retort().matches()); // true
|
640 |
|
641 | ```
|
642 |
|
643 | #### .insertArg(arg, xArgsFromHere);
|
644 | This allows you to insert arguments directly in front of the current retort position. This means you can do fun things
|
645 | like factorials. NOTE: This is not meant to replace good old native code doing math, but its great for scripting and doing
|
646 | dynamic templated calculations and datamining.
|
647 | ```js
|
648 |
|
649 | // the factorial function, ArguMints style!
|
650 | var fact = 1;
|
651 | defaultMints.retort( [3],null, function(arg, exp, idx, cnt){
|
652 | if( typeof exp == 'number' && exp > 0){
|
653 | fact *= exp;
|
654 | defaultMints.insertArg(arg-1, 0);
|
655 | }
|
656 | });
|
657 |
|
658 | console.log("Fact: " + fact); // output 6
|
659 |
|
660 |
|
661 | ```
|
662 |
|
663 | #### .pushArg(moreArgs)
|
664 | Pushes additional arguments onto the user argument queue. This can only be done during a retort, thus you must call this from the retort callback you pass into retort. be careful that you have a way to stop pushing arguments to avoid an infinitely growing args list.
|
665 |
|
666 | ```js
|
667 |
|
668 | // the summation function, ArguMints style!
|
669 | var sum = 0;
|
670 | var t = 15; // first x numbers
|
671 | defaultMints.retort( [1],null, function(arg, exp, idx, cnt){
|
672 | if( typeof exp === 'number' ){
|
673 | sum += exp;
|
674 |
|
675 | t--;
|
676 | if(t > 0){
|
677 | defaultMints.pushArg(exp+1);
|
678 | }
|
679 | }
|
680 | });
|
681 |
|
682 | console.log("Sum: " + sum);
|
683 |
|
684 | ```
|
685 | #### .reset(newOptions=undefined)
|
686 | Resets the ArguMints instance. You must call `retort()` again to re-parse the argument inputs, however, this gives you the option to append new arguments onto the instance.
|
687 |
|
688 | ```js
|
689 |
|
690 | // reset all data, keep current options
|
691 | myArgs.reset();
|
692 |
|
693 | // reset all data, and overwrite new options
|
694 | myArgs.reset({ignoreJson:true});
|
695 |
|
696 | ```
|
697 |
|
698 | ### License
|
699 |
|
700 | ```
|
701 | The MIT License (MIT)
|
702 |
|
703 | Copyright (c) 2016 Decoded4620
|
704 |
|
705 | Permission is hereby granted, free of charge, to any person obtaining a copy
|
706 | of this software and associated documentation files (the "Software"), to deal
|
707 | in the Software without restriction, including without limitation the rights
|
708 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
709 | copies of the Software, and to permit persons to whom the Software is
|
710 | furnished to do so, subject to the following conditions:
|
711 |
|
712 | The above copyright notice and this permission notice shall be included in all
|
713 | copies or substantial portions of the Software.
|
714 |
|
715 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
716 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
717 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
718 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
719 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
720 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
721 | SOFTWARE.
|
722 | ``` |
\ | No newline at end of file |