@@ -19,8 +19,14 @@ class Cmd extends @command, CmdBase {
1919
2020 StringConstExpr getCmdName ( ) { result = this .getElement ( 0 ) }
2121
22- Expr getAnArgument ( ) { result = this .getArgument ( _) or result = this .getNamedArgument ( _) }
23-
22+ /** Gets any argument to this command. */
23+ Expr getAnArgument ( ) { result = this .getArgument ( _) }
24+
25+ /**
26+ * Gets the `i`th argument to this command.
27+ *
28+ * The argument may be named or positional.
29+ */
2430 Expr getArgument ( int i ) {
2531 result =
2632 rank [ i + 1 ] ( CmdElement e , int j |
@@ -32,6 +38,18 @@ class Cmd extends @command, CmdBase {
3238 )
3339 }
3440
41+ /** Gets the `i`th positional argument to this command. */
42+ Expr getPositionalArgument ( int i ) {
43+ result =
44+ rank [ i + 1 ] ( Argument e , int j |
45+ e = this .getArgument ( j ) and
46+ e instanceof PositionalArgument
47+ |
48+ e order by j
49+ )
50+ }
51+
52+ /** Gets the named argument with the given name. */
3553 Expr getNamedArgument ( string name ) {
3654 exists ( int i , CmdParameter p |
3755 this .getElement ( i ) = p and
@@ -53,11 +71,21 @@ class Cmd extends @command, CmdBase {
5371class Argument extends Expr {
5472 Cmd cmd ;
5573
56- Argument ( ) { cmd .getArgument ( _ ) = this or cmd . getNamedArgument ( _ ) = this }
74+ Argument ( ) { cmd .getAnArgument ( ) = this }
5775
5876 Cmd getCmd ( ) { result = cmd }
5977
60- int getIndex ( ) { cmd .getArgument ( result ) = this }
78+ int getPosition ( ) { cmd .getPositionalArgument ( result ) = this }
6179
6280 string getName ( ) { cmd .getNamedArgument ( result ) = this }
6381}
82+
83+ /** A positional argument to a command. */
84+ class PositionalArgument extends Argument {
85+ PositionalArgument ( ) { not this instanceof NamedArgument }
86+ }
87+
88+ /** A named argument to a command. */
89+ class NamedArgument extends Argument {
90+ NamedArgument ( ) { this = cmd .getNamedArgument ( _) }
91+ }
0 commit comments