-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from haskell-works/new-complement-command
New complement command
- Loading branch information
Showing
4 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module App.Commands.Complement | ||
( cmdComplement | ||
) where | ||
|
||
import Control.Lens | ||
import Data.Generics.Product.Any | ||
import Data.Semigroup ((<>)) | ||
import HaskellWorks.Data.Bits.BitWise | ||
import Options.Applicative hiding (columns) | ||
|
||
import qualified App.Commands.Options.Type as Z | ||
import qualified Data.ByteString.Lazy as LBS | ||
|
||
{-# ANN module ("HLint: ignore Redundant do" :: String) #-} | ||
{-# ANN module ("HLint: ignore Redundant return" :: String) #-} | ||
|
||
runComplement :: Z.ComplementOptions -> IO () | ||
runComplement opts = do | ||
let inputFile = opts ^. the @"inputFile" | ||
let outputFile = opts ^. the @"outputFile" | ||
|
||
LBS.readFile inputFile <&> LBS.map comp >>= LBS.writeFile outputFile | ||
|
||
optsComplement :: Parser Z.ComplementOptions | ||
optsComplement = Z.ComplementOptions | ||
<$> strOption | ||
( long "input-file" | ||
<> help "Input file" | ||
<> metavar "FILE" | ||
) | ||
<*> strOption | ||
( long "output-file" | ||
<> help "Output file" | ||
<> metavar "FILE" | ||
) | ||
|
||
cmdComplement :: Mod CommandFields (IO ()) | ||
cmdComplement = command "complement" $ flip info idm $ runComplement <$> optsComplement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters