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