fix option parser

Alternative doesn't combine the subparsers the way I wanted.
Unfortunately this new parser has suboptimal usage because everything is
all jumbled together.
This commit is contained in:
Joey Hess 2019-03-06 13:10:29 -04:00
parent b0fe4916b7
commit be6085cfe5
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -38,7 +38,8 @@ cmd = notBareRepo $
withGlobalOptions [jobsOption, jsonOptions, fileMatchingOptions] $
command "import" SectionCommon
"move and add files from outside git working copy"
paramPaths (seek <$$> optParser)
(paramPaths ++ "|BRANCH[:SUBDIR]")
(seek <$$> optParser)
data ImportOptions
= LocalImportOptions
@ -52,19 +53,19 @@ data ImportOptions
}
optParser :: CmdParamsDesc -> Parser ImportOptions
optParser desc = remoteopts <|> localopts
where
localopts = LocalImportOptions
<$> cmdParams desc
<*> (fromMaybe Default <$> optional duplicateModeParser)
remoteopts = do
remote <- parseRemoteOption <$> parseFromOption
(branch, subdir) <- separate (== ':') <$> argument str
( metavar "BRANCH[:SUBDIR]"
)
pure $ RemoteImportOptions remote
(Ref branch)
(if null subdir then Nothing else Just subdir)
optParser desc = do
ps <- cmdParams desc
mfromremote <- optional $ parseRemoteOption <$> parseFromOption
dupmode <- fromMaybe Default <$> optional duplicateModeParser
return $ case mfromremote of
Nothing -> LocalImportOptions ps dupmode
Just r -> case ps of
[bs] ->
let (branch, subdir) = separate (== ':') bs
in RemoteImportOptions r
(Ref branch)
(if null subdir then Nothing else Just subdir)
_ -> giveup "expected BRANCH[:SUBDIR]"
data DuplicateMode = Default | Duplicate | DeDuplicate | CleanDuplicates | SkipDuplicates | ReinjectDuplicates
deriving (Eq)