diff options
Diffstat (limited to 'clpm.icl')
-rw-r--r-- | clpm.icl | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/clpm.icl b/clpm.icl new file mode 100644 index 0000000..195b135 --- /dev/null +++ b/clpm.icl @@ -0,0 +1,63 @@ +module clpm + +from StdFunc import flip, o +import StdFile +import StdList +import StdOverloaded +import StdString + +import Control.Applicative +import Control.Monad +import Data.Error +from Data.Func import $ +import Data.Functor +import Data.Maybe +import Data.Tuple +from Text import instance + String +import Text.JSON + +import System.CommandLine +import System.File + +import CLPM.Package + +FILENAME :== "clpm.json" + +:: Arguments + = { package_file :: String + } + +instance zero Arguments +where + zero + = { package_file = FILENAME + } + +Start w +# (io,w) = stdio w +# ((missed, args), w) = appFst (parseArgs [] zero o tl) $ getCommandLine w +| not (isEmpty missed) + # io = foldr (flip (<<<)) io ["Unknown option: " + m + "\n" \\ m <- missed] + # (_,w) = fclose io w + = w +# (pkg,w) = readPackage args.package_file w +| isNothing pkg + # io = io <<< "Could not parse " <<< args.package_file <<< '\n' + # (_,w) = fclose io w + = w +# pkg = fromJust pkg +# io = io <<< pkg <<< '\n' +# (_,w) = fclose io w += w + +parseArgs :: [String] Arguments [String] -> ([String], Arguments) +parseArgs miss args [] + = (miss, args) +parseArgs miss args ["-p":name:rest] + = parseArgs miss {args & package_file = name} rest +parseArgs miss args [a:rest] + = parseArgs [a:miss] args rest + +readPackage :: String -> *World -> *(Maybe Package, *World) +readPackage f = appFst parse o readFile f +where parse = join o fmap (fmap toPackage o fromJSON o fromString) o error2mb |