Revision a7ea861a
b/htools/Ganeti/HTools/CLI.hs | ||
---|---|---|
31 | 31 |
( Options(..) |
32 | 32 |
, OptType |
33 | 33 |
, parseOpts |
34 |
, parseYesNo |
|
34 | 35 |
, parseISpecString |
35 | 36 |
, shTemplate |
36 | 37 |
, defaultLuxiSocket |
... | ... | |
411 | 412 |
-- * Functions |
412 | 413 |
|
413 | 414 |
-- | Helper for parsing a yes\/no command line flag. |
414 |
parseYesNo :: Bool -- ^ Default whalue (when we get a @Nothing@)
|
|
415 |
parseYesNo :: Bool -- ^ Default value (when we get a @Nothing@)
|
|
415 | 416 |
-> Maybe String -- ^ Parameter value |
416 | 417 |
-> Result Bool -- ^ Resulting boolean value |
417 | 418 |
parseYesNo v Nothing = return v |
418 | 419 |
parseYesNo _ (Just "yes") = return True |
419 | 420 |
parseYesNo _ (Just "no") = return False |
420 |
parseYesNo _ (Just s) = fail $ "Invalid choice '" ++ s ++
|
|
421 |
"', pass one of 'yes' or 'no'"
|
|
421 |
parseYesNo _ (Just s) = fail ("Invalid choice '" ++ s ++
|
|
422 |
"', pass one of 'yes' or 'no'")
|
|
422 | 423 |
|
423 | 424 |
-- | Usage info. |
424 | 425 |
usageHelp :: String -> [OptType] -> String |
b/htools/Ganeti/HTools/QC.hs | ||
---|---|---|
1478 | 1478 |
Types.Ok v -> failTest $ "Expected failure, got " ++ show v |
1479 | 1479 |
_ -> property True |
1480 | 1480 |
|
1481 |
-- | Test parseYesNo. |
|
1482 |
prop_CLI_parseYesNo def testval val = |
|
1483 |
forAll (elements [val, "yes", "no"]) $ \actual_val -> |
|
1484 |
if testval |
|
1485 |
then CLI.parseYesNo def Nothing ==? Types.Ok def |
|
1486 |
else let result = CLI.parseYesNo def (Just actual_val) |
|
1487 |
in if actual_val `elem` ["yes", "no"] |
|
1488 |
then result ==? Types.Ok (actual_val == "yes") |
|
1489 |
else property $ Types.isBad result |
|
1490 |
|
|
1481 | 1491 |
testSuite "CLI" |
1482 | 1492 |
[ 'prop_CLI_parseISpec |
1483 | 1493 |
, 'prop_CLI_parseISpecFail |
1494 |
, 'prop_CLI_parseYesNo |
|
1484 | 1495 |
] |
Also available in: Unified diff