automate more option stuff

if the elaborator writes it then it will be kept up to date
automatically
This commit is contained in:
rhiannon morris 2023-10-24 18:25:56 +02:00
parent 314e7f036d
commit 1f14e4ab9e
1 changed files with 7 additions and 12 deletions

View File

@ -7,6 +7,7 @@ import System.File
import System.Term
import Derive.Prelude
%default total
%language ElabReflection
public export
@ -63,20 +64,14 @@ toOutFile "" = Ok {outFile := None}
toOutFile "-" = Ok {outFile := Stdout}
toOutFile f = Ok {outFile := File f}
private
phaseName : Phase -> String
phaseName Parse = "parse"
phaseName Check = "check"
phaseName Erase = "erase"
private
toPhase : String -> OptAction
toPhase str = case toLower str of
"parse" => Ok {until := Just Parse}
"check" => Ok {until := Just Check}
"erase" => Ok {until := Just Erase}
_ => Err "unknown phase name \{show str}\nphases: \{phaseNames}"
where phaseNames = joinBy ", " $ map phaseName allPhases
toPhase str =
let lstr = toLower str in
case find (\p => toLower (show p) == lstr) allPhases of
Just p => Ok {until := Just p}
Nothing => Err "unknown phase name \{show str}\nphases: \{phaseNames}"
where phaseNames = joinBy ", " $ map (toLower . show) allPhases
private
toWidth : String -> OptAction