diff options
Diffstat (limited to 'tprint/src')
-rw-r--r-- | tprint/src/Options.hs | 24 | ||||
-rw-r--r-- | tprint/src/Options/Utils.hs | 1 |
2 files changed, 18 insertions, 7 deletions
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 () | |||
26 | import Paths_tprint (version) | 26 | import Paths_tprint (version) |
27 | import Data.Version (showVersion) | 27 | import Data.Version (showVersion) |
28 | 28 | ||
29 | import Data.Maybe | ||
30 | import Data.Monoid | ||
29 | import Data.Bifunctor (Bifunctor(..)) | 31 | import Data.Bifunctor (Bifunctor(..)) |
30 | 32 | ||
33 | import System.Environment (lookupEnv) | ||
34 | |||
31 | data TPrint = TPrint | 35 | data TPrint = TPrint |
32 | { baseUrl :: BaseUrl | 36 | { baseUrl :: BaseUrl |
33 | , dryRun :: Bool | 37 | , dryRun :: Bool |
@@ -149,12 +153,15 @@ pOperation = hsubparser $ mconcat [ command "printers" cmdPrinters | |||
149 | ) (progDesc "Interact with drafts") | 153 | ) (progDesc "Interact with drafts") |
150 | ] | 154 | ] |
151 | 155 | ||
152 | pTPrint :: Parser TPrint | 156 | pTPrint :: IO (Parser TPrint) |
153 | 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) | 157 | pTPrint = do |
154 | <*> switch (long "dry-run" <> short 'n' <> help "Don't send any requests that would be expected to change the servers state") | 158 | baseUrl <- parseBaseUrl =<< (fromMaybe "http://localhost:3000/" <$> lookupEnv "TPRINT_BASEURL") |
155 | <*> pOutput | 159 | return $ |
156 | <*> pOperation | 160 | 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) |
157 | <*> switch (long "dump-options" <> internal) | 161 | <*> switch (long "dry-run" <> short 'n' <> help "Don't send any requests that would be expected to change the servers state") |
162 | <*> pOutput | ||
163 | <*> pOperation | ||
164 | <*> switch (long "dump-options" <> internal) | ||
158 | 165 | ||
159 | pOutput :: Parser Output | 166 | pOutput :: Parser Output |
160 | pOutput = (,) <$> pOutputFormat <*> pSink | 167 | pOutput = (,) <$> pOutputFormat <*> pSink |
@@ -177,4 +184,7 @@ pInput = (,) <$> pInputFormat <*> pSource | |||
177 | rSource' x = ReadFile x | 184 | rSource' x = ReadFile x |
178 | 185 | ||
179 | withArgs :: (TPrint -> IO a) -> IO a | 186 | withArgs :: (TPrint -> IO a) -> IO a |
180 | withArgs a = customExecParser (prefs $ showHelpOnError) (info pTPrint $ header ("tprint " ++ showVersion version) <> progDesc "A cli for Thermoprint.Client") >>= a | 187 | withArgs a = do |
188 | pTPrint' <- pTPrint | ||
189 | customExecParser (prefs $ showHelpOnError) (info pTPrint' $ header ("tprint " ++ showVersion version) <> progDesc "A cli for Thermoprint.Client") >>= a | ||
190 | |||
diff --git a/tprint/src/Options/Utils.hs b/tprint/src/Options/Utils.hs index 237aa56..3fae250 100644 --- a/tprint/src/Options/Utils.hs +++ b/tprint/src/Options/Utils.hs | |||
@@ -13,6 +13,7 @@ import Options.Applicative | |||
13 | import Data.Text (Text) | 13 | import Data.Text (Text) |
14 | import qualified Data.Text as T (pack) | 14 | import qualified Data.Text as T (pack) |
15 | 15 | ||
16 | import Data.Monoid | ||
16 | import Data.Char | 17 | import Data.Char |
17 | import Data.Maybe | 18 | import Data.Maybe |
18 | import Data.List | 19 | import Data.List |