File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,7 @@ executable Fuzzy
165165 , text
166166 , random
167167 , aeson
168+ , bytestring
168169
169170 hs-source-dirs : src
170171
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import qualified Data.Text as T
1212import System.Environment
1313import System.Random
1414import Text.Printf
15+ import qualified Data.ByteString.Lazy as BS
1516
1617data FuzzParams = FuzzParams
1718 { fpFuzzCount :: Int
@@ -42,6 +43,9 @@ instance FromJSON FuzzParams where
4243readFuzzParams :: FilePath -> IO FuzzParams
4344readFuzzParams = fmap (either error id ) . eitherDecodeFileStrict
4445
46+ saveFuzzParams :: FuzzParams -> FilePath -> IO ()
47+ saveFuzzParams params filePath = BS. writeFile filePath $ encode params
48+
4549defaultFuzzParams :: FuzzParams
4650defaultFuzzParams =
4751 FuzzParams
@@ -132,8 +136,15 @@ fuzz params = do
132136 printf " Successes: %d\n " $ length $ filter id report
133137
134138mainWithArgs :: [String ] -> IO ()
135- mainWithArgs (fuzzParamsPath: _) = readFuzzParams fuzzParamsPath >>= fuzz
136- mainWithArgs _ = error " Usage: Fuzz <fuzz.json>"
139+ mainWithArgs (" genconf" : configFilePath: _) = do
140+ saveFuzzParams defaultFuzzParams configFilePath
141+ printf " Generated default configuration at %s" configFilePath
142+ mainWithArgs (" runconf" : fuzzParamsPath: _) = readFuzzParams fuzzParamsPath >>= fuzz
143+ mainWithArgs _ =
144+ error
145+ " Usage: \n \
146+ \ Fuzz genconf <fuzz.json>\n \
147+ \ Fuzz runconf <fuzz.json>"
137148
138149main :: IO ()
139150main = getArgs >>= mainWithArgs
You can’t perform that action at this time.
0 commit comments