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.Vicfg
|
||||||
import qualified Command.Sync
|
import qualified Command.Sync
|
||||||
import qualified Command.Mirror
|
import qualified Command.Mirror
|
||||||
--import qualified Command.AddUrl
|
import qualified Command.AddUrl
|
||||||
#ifdef WITH_FEED
|
#ifdef WITH_FEED
|
||||||
--import qualified Command.ImportFeed
|
--import qualified Command.ImportFeed
|
||||||
#endif
|
#endif
|
||||||
|
@ -131,7 +131,7 @@ cmds =
|
||||||
, Command.Lock.cmd
|
, Command.Lock.cmd
|
||||||
, Command.Sync.cmd
|
, Command.Sync.cmd
|
||||||
, Command.Mirror.cmd
|
, Command.Mirror.cmd
|
||||||
-- , Command.AddUrl.cmd
|
, Command.AddUrl.cmd
|
||||||
#ifdef WITH_FEED
|
#ifdef WITH_FEED
|
||||||
-- , Command.ImportFeed.cmd
|
-- , Command.ImportFeed.cmd
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -38,33 +38,44 @@ import qualified Utility.Quvi as Quvi
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cmd :: Command
|
cmd :: Command
|
||||||
cmd = notBareRepo $ withOptions [fileOption, pathdepthOption, relaxedOption, rawOption] $
|
cmd = notBareRepo $
|
||||||
command "addurl" SectionCommon "add urls to annex"
|
command "addurl" SectionCommon "add urls to annex"
|
||||||
(paramRepeating paramUrl) (withParams seek)
|
(paramRepeating paramUrl) (seek <$$> optParser)
|
||||||
|
|
||||||
fileOption :: Option
|
data AddUrlOptions = AddUrlOptions
|
||||||
fileOption = fieldOption [] "file" paramFile "specify what file the url is added to"
|
{ addUrls :: CmdParams
|
||||||
|
, fileOption :: Maybe FilePath
|
||||||
|
, pathdepthOption :: Maybe Int
|
||||||
|
, relaxedOption :: Bool
|
||||||
|
, rawOption :: Bool
|
||||||
|
}
|
||||||
|
|
||||||
pathdepthOption :: Option
|
optParser :: CmdParamsDesc -> Parser AddUrlOptions
|
||||||
pathdepthOption = fieldOption [] "pathdepth" paramNumber "path components to use in filename"
|
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
|
seek :: AddUrlOptions -> CommandSeek
|
||||||
relaxedOption = flagOption [] "relaxed" "skip size check"
|
seek o = forM_ (addUrls o) $ \u -> do
|
||||||
|
|
||||||
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
|
r <- Remote.claimingUrl u
|
||||||
if Remote.uuid r == webUUID || raw
|
if Remote.uuid r == webUUID || rawOption o
|
||||||
then void $ commandAction $ startWeb relaxed optfile pathdepth u
|
then void $ commandAction $ startWeb (relaxedOption o) (fileOption o) (pathdepthOption o) u
|
||||||
else checkUrl r u optfile relaxed pathdepth
|
else checkUrl r u (fileOption o) (relaxedOption o) (pathdepthOption o)
|
||||||
|
|
||||||
checkUrl :: Remote -> URLString -> Maybe FilePath -> Bool -> Maybe Int -> Annex ()
|
checkUrl :: Remote -> URLString -> Maybe FilePath -> Bool -> Maybe Int -> Annex ()
|
||||||
checkUrl r u optfile relaxed pathdepth = do
|
checkUrl r u optfile relaxed pathdepth = do
|
||||||
|
|
Loading…
Add table
Reference in a new issue