Changeset 8726
- Timestamp:
- 01/17/06 14:08:41 (3 years ago)
- Files:
-
- 2 modified
-
lib/pugs/run.pod (modified) (1 diff)
-
src/Pugs/Run/Args.hs (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lib/pugs/run.pod
r7871 r8726 24 24 WRITEME 25 25 26 =head2 Flags separation27 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' -- --help32 33 But this will show the help message of Pugs:34 35 $ pugs -e 'say @ARGS' --help36 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 43 26 =head2 Command line options 44 27 -
src/Pugs/Run/Args.hs
r6004 r8726 19 19 20 20 -- | Command line argument parser for pugs. 21 module Pugs.Run.Args (canonicalArgs 22 , gatherArgs 23 , unpackOptions 24 25 ) 26 where 21 module Pugs.Run.Args ( 22 canonicalArgs, 23 gatherArgs, 24 unpackOptions, 25 ) where 27 26 import Pugs.Internals 28 27 … … 53 52 54 53 unpackOptions :: [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 54 unpackOptions [] = [] 55 unpackOptions (("-"):rest) = ("-":unpackOptions rest) 56 unpackOptions opts@("--":_) = opts 57 unpackOptions (('-':opt):arg:rest) 58 | takesArg opt = unpackOption opt ++ (arg:unpackOptions rest) 59 unpackOptions (('-':opt):rest) = unpackOption opt ++ unpackOptions rest 60 unpackOptions opts@[filename] = opts 61 unpackOptions (filename:rest) = filename : "--" : unpackOptions rest 62 63 takesArg :: String -> Bool 64 takesArg xs | xs `elem` withParam = True 65 takesArg (x:xs) | x `elem` composable = takesArg xs 66 takesArg _ = False 60 67 61 68 unpackOption :: String -> [String]
