diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-07-10 13:49:46 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-07-10 13:49:46 -0400 |
commit | 00e37e72e06d3692ea2b5c77dfa6b0147a3b6d6d (patch) | |
tree | f957d1c627da125fa2c852cefe24f4b6d556d2f1 | |
parent | 94642d1b1907a379181e25e298910b9c09fd5adf (diff) |
convert version command, and make --raw work when not in a git repo
-rw-r--r-- | CmdLine/GitAnnex.hs | 40 | ||||
-rw-r--r-- | Command.hs | 7 | ||||
-rw-r--r-- | Command/Unused.hs | 2 | ||||
-rw-r--r-- | Command/Version.hs | 50 | ||||
-rw-r--r-- | Types/Command.hs | 3 |
5 files changed, 51 insertions, 51 deletions
diff --git a/CmdLine/GitAnnex.hs b/CmdLine/GitAnnex.hs index 18964d4dd..81b9cd3d6 100644 --- a/CmdLine/GitAnnex.hs +++ b/CmdLine/GitAnnex.hs @@ -23,8 +23,8 @@ import qualified Command.Move import qualified Command.Copy import qualified Command.Get import qualified Command.Fsck -import qualified Command.LookupKey -import qualified Command.ContentLocation +--import qualified Command.LookupKey +--import qualified Command.ContentLocation --import qualified Command.ExamineKey import qualified Command.FromKey import qualified Command.RegisterUrl @@ -48,7 +48,7 @@ import qualified Command.Init import qualified Command.Describe import qualified Command.InitRemote import qualified Command.EnableRemote -import qualified Command.Expire +--import qualified Command.Expire import qualified Command.Repair --import qualified Command.Unused --import qualified Command.DropUnused @@ -82,9 +82,9 @@ 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 +--import qualified Command.ImportFeed #endif import qualified Command.RmUrl --import qualified Command.Import @@ -92,16 +92,16 @@ import qualified Command.Map import qualified Command.Direct import qualified Command.Indirect import qualified Command.Upgrade -import qualified Command.Forget +--import qualified Command.Forget import qualified Command.Proxy import qualified Command.DiffDriver --import qualified Command.Undo import qualified Command.Version #ifdef WITH_ASSISTANT -import qualified Command.Watch -import qualified Command.Assistant +--import qualified Command.Watch +--import qualified Command.Assistant #ifdef WITH_WEBAPP -import qualified Command.WebApp +--import qualified Command.WebApp #endif #ifdef WITH_XMPP import qualified Command.XMPPGit @@ -111,7 +111,7 @@ import qualified Command.RemoteDaemon import qualified Command.Test #ifdef WITH_TESTSUITE import qualified Command.FuzzTest -import qualified Command.TestRemote +--import qualified Command.TestRemote #endif #ifdef WITH_EKG import System.Remote.Monitoring @@ -131,9 +131,9 @@ cmds = , Command.Lock.cmd , Command.Sync.cmd -- , Command.Mirror.cmd - , Command.AddUrl.cmd +-- , Command.AddUrl.cmd #ifdef WITH_FEED - , Command.ImportFeed.cmd +-- , Command.ImportFeed.cmd #endif , Command.RmUrl.cmd -- , Command.Import.cmd @@ -158,8 +158,8 @@ cmds = , Command.Schedule.cmd , Command.Ungroup.cmd -- , Command.Vicfg.cmd - , Command.LookupKey.cmd - , Command.ContentLocation.cmd +-- , Command.LookupKey.cmd +-- , Command.ContentLocation.cmd -- , Command.ExamineKey.cmd , Command.FromKey.cmd , Command.RegisterUrl.cmd @@ -178,7 +178,7 @@ cmds = , Command.VPop.cmd , Command.VCycle.cmd , Command.Fix.cmd - , Command.Expire.cmd +-- , Command.Expire.cmd , Command.Repair.cmd -- , Command.Unused.cmd -- , Command.DropUnused.cmd @@ -197,16 +197,16 @@ cmds = , Command.Direct.cmd , Command.Indirect.cmd , Command.Upgrade.cmd - , Command.Forget.cmd +-- , Command.Forget.cmd , Command.Proxy.cmd , Command.DiffDriver.cmd -- , Command.Undo.cmd , Command.Version.cmd #ifdef WITH_ASSISTANT - , Command.Watch.cmd - , Command.Assistant.cmd +-- , Command.Watch.cmd +-- , Command.Assistant.cmd #ifdef WITH_WEBAPP - , Command.WebApp.cmd +-- , Command.WebApp.cmd #endif #ifdef WITH_XMPP , Command.XMPPGit.cmd @@ -216,7 +216,7 @@ cmds = , Command.Test.cmd #ifdef WITH_TESTSUITE , Command.FuzzTest.cmd - , Command.TestRemote.cmd +-- , Command.TestRemote.cmd #endif ] diff --git a/Command.hs b/Command.hs index a9659b78f..bee63bb74 100644 --- a/Command.hs +++ b/Command.hs @@ -12,7 +12,6 @@ module Command ( noRepo, noCommit, noMessages, - withOptions, withGlobalOptions, next, stop, @@ -43,7 +42,7 @@ import qualified Options.Applicative as O {- Generates a normal Command -} command :: String -> CommandSection -> String -> CmdParamsDesc -> (CmdParamsDesc -> CommandParser) -> Command command name section desc paramdesc mkparser = - Command [] commonChecks False False name paramdesc + Command commonChecks False False name paramdesc section desc (mkparser paramdesc) Nothing {- Simple option parser that takes all non-option params as-is. -} @@ -76,10 +75,6 @@ noMessages c = c { cmdnomessages = True } noRepo :: (String -> O.Parser (IO ())) -> Command -> Command noRepo a c = c { cmdnorepo = Just (a (cmdparamdesc c)) } -{- Adds options to a command. -} -withOptions :: [Option] -> Command -> Command -withOptions o c = c { cmdoptions = cmdoptions c ++ o } - {- Adds global options to a command's option parser, and modifies its seek - option to first run actions for them. -} diff --git a/Command/Unused.hs b/Command/Unused.hs index 4649485c2..c2ca148b7 100644 --- a/Command/Unused.hs +++ b/Command/Unused.hs @@ -35,7 +35,7 @@ import Logs.View (is_branchView) import Annex.BloomFilter cmd :: Command -cmd = withOptions [unusedFromOption, refSpecOption] $ +cmd = -- withGlobalOptions [unusedFromOption, refSpecOption] $ command "unused" SectionMaintenance "look for unused file content" paramNothing (withParams seek) diff --git a/Command/Version.hs b/Command/Version.hs index 9896f671e..72bbe4064 100644 --- a/Command/Version.hs +++ b/Command/Version.hs @@ -18,40 +18,41 @@ import qualified Remote import qualified Backend cmd :: Command -cmd = withOptions [rawOption] $ dontCheck repoExists $ noCommit $ - noRepo (parseparams startNoRepo) $ +cmd = dontCheck repoExists $ noCommit $ + noRepo (seekNoRepo <$$> optParser) $ command "version" SectionQuery "show version info" - paramNothing (parseparams seek) - where - parseparams = withParams + paramNothing (seek <$$> optParser) -rawOption :: Option -rawOption = flagOption [] "raw" "output only program version" +data VersionOptions = VersionOptions + { rawOption :: Bool + } -seek :: CmdParams -> CommandSeek -seek = withNothing $ ifM (getOptionFlag rawOption) (startRaw, start) +optParser :: CmdParamsDesc -> Parser VersionOptions +optParser _ = VersionOptions + <$> switch + ( long "raw" + <> help "output only program version" + ) -startRaw :: CommandStart -startRaw = do - liftIO $ do - putStr SysConfig.packageversion - hFlush stdout - stop +seek :: VersionOptions -> CommandSeek +seek o + | rawOption o = liftIO showRawVersion + | otherwise = showVersion + +seekNoRepo :: VersionOptions -> IO () +seekNoRepo o + | rawOption o = showRawVersion + | otherwise = showPackageVersion -start :: CommandStart -start = do +showVersion :: Annex () +showVersion = do v <- getVersion liftIO $ do - showPackageVersion vinfo "local repository version" $ fromMaybe "unknown" v vinfo "supported repository version" supportedVersion vinfo "upgrade supported from repository versions" $ unwords upgradableVersions - stop - -startNoRepo :: CmdParams -> IO () -startNoRepo _ = showPackageVersion showPackageVersion :: IO () showPackageVersion = do @@ -60,5 +61,10 @@ showPackageVersion = do vinfo "key/value backends" $ unwords $ map B.name Backend.list vinfo "remote types" $ unwords $ map R.typename Remote.remoteTypes +showRawVersion :: IO () +showRawVersion = do + putStr SysConfig.packageversion + hFlush stdout -- no newline, so flush + vinfo :: String -> String -> IO () vinfo k v = putStrLn $ k ++ ": " ++ v diff --git a/Types/Command.hs b/Types/Command.hs index acd662bf3..e12873850 100644 --- a/Types/Command.hs +++ b/Types/Command.hs @@ -38,8 +38,7 @@ type CommandCleanup = Annex Bool {- A command is defined by specifying these things. -} data Command = Command - { cmdoptions :: [Option] -- command-specific options - , cmdcheck :: [CommandCheck] -- check stage + { cmdcheck :: [CommandCheck] -- check stage , cmdnocommit :: Bool -- don't commit journalled state changes , cmdnomessages :: Bool -- don't output normal messages , cmdname :: String |