src/Nix/Options/Parser.hs: m upd alignment

This commit is contained in:
Anton-Latukha 2020-08-25 21:34:21 +03:00 committed by Anton Latukha
parent 38215317b9
commit 2dc211314e

View file

@ -28,146 +28,167 @@ argPair = option $ str >>= \s -> case Text.findIndex (== '=') s of
nixOptions :: UTCTime -> Parser Options nixOptions :: UTCTime -> Parser Options
nixOptions current = nixOptions current =
Options Options
<$> (fromMaybe Informational <$> optional <$> (fromMaybe Informational <$>
optional
(option (option
(do (do
a <- str a <- str
if all isDigit a if all isDigit a
then pure $ decodeVerbosity (read a) then pure $ decodeVerbosity (read a)
else fail "Argument to -v/--verbose must be a number" else fail "Argument to -v/--verbose must be a number"
) )
(short 'v' <> long "verbose" <> help "Verbose output")
( short 'v'
<> long "verbose"
<> help "Verbose output"
)
) )
) )
<*> switch <*> switch
( long "trace" ( long "trace"
<> help <> help "Enable tracing code (even more can be seen if built with --flags=tracing)"
"Enable tracing code (even more can be seen if built with --flags=tracing)" )
)
<*> switch <*> switch
(long "thunks" <> help ( long "thunks"
"Enable reporting of thunk tracing as well as regular evaluation" <> help "Enable reporting of thunk tracing as well as regular evaluation"
) )
<*> switch <*> switch
( long "values" ( long "values"
<> help "Enable reporting of value provenance in error messages" <> help "Enable reporting of value provenance in error messages"
) )
<*> switch <*> switch
( long "scopes" ( long "scopes"
<> help "Enable reporting of scopes in evaluation traces" <> help "Enable reporting of scopes in evaluation traces"
) )
<*> optional <*> optional
(strOption (strOption
( long "reduce" ( long "reduce"
<> help <> help "When done evaluating, output the evaluated part of the expression to FILE"
"When done evaluating, output the evaluated part of the expression to FILE"
)
) )
)
<*> switch <*> switch
(long "reduce-sets" <> help ( long "reduce-sets"
"Reduce set members that aren't used; breaks if hasAttr is used" <> help "Reduce set members that aren't used; breaks if hasAttr is used"
) )
<*> switch <*> switch
(long "reduce-lists" <> help ( long "reduce-lists"
"Reduce list members that aren't used; breaks if elemAt is used" <> help "Reduce list members that aren't used; breaks if elemAt is used"
) )
<*> switch <*> switch
( long "parse" ( long "parse"
<> help "Whether to parse the file (also the default right now)" <> help "Whether to parse the file (also the default right now)"
) )
<*> switch <*> switch
( long "parse-only" ( long "parse-only"
<> help "Whether to parse only, no pretty printing or checking" <> help "Whether to parse only, no pretty printing or checking"
) )
<*> switch (long "find" <> help "If selected, find paths within attr trees") <*> switch
( long "find"
<> help "If selected, find paths within attr trees"
)
<*> optional <*> optional
(strOption (strOption
( long "find-file" ( long "find-file"
<> help "Look up the given files in Nix's search path" <> help "Look up the given files in Nix's search path"
)
) )
)
<*> switch <*> switch
( long "strict" ( long "strict"
<> help <> help "When used with --eval, recursively evaluate list elements and attributes"
"When used with --eval, recursively evaluate list elements and attributes" )
)
<*> switch (long "eval" <> help "Whether to evaluate, or just pretty-print")
<*> switch <*> switch
( long "json" ( long "eval"
<> help "Print the resulting value as an JSON representation" <> help "Whether to evaluate, or just pretty-print"
) )
<*> switch <*> switch
( long "xml" ( long "json"
<> help "Print the resulting value as an XML representation" <> help "Print the resulting value as an JSON representation"
) )
<*> switch
( long "xml"
<> help "Print the resulting value as an XML representation"
)
<*> optional <*> optional
(strOption (strOption
( short 'A' ( short 'A'
<> long "attr" <> long "attr"
<> help <> help "Select an attribute from the top-level Nix expression being evaluated"
"Select an attribute from the top-level Nix expression being evaluated"
)
) )
)
<*> many <*> many
(strOption (strOption
(short 'I' <> long "include" <> help ( short 'I'
"Add a path to the Nix expression search path" <> long "include"
) <> help "Add a path to the Nix expression search path"
) )
)
<*> switch <*> switch
( long "check" ( long "check"
<> help "Whether to check for syntax errors after parsing" <> help "Whether to check for syntax errors after parsing"
) )
<*> optional <*> optional
(strOption (strOption
( long "read" ( long "read"
<> help "Read in an expression tree from a binary cache" <> help "Read in an expression tree from a binary cache"
)
) )
)
<*> switch <*> switch
( long "cache" ( long "cache"
<> help "Write out the parsed expression tree to a binary cache" <> help "Write out the parsed expression tree to a binary cache"
) )
<*> switch <*> switch
( long "repl" ( long "repl"
<> help "After performing any indicated actions, enter the REPL" <> help "After performing any indicated actions, enter the REPL"
) )
<*> switch <*> switch
( long "ignore-errors" ( long "ignore-errors"
<> help "Continue parsing files, even if there are errors" <> help "Continue parsing files, even if there are errors"
) )
<*> optional <*> optional
(strOption (strOption
(short 'E' <> long "expr" <> help "Expression to parse or evaluate") ( short 'E'
) <> long "expr"
<> help "Expression to parse or evaluate")
)
<*> many <*> many
(argPair (argPair
(long "arg" <> help "Argument to pass to an evaluated lambda") ( long "arg"
) <> help "Argument to pass to an evaluated lambda")
)
<*> many <*> many
(argPair (argPair
( long "argstr" ( long "argstr"
<> help "Argument string to pass to an evaluated lambda" <> help "Argument string to pass to an evaluated lambda"
)
) )
)
<*> optional <*> optional
(strOption (strOption
(short 'f' <> long "file" <> help ( short 'f'
"Parse all of the files given in FILE; - means stdin" <> long "file"
) <> help "Parse all of the files given in FILE; - means stdin"
) )
)
<*> option <*> option
(parseTimeOrError True defaultTimeLocale "%Y/%m/%d %H:%M:%S" <$> str) (parseTimeOrError True defaultTimeLocale "%Y/%m/%d %H:%M:%S" <$> str)
(long "now" <> value current <> help ( long "now"
"Set current time for testing purposes" <> value current
<> help "Set current time for testing purposes"
)
<*> many
(strArgument
( metavar "FILE"
<> help "Path of file to parse"
) )
<*> many (strArgument (metavar "FILE" <> help "Path of file to parse")) )
versionOpt :: Parser (a -> a) versionOpt :: Parser (a -> a)
versionOpt = infoOption versionOpt = infoOption
(showVersion version) (showVersion version)
( long "version" ( long "version"
<> help "Show release version" <> help "Show release version"
) )
nixOptionsInfo :: UTCTime -> ParserInfo Options nixOptionsInfo :: UTCTime -> ParserInfo Options
nixOptionsInfo current = info (helper <*> versionOpt <*> nixOptions current) nixOptionsInfo current = info (helper <*> versionOpt <*> nixOptions current)