summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-07-13 10:57:49 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-07-13 10:57:49 -0400
commitcb5c686b059d37eaa377c5fd8ab20bcf6617f981 (patch)
tree7c8604961076447c6030c94ec7e69afafe593c9e
parent3863b682b4a0fab70f1f03ac8e7957f17a3ee0b0 (diff)
converted addurl
-rw-r--r--CmdLine/GitAnnex.hs4
-rw-r--r--Command/AddUrl.hs57
2 files changed, 36 insertions, 25 deletions
diff --git a/CmdLine/GitAnnex.hs b/CmdLine/GitAnnex.hs
index bbd66eca8..cdeac1b51 100644
--- a/CmdLine/GitAnnex.hs
+++ b/CmdLine/GitAnnex.hs
@@ -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
diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs
index 45edca283..ed76e6c35 100644
--- a/Command/AddUrl.hs
+++ b/Command/AddUrl.hs
@@ -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"
-
-relaxedOption :: Option
-relaxedOption = flagOption [] "relaxed" "skip size check"
-
-rawOption :: Option
-rawOption = flagOption [] "raw" "disable special handling for torrents, quvi, etc"
+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"
+ )
-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