Skip to content

Commit f0d8803

Browse files
Merge pull request #374 from ambiata/topic/coding-standards
mismi-cli: Apply coding standards
2 parents ed3a5d9 + 396b5ed commit f0d8803

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

mismi-cli/main/s3.hs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import BuildInfo_ambiata_mismi_cli
66
import DependencyInfo_ambiata_mismi_cli
77

88
import Control.Lens (over, set)
9-
import Control.Monad.IO.Class
10-
import Control.Monad.Trans.Resource
9+
import Control.Monad.IO.Class (MonadIO, liftIO)
10+
import Control.Monad.Trans.Resource (runResourceT)
1111

1212
import qualified Data.ByteString as BS
13-
import Data.Conduit
13+
import Data.Conduit ((=$=), ($$), ($$+-))
1414
import qualified Data.Conduit.List as DC
1515
import qualified Data.List as List
1616
import Data.Map (Map)
@@ -25,22 +25,23 @@ import qualified Mismi.OpenSSL as O
2525
import Mismi.S3
2626
import Mismi.S3.Amazonka (s3)
2727

28-
import Options.Applicative
29-
3028
import P hiding (All)
3129

32-
import System.IO
30+
import System.IO (BufferMode (..), FilePath, IO, hSetBuffering, print, stderr, stdout)
3331
import System.Environment (lookupEnv)
34-
import System.Exit
35-
import System.FilePath
36-
import System.Posix.Signals
37-
import System.Posix.Process
32+
import System.Exit (ExitCode (..), exitFailure, exitSuccess)
33+
import qualified System.FilePath as FP
34+
import System.Posix.Signals (Handler (..), installHandler, sigINT, sigQUIT, sigTERM)
35+
import System.Posix.Process (exitImmediately)
3836

3937
import Text.Printf (printf)
4038

41-
import X.Control.Monad.Trans.Either.Exit
39+
import X.Control.Monad.Trans.Either.Exit (orDie)
4240
import X.Control.Monad.Trans.Either (EitherT, eitherT, runEitherT, firstEitherT)
43-
import X.Options.Applicative
41+
import X.Options.Applicative (Completer, Parser, RunType (..), SafeCommand (..)
42+
, action, auto, command', flag, flag', help, long, metavar
43+
, pOption, option, short, value)
44+
import qualified X.Options.Applicative as XOA
4445

4546
data Recursive =
4647
NotRecursive
@@ -103,7 +104,7 @@ main = do
103104
installHandler s (Catch . void . exitImmediately $ ExitFailure 111) Nothing
104105

105106
f <- lookupEnv "AWS_FORCE"
106-
dispatch (mismi $ parseForce f) >>= \case
107+
XOA.dispatch (mismi $ parseForce f) >>= \case
107108
VersionCommand ->
108109
T.putStrLn ("s3: " <> T.pack buildInfoVersion) >> exitSuccess
109110
DependencyCommand ->
@@ -283,16 +284,16 @@ renderExit f =
283284

284285
optAppendFileName :: FilePath -> Key -> FilePath
285286
optAppendFileName f k = fromMaybe f $ do
286-
fp <- valueOrEmpty (hasTrailingPathSeparator f || takeFileName f == ".") (takeDirectory f)
287+
fp <- valueOrEmpty (FP.hasTrailingPathSeparator f || FP.takeFileName f == ".") (FP.takeDirectory f)
287288
bn <- basename k
288-
pure . combine fp $ T.unpack bn
289+
pure . FP.combine fp $ T.unpack bn
289290

290291
mismi :: Force -> Parser (SafeCommand Command)
291292
mismi f =
292-
safeCommand (commandP' f <|> deprecatedCommandP')
293+
XOA.safeCommand (commandP' f <|> deprecatedCommandP')
293294

294295
commandP' :: Force -> Parser Command
295-
commandP' f = subparser $
296+
commandP' f = XOA.subparser $
296297
command' "upload"
297298
"Upload a file to s3."
298299
(Upload <$> filepath' <*> address' <*> writeMode' f)
@@ -331,8 +332,8 @@ commandP' f = subparser $
331332
(List <$> address' <*> recursive')
332333

333334
deprecatedCommandP' :: Parser Command
334-
deprecatedCommandP' = subparser $
335-
internal <> command'
335+
deprecatedCommandP' = XOA.subparser $
336+
XOA.internal <> command'
336337
"read"
337338
"Read from an address. (Deprecated in favour of `s3 cat`.)"
338339
(Read <$> address')
@@ -371,26 +372,26 @@ detail' =
371372
<> help "Display only the combined total for a prefix."
372373

373374
address' :: Parser Address
374-
address' = argument (pOption s3Parser) $
375+
address' = XOA.argument (pOption s3Parser) $
375376
metavar "S3URI"
376377
<> help "An s3 uri, i.e. s3://bucket/prefix/key"
377-
<> completer addressCompleter
378+
<> XOA.completer addressCompleter
378379

379380
outputAddress' :: Parser Address
380381
outputAddress' = option (pOption s3Parser) $
381382
long "output"
382383
<> metavar "S3URI"
383384
<> help "An s3 uri, i.e. s3://bucket/prefix/key"
384-
<> completer addressCompleter
385+
<> XOA.completer addressCompleter
385386

386387
filepath' :: Parser FilePath
387-
filepath' = strArgument $
388+
filepath' = XOA.strArgument $
388389
metavar "FILEPATH"
389390
<> help "Absolute file path, i.e. /tmp/fred"
390391
<> action "file"
391392

392393
text' :: Parser Text
393-
text' = T.pack <$> (strArgument $
394+
text' = T.pack <$> (XOA.strArgument $
394395
metavar "STRING"
395396
<> help "Data to write to S3 address.")
396397

@@ -414,14 +415,14 @@ syncMode' =
414415
<|> (flag' OverwriteSync $ long "overwrite" <> help "Overwrite files that already exist in the target location.")
415416

416417
fork' :: Parser Int
417-
fork' = option auto $
418+
fork' = XOA.option auto $
418419
long "fork"
419420
<> metavar "INT"
420421
<> help "Number of threads to fork CopyObject call by."
421422
<> value 8
422423

423424
addressCompleter :: Completer
424-
addressCompleter = mkCompleter $ \s -> do
425+
addressCompleter = XOA.mkCompleter $ \s -> do
425426
res <- runEitherT (go s)
426427
case res of
427428
Left _ -> pure []

0 commit comments

Comments
 (0)