Changeset 8726

Show
Ignore:
Timestamp:
01/17/06 14:08:41 (3 years ago)
Author:
audreyt
Message:

* Pugs.Run.Args: When the arg list parser encounters the script

file name, treat everything after it (even -options) as arguments.

So these two forms are now identical:

pugs foo.p6 --help
pugs foo.p6 -- --help

(t/pugsrun/12-script-args.t now passes because of this.)

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lib/pugs/run.pod

    r7871 r8726  
    2424WRITEME 
    2525 
    26 =head2 Flags separation 
    27  
    28 Pugs uses C<--> to separate flags of Pugs itself and arguments to the program. 
    29 For example, this will print C<--help>: 
    30  
    31     $ pugs -e 'say @ARGS' -- --help 
    32  
    33 But this will show the help message of Pugs: 
    34  
    35     $ pugs -e 'say @ARGS' --help 
    36  
    37 For the same reason, to use Pugs in the Unix C<#!> line, add an extra C<--> 
    38 after it: 
    39  
    40     #!/usr/bin/pugs -- 
    41     say 'Hello, ', @ARGS, '!'; 
    42  
    4326=head2 Command line options 
    4427 
  • src/Pugs/Run/Args.hs

    r6004 r8726  
    1919 
    2020-- | Command line argument parser for pugs. 
    21 module Pugs.Run.Args (canonicalArgs 
    22 , gatherArgs 
    23 , unpackOptions 
    24  
    25 ) 
    26 where 
     21module Pugs.Run.Args ( 
     22    canonicalArgs, 
     23    gatherArgs, 
     24    unpackOptions, 
     25) where 
    2726import Pugs.Internals 
    2827 
     
    5352 
    5453unpackOptions :: [String] -> [String] 
    55 unpackOptions [] = [] 
    56 unpackOptions (('-':[]):rest)  = ["-"] ++ unpackOptions rest 
    57 unpackOptions ("--":opts) = ["--"] ++ opts 
    58 unpackOptions (('-':opt):rest) = unpackOption opt ++ unpackOptions rest 
    59 unpackOptions (filename:rest) = filename : unpackOptions rest 
     54unpackOptions []                = [] 
     55unpackOptions (("-"):rest)      = ("-":unpackOptions rest) 
     56unpackOptions opts@("--":_)     = opts 
     57unpackOptions (('-':opt):arg:rest) 
     58    | takesArg opt              = unpackOption opt ++ (arg:unpackOptions rest) 
     59unpackOptions (('-':opt):rest)  = unpackOption opt ++ unpackOptions rest 
     60unpackOptions opts@[filename]   = opts 
     61unpackOptions (filename:rest)   = filename : "--" : unpackOptions rest 
     62 
     63takesArg :: String -> Bool 
     64takesArg xs     | xs `elem` withParam   = True 
     65takesArg (x:xs) | x `elem` composable   = takesArg xs 
     66takesArg _                              = False 
    6067 
    6168unpackOption :: String -> [String]