convert version command, and make --raw work when not in a git repo

This commit is contained in:
Joey Hess 2015-07-10 13:49:46 -04:00
parent b4d22e6d49
commit 4064dd4c82
5 changed files with 51 additions and 51 deletions

View file

@ -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
]

View file

@ -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.
-}

View file

@ -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)

View file

@ -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
start :: CommandStart
start = do
seekNoRepo :: VersionOptions -> IO ()
seekNoRepo o
| rawOption o = showRawVersion
| otherwise = showPackageVersion
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

View file

@ -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