mirror of
https://github.com/github/semantic.git
synced 2024-12-27 17:05:33 +03:00
create a boolean option to print with color
This commit is contained in:
parent
44db35aba0
commit
51ce6dd303
@ -16,6 +16,7 @@ import Text.Pretty.Simple (pPrint)
|
|||||||
|
|
||||||
data SemanticAST = SemanticAST
|
data SemanticAST = SemanticAST
|
||||||
{ format :: Format
|
{ format :: Format
|
||||||
|
, color :: Bool
|
||||||
, source :: Either FilePath Prelude.String
|
, source :: Either FilePath Prelude.String
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,6 +25,10 @@ parseAST = SemanticAST
|
|||||||
<$> option auto
|
<$> option auto
|
||||||
( long "format"
|
( long "format"
|
||||||
<> help "Specify desired output: show, json, sexpression" )
|
<> help "Specify desired output: show, json, sexpression" )
|
||||||
|
<*> switch
|
||||||
|
( long "color"
|
||||||
|
<> help "Print with color: --color"
|
||||||
|
)
|
||||||
<*> (Left <$> strOption
|
<*> (Left <$> strOption
|
||||||
( long "sourceFile"
|
( long "sourceFile"
|
||||||
<> metavar "FILEPATH"
|
<> metavar "FILEPATH"
|
||||||
@ -38,7 +43,7 @@ main :: IO ()
|
|||||||
main = generateAST =<< execParser opts
|
main = generateAST =<< execParser opts
|
||||||
|
|
||||||
generateAST :: SemanticAST -> IO ()
|
generateAST :: SemanticAST -> IO ()
|
||||||
generateAST (SemanticAST format source) = do
|
generateAST (SemanticAST format _ source) = do
|
||||||
bytestring <- case source of
|
bytestring <- case source of
|
||||||
Left filePath -> do
|
Left filePath -> do
|
||||||
Data.ByteString.readFile filePath
|
Data.ByteString.readFile filePath
|
||||||
@ -58,3 +63,12 @@ opts = info (parseAST <**> helper)
|
|||||||
-- TODO: Define formats for json, sexpression, etc.
|
-- TODO: Define formats for json, sexpression, etc.
|
||||||
data Format = Show | Pretty
|
data Format = Show | Pretty
|
||||||
deriving (Read)
|
deriving (Read)
|
||||||
|
|
||||||
|
-- CLI feature request -> implementation
|
||||||
|
-- add a boolean flag that represents "print with color" or not
|
||||||
|
-- `semantic-ast --format=Pretty --no-color` won't show those pretty colors
|
||||||
|
-- adding a boolean field to represent whether color is on or not
|
||||||
|
-- and use an appropriate construct in optparse-applicative to indicate that `--color` means True
|
||||||
|
-- and -- no-color means false, and not provided means True
|
||||||
|
|
||||||
|
-- The difference between auto and string option
|
||||||
|
Loading…
Reference in New Issue
Block a user