Skip to content

Commit a8f2830

Browse files
committed
Remove the formatting options from the CLI
This was awkward to use. One needs to specify either the whole formatting options, either none. What we need here is a HKT to have every fields in the `Formatting` data type wrapped in a `Maybe`.
1 parent 843dc2a commit a8f2830

File tree

2 files changed

+3
-54
lines changed

2 files changed

+3
-54
lines changed

app/Main.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,14 @@ main = do
126126
when (total > 0) $ System.exitWith $ System.ExitFailure total
127127
Options.FixFilePaths Options.FixFilePathsOptions {..} files -> do
128128
Config.Config {coFilename = Config.Filename {..}, ..} <- Config.readConfig
129-
let formatting = fromMaybe fiFormatting foFormatting
130-
pattern = fromMaybe fiPattern foPattern
129+
let pattern = fromMaybe fiPattern foPattern
131130
-- Get the base directory from the cli and fallback to the config file
132131
baseDir <- maybe (pure coFixPaths) Path.makeAbsolute foBaseDirectory
133132
let fixFilePathOptions =
134133
Commands.FixFilePathsOptions
135134
{ Commands.fiDryRun = foDryRun,
136135
Commands.fiBaseDirectory = baseDir,
137-
Commands.fiFormatting = formatting,
136+
Commands.fiFormatting = fiFormatting,
138137
Commands.fiPattern = pattern
139138
}
140139

app/Options.hs

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import Check.Album qualified as Album
1212
import Check.Artist qualified as Artist
1313
import Check.Track qualified as Track
1414
import Config qualified
15-
import Data.List.Extra qualified as List
1615
import Data.Text qualified as Text
1716
import Model.Cover qualified as Cover
1817
import Model.Pattern qualified as Pattern
@@ -33,15 +32,13 @@ data Files = Files
3332

3433
data CheckOptions = CheckOptions
3534
{ chChecks :: Config.Checks,
36-
chFormatting :: Maybe Pattern.Formatting,
3735
chFilematches :: Maybe Pattern.Pattern
3836
}
3937
deriving (Show)
4038

4139
data FixFilePathsOptions = FixFilePathsOptions
4240
{ foDryRun :: Bool,
4341
foBaseDirectory :: Maybe (Path.SomeBase Path.Dir),
44-
foFormatting :: Maybe Pattern.Formatting,
4542
foPattern :: Maybe Pattern.Pattern
4643
}
4744
deriving (Show)
@@ -65,10 +62,9 @@ checks
6562
config@(Config.Config {coFilename = Config.Filename {..}})
6663
(Options.CheckOptions {..})
6764
| not $ Config.haveChecks chChecks = Config.factorChecks config
68-
| otherwise = Config.factorChecks' pattern formatting chChecks
65+
| otherwise = Config.factorChecks' pattern fiFormatting chChecks
6966
where
7067
pattern = fromMaybe fiPattern chFilematches
71-
formatting = fromMaybe fiFormatting chFormatting
7268

7369
optionsInfo :: Options.ParserInfo Command
7470
optionsInfo = Options.info (optionsP <**> Options.helper) Options.idm
@@ -77,7 +73,6 @@ checkOptionsP :: Options.Parser CheckOptions
7773
checkOptionsP =
7874
CheckOptions
7975
<$> checksP
80-
<*> Options.optional formattingP
8176
<*> Options.optional filematchesP
8277

8378
checksP :: Options.Parser Config.Checks
@@ -97,7 +92,6 @@ fixFilePathsOptionsP =
9792
FixFilePathsOptions
9893
<$> dryRunP
9994
<*> optional baseDirectoryP
100-
<*> optional formattingP
10195
<*> optional filematchesP
10296

10397
dryRunP :: Options.Parser Bool
@@ -243,50 +237,6 @@ filematchesP =
243237
where
244238
parse = Megaparsec.parseMaybe Pattern.parser
245239

246-
formattingP :: Options.Parser Pattern.Formatting
247-
formattingP =
248-
Pattern.Formatting
249-
<$> charToCharActionP
250-
<*> paddingP "pad track"
251-
<*> paddingP "pad disc"
252-
<*> Options.option
253-
Options.auto
254-
( Options.long "placeholder-max-length"
255-
<> Options.metavar "N"
256-
<> Options.help
257-
"Maximum length of placeholder values after the formatting"
258-
)
259-
260-
charToCharActionP :: Options.Parser [(Char, Pattern.CharAction)]
261-
charToCharActionP =
262-
Pattern.addSlashIfNeeded
263-
<$> Options.many
264-
( (,Pattern.ChRemove)
265-
<$> Options.option
266-
Options.auto
267-
(Options.long "remove" <> Options.metavar "CHAR")
268-
<|> second Pattern.ChReplace
269-
<$> Options.option
270-
(Options.eitherReader $ first toString . parse)
271-
(Options.long "replace" <> Options.metavar "CHAR:CHAR")
272-
)
273-
where
274-
parse :: String -> Either Text (Char, Char)
275-
parse [c1, ':', c2] = Right (c1, c2)
276-
parse _ = Left "Must be in the form 'x:y'"
277-
278-
paddingP :: String -> Options.Parser Pattern.Padding
279-
paddingP label =
280-
Options.option
281-
(Options.eitherReader $ first toString . Pattern.parsePadding . toText)
282-
( Options.long option
283-
<> Options.metavar "N"
284-
<> Options.help
285-
("Number of digits to " <> label <> " numbers to")
286-
)
287-
where
288-
option = List.replace " " "-" label
289-
290240
setTagsOptionsP :: Options.Parser SetTagsOptions.SetTagsOptions
291241
setTagsOptionsP =
292242
SetTagsOptions.SetTagsOptions

0 commit comments

Comments
 (0)