3-- Copyright : (c) 2019 Composewell Technologies
6-- Maintainer : streamly@composewell.com
8module Common (parseCLIOpts) where
10import Control.Exception (evaluate)
11import Control.Monad (when)
12import Data.List (scanl')
13import Data.Maybe (catMaybes)
14import System.Console.GetOpt
15 (OptDescr(..), ArgDescr(..), ArgOrder(..), getOpt')
16import System.Environment (getArgs)
17import Text.Read (readMaybe)
21-------------------------------------------------------------------------------
22-- Parse custom CLI options
23-------------------------------------------------------------------------------
25data BenchOpts = StreamSize Int deriving Show
27options :: [OptDescr BenchOpts]
30 Option [] ["stream-size"] (ReqArg getSize "COUNT") "Stream element count"
35 getSize :: String -> BenchOpts
37 case (readMaybe size :: Maybe Int) of
38 Just x -> StreamSize x
39 Nothing -> error "Stream size must be numeric"
42 :: (Maybe String, Maybe String) -- (prev, yielded)
44 -> (Maybe String, Maybe String)
45deleteOptArgs (Nothing, _) opt =
46 if opt == "--stream-size"
47 then (Just opt, Nothing)
48 else (Just opt, Just opt)
50deleteOptArgs (Just prev, _) opt =
51 if opt == "--stream-size" || prev == "--stream-size"
52 then (Just opt, Nothing)
53 else (Just opt, Just opt)
55parseCLIOpts :: Int -> IO (Int, Config, [String])
56parseCLIOpts defaultStreamSize = do
59 -- Parse custom options
60 let (opts, _, _, errs) = getOpt' Permute options args
61 when (not $ null errs) $ error $ concat errs
62 (streamSize, args') <- evaluate $
65 -- Hack! remove the option and its argument from args
66 -- getOpt should have a way to return the unconsumed args in
71 $ scanl' deleteOptArgs (Nothing, Nothing) args
73 _ -> (defaultStreamSize, args)
75 -- Parse gauge options
76 let config = defaultConfig
79 , includeFirstIter = streamSize > defaultStreamSize
81 let (cfg, benches) = parseWith config args'
82 return (streamSize, cfg, benches)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list