converted addurl
This commit is contained in:
parent
3639b4f8ea
commit
aff4b9a3dc
2 changed files with 36 additions and 25 deletions
|
@ -82,7 +82,7 @@ import qualified Command.Ungroup
|
|||
import qualified Command.Vicfg
|
||||
import qualified Command.Sync
|
||||
import qualified Command.Mirror
|
||||
--import qualified Command.AddUrl
|
||||
import qualified Command.AddUrl
|
||||
#ifdef WITH_FEED
|
||||
--import qualified Command.ImportFeed
|
||||
#endif
|
||||
|
@ -131,7 +131,7 @@ cmds =
|
|||
, Command.Lock.cmd
|
||||
, Command.Sync.cmd
|
||||
, Command.Mirror.cmd
|
||||
-- , Command.AddUrl.cmd
|
||||
, Command.AddUrl.cmd
|
||||
#ifdef WITH_FEED
|
||||
-- , Command.ImportFeed.cmd
|
||||
#endif
|
||||
|
|
|
@ -38,33 +38,44 @@ import qualified Utility.Quvi as Quvi
|
|||
#endif
|
||||
|
||||
cmd :: Command
|
||||
cmd = notBareRepo $ withOptions [fileOption, pathdepthOption, relaxedOption, rawOption] $
|
||||
cmd = notBareRepo $
|
||||
command "addurl" SectionCommon "add urls to annex"
|
||||
(paramRepeating paramUrl) (withParams seek)
|
||||
(paramRepeating paramUrl) (seek <$$> optParser)
|
||||
|
||||
fileOption :: Option
|
||||
fileOption = fieldOption [] "file" paramFile "specify what file the url is added to"
|
||||
data AddUrlOptions = AddUrlOptions
|
||||
{ addUrls :: CmdParams
|
||||
, fileOption :: Maybe FilePath
|
||||
, pathdepthOption :: Maybe Int
|
||||
, relaxedOption :: Bool
|
||||
, rawOption :: Bool
|
||||
}
|
||||
|
||||
pathdepthOption :: Option
|
||||
pathdepthOption = fieldOption [] "pathdepth" paramNumber "path components to use in filename"
|
||||
optParser :: CmdParamsDesc -> Parser AddUrlOptions
|
||||
optParser desc = AddUrlOptions
|
||||
<$> cmdParams desc
|
||||
<*> optional (strOption
|
||||
( long "file" <> metavar paramFile
|
||||
<> help "specify what file the url is added to"
|
||||
))
|
||||
<*> optional (option auto
|
||||
( long "pathdepth" <> metavar paramNumber
|
||||
<> help "path components to use in filename"
|
||||
))
|
||||
<*> switch
|
||||
( long "relaxed"
|
||||
<> help "skip size check"
|
||||
)
|
||||
<*> switch
|
||||
( long "raw"
|
||||
<> help "disable special handling for torrents, quvi, etc"
|
||||
)
|
||||
|
||||
relaxedOption :: Option
|
||||
relaxedOption = flagOption [] "relaxed" "skip size check"
|
||||
|
||||
rawOption :: Option
|
||||
rawOption = flagOption [] "raw" "disable special handling for torrents, quvi, etc"
|
||||
|
||||
seek :: CmdParams -> CommandSeek
|
||||
seek us = do
|
||||
optfile <- getOptionField fileOption return
|
||||
relaxed <- getOptionFlag relaxedOption
|
||||
raw <- getOptionFlag rawOption
|
||||
pathdepth <- getOptionField pathdepthOption (return . maybe Nothing readish)
|
||||
forM_ us $ \u -> do
|
||||
r <- Remote.claimingUrl u
|
||||
if Remote.uuid r == webUUID || raw
|
||||
then void $ commandAction $ startWeb relaxed optfile pathdepth u
|
||||
else checkUrl r u optfile relaxed pathdepth
|
||||
seek :: AddUrlOptions -> CommandSeek
|
||||
seek o = forM_ (addUrls o) $ \u -> do
|
||||
r <- Remote.claimingUrl u
|
||||
if Remote.uuid r == webUUID || rawOption o
|
||||
then void $ commandAction $ startWeb (relaxedOption o) (fileOption o) (pathdepthOption o) u
|
||||
else checkUrl r u (fileOption o) (relaxedOption o) (pathdepthOption o)
|
||||
|
||||
checkUrl :: Remote -> URLString -> Maybe FilePath -> Bool -> Maybe Int -> Annex ()
|
||||
checkUrl r u optfile relaxed pathdepth = do
|
||||
|
|
Loading…
Reference in a new issue