diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/Main.hs | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/cli/Main.hs b/cli/Main.hs index 643fd5f..f40966c 100644 --- a/cli/Main.hs +++ b/cli/Main.hs @@ -1,21 +1,26 @@ {-# LANGUAGE QuasiQuotes #-} -module Main where +module Main + ( main + ) where +import qualified Data.ByteString as BS +import qualified Data.ByteString.Char8 as C import Data.Version (showVersion) import Paths_zerobin (version) -- from cabal +import qualified System.Console.Docopt.NoTH as O import System.Environment (getArgs) import System.Exit (exitFailure) -import System.IO (stderr, hPutStrLn) +import System.IO (hPutStrLn, stderr) import Text.RawString.QQ (r) -import Web.ZeroBin (share, Expiration(..)) -import qualified Data.ByteString as BS -import qualified Data.ByteString.Char8 as C -import qualified System.Console.Docopt.NoTH as O +import Web.ZeroBin (Expiration(..), share) usage :: String -usage = "zerobin " ++ showVersion version - ++ " pastes to 0bin services" ++ [r| +usage = + "zerobin " ++ + showVersion version ++ + " pastes to 0bin services" ++ + [r| zerobin prints URI to be shared or error message See http://0bin.net and https://paste.ec @@ -37,15 +42,14 @@ Examples: zerobin -b http://0bin.net hello paste to 0bin.net |] - getExpiration :: String -> Maybe Expiration getExpiration e = case e of - "once" -> Just Once - "day" -> Just Day - "week" -> Just Week + "once" -> Just Once + "day" -> Just Day + "week" -> Just Week "month" -> Just Month - _ -> Nothing + _ -> Nothing die :: String -> IO () die msg = do @@ -63,14 +67,13 @@ main = do doco <- O.parseUsageOrExit usage args <- O.parseArgsOrExit doco =<< getArgs if args `O.isPresent` O.longOption "help" - then putStrLn $ O.usage doco - else do - let get = O.getArgOrExitWith doco - bin <- args `get` O.longOption "bin" - expire <- args `get` O.longOption "expire" - text <- args `get` O.argument "TEXT" - cnt <- getContent (args `O.isPresent` O.longOption "file") text - case getExpiration expire of - Nothing -> die "invalid value for expiration" - Just e -> share bin e cnt >>= putStrLn - + then putStrLn $ O.usage doco + else do + let get = O.getArgOrExitWith doco + bin <- args `get` O.longOption "bin" + expire <- args `get` O.longOption "expire" + text <- args `get` O.argument "TEXT" + cnt <- getContent (args `O.isPresent` O.longOption "file") text + case getExpiration expire of + Nothing -> die "invalid value for expiration" + Just e -> share bin e cnt >>= putStrLn |