Skip to content

Commit

Permalink
Add option --numeric-version and rededicate -v to future --verbose
Browse files Browse the repository at this point in the history
Closes #250.
  • Loading branch information
andreasabel committed Nov 3, 2023
1 parent ff4832e commit 48f6cfb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

* Add option `--numeric-version`.
* Remove deprecated `-v` as alias for `--version`.
* Add `-v` as placeholder for a future `--verbose` option.

## Changes in 3.4.0.1

* Address new `x-partial` warning of GHC 9.8.
Expand Down
27 changes: 20 additions & 7 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,26 @@ alexOpenFile file mode = do
-- `main' decodes the command line arguments and calls `alex'.

main:: IO ()
main = do
args <- getArgs
case getOpt Permute argInfo args of
main = do
args <- getArgs
case getOpt Permute argInfo args of
(cli,_,[]) | DumpHelp `elem` cli -> do
prog <- getProgramName
bye (usageInfo (usageHeader prog) argInfo)
(cli,_,[]) | DumpVersion `elem` cli ->
bye copyright
(cli,_,[]) | DumpNumericVersion `elem` cli ->
bye projectVersion
(cli,_,[]) | OptVerbose `elem` cli ->
failure "Option '--verbose' not yet implemented"
(cli,[file],[]) ->
runAlex cli file
(_,_,errors) -> do
prog <- getProgramName
die (concat errors ++ usageInfo (usageHeader prog) argInfo)
(_,_,errors) ->
failure $ concat errors
where
failure err = do
prog <- getProgramName
die (err ++ usageInfo (usageHeader prog) argInfo)

projectVersion :: String
projectVersion = showVersion version
Expand Down Expand Up @@ -462,8 +469,10 @@ data CLIFlags
| OptTabSize String
| OptTemplateDir FilePath
| OptLatin1
| OptVerbose
| DumpHelp
| DumpVersion
| DumpNumericVersion
deriving Eq

argInfo :: [OptDescr CLIFlags]
Expand All @@ -482,10 +491,14 @@ argInfo = [
"set tab size to be used in the generated lexer (default: 8)",
Option ['d'] ["debug"] (NoArg OptDebugParser)
"produce a debugging scanner",
Option ['v'] ["verbose"] (NoArg OptVerbose)
"be verbose (not yet implemented)",
Option ['?'] ["help"] (NoArg DumpHelp)
"display this help and exit",
Option ['V','v'] ["version"] (NoArg DumpVersion) -- ToDo: -v is deprecated!
Option ['V'] ["version"] (NoArg DumpVersion)
"output version information and exit"
,Option [] ["numeric-version"] (NoArg DumpNumericVersion)
"output the version number and exit"
]

-- -----------------------------------------------------------------------------
Expand Down

0 comments on commit 48f6cfb

Please sign in to comment.