File tree 1 file changed +45
-0
lines changed
1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Enhanced Command Line Argument Parser
2
+ // Copyright (c) 2019 Sport Trades Ltd
3
+
4
+ // Documentation: https://github.com/BuaBook/kdb-common/wiki/cargs.q
5
+
6
+ .require.lib `type ;
7
+
8
+
9
+ / This function provides additional parsing on top of the standard '.Q.opt' parsing for user-specified command line arguments
10
+ / @returns (Dict) Argument parameter as keys with the argument values
11
+ / @see .cargs.i.parse
12
+ / @see .z.x
13
+ .cargs.get: {
14
+ : .cargs.i.parse .z.x ;
15
+ };
16
+
17
+ / This function provides addition parsing on top of the standard '.Q.opt' parsing for all command line arguments (including kdb
18
+ / internal single-character arguments
19
+ / @returns (Dict) Argument parameter as keys with the argument values
20
+ / @see .cargs.i.parse
21
+ / @see .z.X
22
+ .cargs.getWithInternal: {
23
+ : .cargs.i.parse .z.X ;
24
+ };
25
+
26
+
27
+ / Command line argument parser with additional functionality on top of the standard '.Q.opt' parsing:
28
+ / - Removes additional '-' when argument keys are specified in the more standard '--parameter' form
29
+ / - All argument values are a string (10h) with multi-argument values joined with spaces between them
30
+ / @returns (Dict) Argument parameter as keys with the argument values
31
+ / @throws IllegalArgumentException If the input is not a mixed list of strings
32
+ / @see .Q.opt
33
+ .cargs.i.parse: {[cmdArgsStr ]
34
+ if [not .type.isMixedList cmdArgsStr ;
35
+ ' "IllegalArgumentException" ;
36
+ ];
37
+
38
+ cmdArgs : .Q.opt cmdArgsStr ;
39
+ cmdArgs : " " sv /: cmdArgs ;
40
+
41
+ cmdArgsK : key cmdArgs ;
42
+ cmdArgsK : @ [cmdArgsK ; where "-" = first each string cmdArgsK ; { ` $ 1 _ string x }];
43
+
44
+ : cmdArgsK ! value cmdArgs ;
45
+ };
You can’t perform that action at this time.
0 commit comments