summaryrefslogtreecommitdiff
path: root/Command/Info.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-10-21 13:44:17 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-10-21 14:35:07 -0400
commit19e96c4dcf8cf6e78dcc78527530279f205caf98 (patch)
tree02f15841f1dbd68297b399d49a211879d589d6a0 /Command/Info.hs
parent025c8e0d6e4c0037296968a828a6b57148f8e5e5 (diff)
info: When passed the name or uuid of a remote, displays info about that remote.
No per-remote-type info yet. This commit was sponsored by Stanley Yamane.
Diffstat (limited to 'Command/Info.hs')
-rw-r--r--Command/Info.hs53
1 files changed, 43 insertions, 10 deletions
diff --git a/Command/Info.hs b/Command/Info.hs
index ffa6a591e..5cac2954a 100644
--- a/Command/Info.hs
+++ b/Command/Info.hs
@@ -16,10 +16,11 @@ import Data.Tuple
import Data.Ord
import Common.Annex
-import qualified Remote
import qualified Command.Unused
import qualified Git
import qualified Annex
+import qualified Remote
+import qualified Types.Remote as Remote
import Command
import Utility.DataUnits
import Utility.DiskFree
@@ -75,7 +76,7 @@ type StatState = StateT StatInfo Annex
cmd :: [Command]
cmd = [noCommit $ dontCheck repoExists $ withOptions [jsonOption] $
- command "info" paramPaths seek SectionQuery
+ command "info" (paramOptional $ paramRepeating paramItem) seek SectionQuery
"shows information about the specified item or the repository as a whole"]
seek :: CommandSeek
@@ -99,11 +100,15 @@ globalInfo = do
itemInfo :: String -> Annex ()
itemInfo p = ifM (isdir p)
( dirInfo p
- , maybe noinfo (fileInfo p) =<< isAnnexLink p
+ , do
+ v <- Remote.byName' p
+ case v of
+ Right r -> remoteInfo r
+ Left _ -> maybe noinfo (fileInfo p) =<< isAnnexLink p
)
where
isdir = liftIO . catchBoolIO . (isDirectory <$$> getFileStatus)
- noinfo = error $ p ++ " is not a directory or an annexed file"
+ noinfo = error $ p ++ " is not a directory or an annexed file or a remote"
dirInfo :: FilePath -> Annex ()
dirInfo dir = showCustom (unwords ["info", dir]) $ do
@@ -118,6 +123,11 @@ fileInfo file k = showCustom (unwords ["info", file]) $ do
evalStateT (mapM_ showStat (file_stats file k)) emptyStatInfo
return True
+remoteInfo :: Remote -> Annex ()
+remoteInfo r = showCustom (unwords ["info", Remote.name r]) $ do
+ evalStateT (mapM_ showStat (remote_stats r)) emptyStatInfo
+ return True
+
selStats :: [Stat] -> [Stat] -> Annex [Stat]
selStats fast_stats slow_stats = do
fast <- Annex.getState Annex.fast
@@ -150,7 +160,7 @@ global_slow_stats =
]
dir_fast_stats :: [FilePath -> Stat]
dir_fast_stats =
- [ local_dir
+ [ dir_name
, const local_annex_keys
, const local_annex_size
, const known_annex_files
@@ -163,11 +173,19 @@ dir_slow_stats =
file_stats :: FilePath -> Key -> [Stat]
file_stats f k =
- [ local_file f
+ [ file_name f
, key_size k
, key_name k
]
+remote_stats :: Remote -> [Stat]
+remote_stats r =
+ [ remote_name r
+ , remote_description r
+ , remote_uuid r
+ , remote_cost r
+ ]
+
stat :: String -> (String -> StatState String) -> Stat
stat desc a = return $ Just (desc, a desc)
@@ -204,11 +222,26 @@ remote_list level = stat n $ nojson $ lift $ do
where
n = showTrustLevel level ++ " repositories"
-local_dir :: FilePath -> Stat
-local_dir dir = stat "directory" $ json id $ return dir
+dir_name :: FilePath -> Stat
+dir_name dir = stat "directory" $ json id $ pure dir
+
+file_name :: FilePath -> Stat
+file_name file = stat "file" $ json id $ pure file
+
+remote_name :: Remote -> Stat
+remote_name r = stat "remote" $ json id $ pure (Remote.name r)
+
+remote_description :: Remote -> Stat
+remote_description r = stat "description" $ json id $ lift $
+ Remote.prettyUUID (Remote.uuid r)
+
+remote_uuid :: Remote -> Stat
+remote_uuid r = stat "uuid" $ json id $ pure $
+ fromUUID $ Remote.uuid r
-local_file :: FilePath -> Stat
-local_file file = stat "file" $ json id $ return file
+remote_cost :: Remote -> Stat
+remote_cost r = stat "cost" $ json id $ pure $
+ show $ Remote.cost r
local_annex_keys :: Stat
local_annex_keys = stat "local annex keys" $ json show $