Skip to content

Commit a3b7d24

Browse files
committed
Add --backend flag to select used image manipulation backend
1 parent 346f51d commit a3b7d24

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

Diff for: app/Main.hs

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{-# LANGUAGE OverloadedRecordDot #-}
22
{-# LANGUAGE QuasiQuotes #-}
3+
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
4+
5+
{-# HLINT ignore "Replace case with maybe" #-}
36

47
module Main where
58

@@ -22,7 +25,8 @@ import Protolude (
2225
)
2326
import Protolude qualified as P
2427

25-
import Data.Text as T (isInfixOf, pack, unpack)
28+
import Data.Text (pack, unpack)
29+
import Data.Text qualified as T
2630
import Data.Yaml (decodeFileEither, prettyPrintParseException)
2731
import System.Console.Docopt as Docopt (
2832
Arguments,
@@ -48,12 +52,15 @@ import System.Directory (
4852
)
4953
import System.FilePath ((</>))
5054

55+
import Control.Arrow ((>>>))
5156
import Lib (loadAndStart)
5257
import Rename (getRenamingBatches)
5358
import Types (
5459
Config,
5560
RenameMode (Even, Odd, Sequential),
5661
SortOrder (Ascending, Descending),
62+
TransformBackend (HipBackend, ImageMagickBackend, SimpleCVBackend),
63+
transformBackendFlag,
5764
)
5865

5966

@@ -66,9 +73,24 @@ getArgOrExit = getArgOrExitWith patterns
6673

6774

6875
execWithArgs :: Config -> [[Char]] -> IO ()
69-
execWithArgs config cliArgs = do
76+
execWithArgs confFromFile cliArgs = do
7077
args <- parseArgsOrExit patterns cliArgs
7178

79+
let config = case args `getArg` longOption "backend" of
80+
Nothing -> confFromFile
81+
Just backend ->
82+
confFromFile
83+
{ transformBackendFlag =
84+
backend
85+
& ( T.pack
86+
>>> T.toLower
87+
>>> \case
88+
"hip" -> HipBackend
89+
"imagemagick" -> ImageMagickBackend
90+
_ -> SimpleCVBackend
91+
)
92+
}
93+
7294
when (args `isPresent` command "gui") $ do
7395
loadAndStart config Nothing
7496

Diff for: usage.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ Correct the perspective of photos
44
and rename them to match their page numbers.
55

66
Usage:
7-
perspec gui
8-
perspec fix <file>...
7+
perspec gui [--backend=<str>]
8+
perspec fix [--backend=<str>] <file>...
99
perspec rename [options] <directory>
1010

1111
Options:
12+
--backend=<str> Image manipulation backend to use
13+
(SimpleCV, Hip, ImageMagick)
14+
15+
Rename Options:
1216
--start-with=<int> First page number
1317
--even The directory contains only even page numbers
1418
--odd The directory contains only odd page numbers

0 commit comments

Comments
 (0)