-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
Control.Applicative.Alternative
capabilities, and introduce `Al…
…ternative.optional` field (#86) * add `Alternable` typeclass thing and `Alternative.optional` function * update optparse example with `optional` field example
- Loading branch information
1 parent
551133c
commit c8dc4c4
Showing
2 changed files
with
15 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
-- Includes example of Semigroup. | ||
data Opts = Opts { | ||
quiet :: Bool, | ||
filePath :: Text | ||
filePath :: Maybe Text | ||
} | ||
options = | ||
(\quiet path -> Main.Opts { quiet = quiet, filePath = path }) | ||
<$> Options.switch (Flag.long "quiet" <> Flag.help "Be quiet?") | ||
<*> Options.strOption (Option.long "path" <> Option.help "The filepath to export") | ||
<*> (Alternative.optional $ Options.strOption (Option.long "path" <> Option.help "The filepath to export")) | ||
main = do | ||
opts <- Options.execParser (Options.info (Main.options <**> Options.helper) Options.fullDesc) | ||
Text.putStrLn $ Record.get @"filePath" opts | ||
Text.putStrLn $ Maybe.maybe "No file path" Function.id (Record.get @"filePath" opts) | ||
Text.putStrLn $ Show.show @Bool $ Record.get @"quiet" opts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters