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

Nuke --beautify and --output options

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