From 7065a8cc1b8b01cd32d4b1d5317b323fec5238bd Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 7 Mar 2017 14:16:21 +0100 Subject: Bump versions --- tprint/src/Options.hs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'tprint/src/Options.hs') diff --git a/tprint/src/Options.hs b/tprint/src/Options.hs index e146f91..703c23b 100644 --- a/tprint/src/Options.hs +++ b/tprint/src/Options.hs @@ -26,8 +26,12 @@ import Instances () import Paths_tprint (version) import Data.Version (showVersion) +import Data.Maybe +import Data.Monoid import Data.Bifunctor (Bifunctor(..)) +import System.Environment (lookupEnv) + data TPrint = TPrint { baseUrl :: BaseUrl , dryRun :: Bool @@ -149,12 +153,15 @@ pOperation = hsubparser $ mconcat [ command "printers" cmdPrinters ) (progDesc "Interact with drafts") ] -pTPrint :: Parser TPrint -pTPrint = TPrint <$> option (eitherReader $ first show . parseBaseUrl) (metavar "URL" <> long "baseurl" <> short 'u' <> help "Server to interact with" <> value (BaseUrl Http "localhost" 3000 "") <> showDefaultWith showBaseUrl) - <*> switch (long "dry-run" <> short 'n' <> help "Don't send any requests that would be expected to change the servers state") - <*> pOutput - <*> pOperation - <*> switch (long "dump-options" <> internal) +pTPrint :: IO (Parser TPrint) +pTPrint = do + baseUrl <- parseBaseUrl =<< (fromMaybe "http://localhost:3000/" <$> lookupEnv "TPRINT_BASEURL") + return $ + TPrint <$> option (eitherReader $ first show . parseBaseUrl) (metavar "URL" <> long "baseurl" <> short 'u' <> help "Server to interact with; also read from TPRINT_BASEURL when set" <> value baseUrl <> showDefaultWith showBaseUrl) + <*> switch (long "dry-run" <> short 'n' <> help "Don't send any requests that would be expected to change the servers state") + <*> pOutput + <*> pOperation + <*> switch (long "dump-options" <> internal) pOutput :: Parser Output pOutput = (,) <$> pOutputFormat <*> pSink @@ -177,4 +184,7 @@ pInput = (,) <$> pInputFormat <*> pSource rSource' x = ReadFile x withArgs :: (TPrint -> IO a) -> IO a -withArgs a = customExecParser (prefs $ showHelpOnError) (info pTPrint $ header ("tprint " ++ showVersion version) <> progDesc "A cli for Thermoprint.Client") >>= a +withArgs a = do + pTPrint' <- pTPrint + customExecParser (prefs $ showHelpOnError) (info pTPrint' $ header ("tprint " ++ showVersion version) <> progDesc "A cli for Thermoprint.Client") >>= a + -- cgit v1.2.3