David Gordon
David Gordon

Reputation: 91

Is there a way to have a short and two long command line argument alternatives for a parameter?

I have guessed multiple syntax variations to achieve this in a single line in the MAIN function. I know I could achieve it in two separate lines, but am looking for the cleaner solution and only having the one named parameter assigned the value where the other long named parameter argument is just a form of alias.

Below are variations that all fail to compile with several different error messages. They were all tested one by one and as the first line in the MAIN function:

Bool :A(:$opt-ALLDEBUG is alias<ALLDEBUG>) = False,         
Bool :A(:$opt-ALLDEBUG) = False,                
Bool (:$opt-ALLDEBUG is alias<ALLDEBUG>) = False,       
Bool :A(:$ALLDEBUG) = False,                    
Bool :opt-ALLDEBUG(:-A :ALLDEBUG) = False,              
Bool :opt-ALLDEBUG(:-A :ALLDEBUG),                  
Bool :opt-ALLDEBUG(-A :ALLDEBUG),                   
Bool :opt-ALLDEBUG(:ALLDEBUG -A ),                  
Bool :opt-ALLDEBUG(:ALLDEBUG -:A ),                 
Bool :opt-ALLDEBUG(:ALLDEBUG -:A),                  
Bool :opt-ALLDEBUG(:ALLDEBUG),                  
Bool :opt-ALLDEBUG(:ALLDEBUG),                  
Bool :$opt-ALLDEBUG(:ALLDEBUG),                 
Bool :$opt-ALLDEBUG :ALLDEBUG,                  
Bool :$opt-ALLDEBUG :$ALLDEBUG,                 
Bool :$opt-ALLDEBUG :$ALLDEBUG = False,                 
Bool :$opt-ALLDEBUG (:$ALLDEBUG :A) = False,                
Bool :$opt-ALLDEBUG (:$ALLDEBUG :-A) = False,                   
Bool :A(:$opt-ALLDEBUG :$ALLDEBUG) = False,             
Bool :$opt-ALLDEBUG(:A, :$ALLDEBUG) = False,            
Bool :$opt-ALLDEBUG(:A :$ALLDEBUG) = False,             
Bool :A(:$opt-ALLDEBUG) (:$ALLDEBUG) = False,               
Bool :$opt-ALLDEBUG (:$ALLDEBUG) = False,                   
Bool :$opt-ALLDEBUG (:$ALLDEBUG),                   

Upvotes: 9

Views: 375

Answers (1)

ugexe
ugexe

Reputation: 5726

You can nest the aliasing as shown below. Note that as far as raku is concerned there is no difference between short options with - and long options with -- and they can be used interchangeably

$ raku -e 'sub MAIN(Bool :A(:opt-ALLDEBUG(:$ALLDEBUG)) = False) { say $ALLDEBUG }'
False

$ raku -e 'sub MAIN(Bool :A(:opt-ALLDEBUG(:$ALLDEBUG)) = False) { say $ALLDEBUG }' -A
True

$ raku -e 'sub MAIN(Bool :A(:opt-ALLDEBUG(:$ALLDEBUG)) = False) { say $ALLDEBUG }' --opt-ALLDEBUG
True

$ raku -e 'sub MAIN(Bool :A(:opt-ALLDEBUG(:$ALLDEBUG)) = False) { say $ALLDEBUG }' --ALLDEBUG
True

Also see https://docs.raku.org/language/signatures#Argument_aliases

Upvotes: 11

Related Questions