Skip to content

Commit

Permalink
Add --version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Maclean committed Oct 29, 2018
1 parent 97881e0 commit 564821a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import Print (toSql)
import Reverse
import Validate

version :: String
version = "0.1.0.0"

main :: IO ()
main = do
options <- execParser parseOptions
Expand Down Expand Up @@ -72,7 +75,7 @@ instance ToJSON YamlOutput where

parseOptions :: ParserInfo Options
parseOptions =
info (parser <**> helper) $
info (parser <**> helper <**> versionOption) $
fullDesc <> progDescDoc (Just description) <> header "sddl"
where
parser =
Expand All @@ -83,7 +86,9 @@ parseOptions =
(long "reverse" <> short 'r' <> help "Generate reverse migration") <*>
option
(maybeReader parseFormat)
(long "format" <> short 'f' <> metavar "FORMAT" <> help "output format")
(long "format" <> short 'f' <> metavar "FORMAT" <> help "Output format. One of {sql, yaml}")
versionOption :: Parser (a -> a)
versionOption = infoOption version (long "version" <> help "Show version")

parseFormat :: String -> Maybe Format
parseFormat =
Expand Down Expand Up @@ -121,5 +126,5 @@ description = PrettyPrint.string $ unlines
, " - type: SQL type"
, " - null: (boolean) whether the column is nullable"
, ""
, "SQL type is one of {text timestamp integer boolean json}"
, "SQL type is one of {text, timestamp, integer, boolean, json}"
]
2 changes: 1 addition & 1 deletion src/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ instance FromJSON SqlType where
"integer" -> pure SInteger
"boolean" -> pure SBoolean
"json" -> pure SJson
_ -> fail "must be one of {text timestamp integer boolean json}"
_ -> fail "must be one of {text, timestamp, integer, boolean, json}"

data Statement =
AddColumn { table :: String, column :: String, type_ :: SqlType }
Expand Down

0 comments on commit 564821a

Please sign in to comment.