Verified Commit a9291252 authored by Camil Staps's avatar Camil Staps 🚀

Accept input file as operand

parent b38832ba
module profile2html module profile2html
import StdEnv import StdEnv
import StdMaybe
import Data.Error import Data.Error
import Data.Func import Data.Func
...@@ -31,12 +32,13 @@ Start w ...@@ -31,12 +32,13 @@ Start w
# ([prog:args],w) = getCommandLine w # ([prog:args],w) = getCommandLine w
# args = parseOptions option_description args defaultOptions # args = parseOptions option_description args defaultOptions
| isError args | isError args
= exit (join "\n" (fromError args)) w = exit (join "\n" [usage prog,"":fromError args]) w
# args = fromOk args # args = fromOk args
| args.input=="" | size args.input==0
= exit "Specify an input file with -i/--input" w = exit "Specify an input file" w
| args.output=="" # args & output = if (size args.output==0)
= exit "Specify an output file with -o/--output" w (addExtension args.input "html")
args.output
# (ok,input,w) = fopen args.input FReadData w # (ok,input,w) = fopen args.input FReadData w
| not ok | not ok
= exit "Could not open input file" w = exit "Could not open input file" w
...@@ -52,12 +54,14 @@ Start w ...@@ -52,12 +54,14 @@ Start w
# (_,w) = fclose f w # (_,w) = fclose f w
= w = w
where where
option_description = WithHelp True $ Options usage prog = concat
[ Shorthand "-i" "--input" $ Option "--input" [ "Usage: "
(\ip opts -> Ok {opts & input=ip}) , prog
"INPUT" , " [options] INPUT"
"The input file" ]
, Shorthand "-o" "--output" $ Option "--output" option_description =
WithHelp True $ Options
[ Shorthand "-o" "--output" $ Option "--output"
(\op opts -> Ok {opts & output=op}) (\op opts -> Ok {opts & output=op})
"OUTPUT" "OUTPUT"
"The output file" "The output file"
...@@ -75,6 +79,14 @@ where ...@@ -75,6 +79,14 @@ where
-> Ok {opts & min_cumulative_ticks=t}) -> Ok {opts & min_cumulative_ticks=t})
"N" "N"
"Only include cost centres with at least N ticks (cumulatively)" "Only include cost centres with at least N ticks (cumulatively)"
, Operand
False
(\ip opts
| size opts.input==0
-> Just (Ok {opts & input=ip})
-> Nothing)
"INPUT"
"The input file"
] ]
exit err w exit err w
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment