From e835e6ed7245320b451bb9392487391dd91df8f9 Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Thu, 16 Mar 2017 18:05:15 +0530 Subject: [PATCH] Make FileUploader to use positional argument. (#32) --- README.md | 20 ++++++++++---------- examples/FileUploader.hs | 18 +++++++++--------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 824f8ac..ce3c17e 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ stack haddock {-# Language OverloadedStrings, ScopedTypeVariables #-} import Network.Minio -import Control.Monad.Catch (catch) +import Control.Monad.Catch (catchIf) import Control.Monad.IO.Class (liftIO) import Options.Applicative import Prelude @@ -66,19 +66,21 @@ import Data.Text (pack) -- -- optparse-applicative package based command-line parsing. -fileNameOpts :: Parser FilePath -fileNameOpts = strOption - (long "filename" - <> metavar "FILENAME" +fileNameArgs :: Parser FilePath +fileNameArgs = strArgument + (metavar "FILENAME" <> help "Name of file to upload to AWS S3 or a Minio server") cmdParser = info - (helper <*> fileNameOpts) + (helper <*> fileNameArgs) (fullDesc <> progDesc "FileUploader" <> header "FileUploader - a simple file-uploader program using minio-hs") +ignoreMinioErr :: ServiceErr -> Minio () +ignoreMinioErr = return . const () + main :: IO () main = do @@ -90,9 +92,7 @@ main = do res <- runResourceT $ runMinio minioPlayCI $ do -- Make a bucket; catch bucket already exists exception if thrown. - catch - (makeBucket bucket Nothing) - (\(_ :: MError) -> liftIO $ putStrLn "Bucket already exists, proceeding with upload file.") + catchIf (== BucketAlreadyOwnedByYou) (makeBucket bucket Nothing) ignoreMinioErr -- Upload filepath to bucket; object is derived from filepath. fPutObject bucket object filepath @@ -105,7 +105,7 @@ main = do ### Run fileuploader ``` sh -./FileUploader.hs --filename "path/to/my/file" +./FileUploader.hs "path/to/my/file" ``` diff --git a/examples/FileUploader.hs b/examples/FileUploader.hs index 25bfeb3..6798554 100755 --- a/examples/FileUploader.hs +++ b/examples/FileUploader.hs @@ -21,7 +21,7 @@ {-# Language OverloadedStrings, ScopedTypeVariables #-} import Network.Minio -import Control.Monad.Catch (catch) +import Control.Monad.Catch (catchIf) import Control.Monad.IO.Class (liftIO) import Options.Applicative import Prelude @@ -36,19 +36,21 @@ import Data.Text (pack) -- -- optparse-applicative package based command-line parsing. -fileNameOpts :: Parser FilePath -fileNameOpts = strOption - (long "filename" - <> metavar "FILENAME" +fileNameArgs :: Parser FilePath +fileNameArgs = strArgument + (metavar "FILENAME" <> help "Name of file to upload to AWS S3 or a Minio server") cmdParser = info - (helper <*> fileNameOpts) + (helper <*> fileNameArgs) (fullDesc <> progDesc "FileUploader" <> header "FileUploader - a simple file-uploader program using minio-hs") +ignoreMinioErr :: ServiceErr -> Minio () +ignoreMinioErr = return . const () + main :: IO () main = do @@ -60,9 +62,7 @@ main = do res <- runResourceT $ runMinio minioPlayCI $ do -- Make a bucket; catch bucket already exists exception if thrown. - catch - (makeBucket bucket Nothing) - (\(_ :: MinioErr) -> liftIO $ putStrLn "Bucket already exists, proceeding with upload file.") + catchIf (== BucketAlreadyOwnedByYou) (makeBucket bucket Nothing) ignoreMinioErr -- Upload filepath to bucket; object is derived from filepath. fPutObject bucket object filepath