Commit 50550928 authored by Camil Staps's avatar Camil Staps 🍃

Nuke --beautify and --output options

parent 02c7299a
module saplcg
import StdBool
import StdFile
import StdList
import StdString
import StdTuple
import Data.Error
from Data.Func import $, mapSt, seqSt
from Data.Map import fromList, newMap
import Data.Maybe
import System.CommandLine
import System.Environment
import System.File
import System.FilePath
import System.Options
import System.Process
import Text
import Sapl.Target.CleanFlavour
......@@ -27,8 +20,6 @@ import Sapl.Target.JS.CodeGeneratorJS
, libraries :: ![String]
, modules :: ![String]
, trampoline :: !Bool
, output :: !Maybe FilePath
, beautify :: !Maybe FilePath
}
defaultOptions :: Options
......@@ -38,8 +29,6 @@ defaultOptions =
, libraries = ["StdEnv"]
, modules = []
, trampoline = False
, output = Nothing
, beautify = Nothing
}
defaultParserState :: ParserState
......@@ -57,7 +46,7 @@ defaultParserState =
Start w
# ([prog:args],w) = getCommandLine w
# noUsage = Nothing
# usage = Just ("Usage: " +++ prog +++ " [OPTIONS] -o OUTPUT MOD [MOD..]")
# usage = Just ("Usage: " +++ prog +++ " [OPTIONS] MOD [MOD..]")
# opts = defaultOptions
# (home,w) = getEnvironmentVariable "CLEAN_HOME" w
......@@ -66,27 +55,14 @@ Start w
# opts = fromOk opts
| isEmpty opts.modules = error usage "No modules given" w
| isNothing opts.output = error usage "No output file given" w
| isNothing opts.output && isJust opts.beautify = error Nothing "Cannot use beautifier when outputting to stdout" w
# (files,(pst,w)) = mapSt (parseModule opts) opts.modules (defaultParserState,w)
| any isNothing files = error Nothing "Parsing failed" w
# (ok,out,w) = case opts.output of
Nothing -> let (f,w`) = stdio w in (True,f,w`)
Just o -> fopen o FWriteText w
# (out,w) = stdio w
# (out,_,w) = seqSt (genCode opts) [f \\ Just f <- files] (out,pst,w)
# (_,w) = fclose out w
# w = case opts.beautify of
Nothing -> w
Just beautify
# (err,w) = callProcess beautify [out,"-o",out] Nothing w
with out = fromJust opts.output
| isError err
-> error Nothing ("Error while beautifying: " +++ snd (fromError err)) w
-> w
= w
where
optionDescription :: Option Options
......@@ -110,16 +86,6 @@ where
"--trampoline"
(\opts -> Ok {opts & trampoline=True})
"Turn on trampoline code"
, Shorthand "-b" "--beautify" $ Option
"--beautify"
(\b opts -> Ok {opts & beautify=Just b})
"PROG"
"Name or path of a JavaScript beautifier"
, Shorthand "-o" "--output" $ Option
"--output"
(\f opts -> Ok {opts & output=Just f})
"OUTPUT"
"File to write output to"
, Operand False
(\m opts -> Just $ Ok {opts & modules=opts.modules ++ [m]})
"MODULE"
......
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