From 0d18329354b1fdb04bc245f86047094c5895999e Mon Sep 17 00:00:00 2001 From: Joscha Date: Tue, 19 Nov 2019 10:59:30 +0000 Subject: [PATCH] Add help for formatting options --- app/MimaRun/Main.hs | 2 +- src/Mima/Options.hs | 47 ++++++++++++++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/app/MimaRun/Main.hs b/app/MimaRun/Main.hs index 7c3259e..9bf2665 100644 --- a/app/MimaRun/Main.hs +++ b/app/MimaRun/Main.hs @@ -71,7 +71,7 @@ settingsParser = Settings <*> formatConfigParser opts :: ParserInfo Settings -opts = info (helper <*> settingsParser) $ fullDesc <> failureCode 1 +opts = info (helper <*> settingsParser) $ fullDesc <> failureCode 1 <> footer formatConfigHelp {- Loading the flag file -} diff --git a/src/Mima/Options.hs b/src/Mima/Options.hs index 4b9f8ff..3aa2b72 100644 --- a/src/Mima/Options.hs +++ b/src/Mima/Options.hs @@ -1,5 +1,6 @@ module Mima.Options ( switchWithNo + , formatConfigHelp , formatConfigParser ) where @@ -8,21 +9,37 @@ import Options.Applicative import Mima.Format.State switchWithNo :: String -> Bool -> Mod FlagFields Bool -> Parser Bool -switchWithNo name True fields = flag' False (long ("no-" ++ name) <> fields) - <|> flag True True (long name <> fields) -switchWithNo name False fields = flag' True (long name <> fields) - <|> flag False False (long ("no-" ++ name) <> fields) +switchWithNo name defaultValue fields + | defaultValue = flag' False noMod <|> flag True True yesMod + | otherwise = flag' True yesMod <|> flag False False noMod + where + yesMod = long name <> hidden <> fields + noMod = long ("no-" ++ name) <> hidden + +formatConfigHelp :: String +formatConfigHelp = "All options labeled with 'Formatting:' can be negated by prepending 'no-' to their name (e. g. '--sparse' becomes '--no-sparse')." formatConfigParser :: Parser FormatConfig formatConfigParser = FormatConfig - <$> switchWithNo "sparse" False mempty - <*> switchWithNo "register-flags" True mempty - <*> switchWithNo "memory-flags" True mempty - <*> switchWithNo "address-dec" True mempty - <*> switchWithNo "address-hex" True mempty - <*> switchWithNo "address-bin" False mempty - <*> switchWithNo "word-dec" True mempty - <*> switchWithNo "word-hex" True mempty - <*> switchWithNo "word-bin" False mempty - <*> switchWithNo "instructions" True mempty - <*> switchWithNo "labels" True mempty + <$> switchWithNo "sparse" False + (help "Formatting: Omit uninteresting addresses") + <*> switchWithNo "register-flags" True + (help "Formatting: For each address, show all the memory flags that are active for that address") + <*> switchWithNo "memory-flags" True + (help "Formatting: For each address, show all registers currently pointing to that address") + <*> switchWithNo "address-dec" True + (help "Formatting: Display addresses in decimal") + <*> switchWithNo "address-hex" True + (help "Formatting: Display addresses in hexadecimal") + <*> switchWithNo "address-bin" False + (help "Formatting: Display addresses in binary") + <*> switchWithNo "word-dec" True + (help "Formatting: Display words in decimal") + <*> switchWithNo "word-hex" True + (help "Formatting: Display words in hexadecimal") + <*> switchWithNo "word-bin" False + (help "Formatting: Display words in binary") + <*> switchWithNo "instructions" True + (help "Formatting: Show instructions") + <*> switchWithNo "labels" True + (help "Formatting: Show labels from the symbol file")