convert version command, and make --raw work when not in a git repo
This commit is contained in:
parent
b4d22e6d49
commit
4064dd4c82
5 changed files with 51 additions and 51 deletions
|
@ -23,8 +23,8 @@ import qualified Command.Move
|
||||||
import qualified Command.Copy
|
import qualified Command.Copy
|
||||||
import qualified Command.Get
|
import qualified Command.Get
|
||||||
import qualified Command.Fsck
|
import qualified Command.Fsck
|
||||||
import qualified Command.LookupKey
|
--import qualified Command.LookupKey
|
||||||
import qualified Command.ContentLocation
|
--import qualified Command.ContentLocation
|
||||||
--import qualified Command.ExamineKey
|
--import qualified Command.ExamineKey
|
||||||
import qualified Command.FromKey
|
import qualified Command.FromKey
|
||||||
import qualified Command.RegisterUrl
|
import qualified Command.RegisterUrl
|
||||||
|
@ -48,7 +48,7 @@ import qualified Command.Init
|
||||||
import qualified Command.Describe
|
import qualified Command.Describe
|
||||||
import qualified Command.InitRemote
|
import qualified Command.InitRemote
|
||||||
import qualified Command.EnableRemote
|
import qualified Command.EnableRemote
|
||||||
import qualified Command.Expire
|
--import qualified Command.Expire
|
||||||
import qualified Command.Repair
|
import qualified Command.Repair
|
||||||
--import qualified Command.Unused
|
--import qualified Command.Unused
|
||||||
--import qualified Command.DropUnused
|
--import qualified Command.DropUnused
|
||||||
|
@ -82,9 +82,9 @@ 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
|
||||||
import qualified Command.RmUrl
|
import qualified Command.RmUrl
|
||||||
--import qualified Command.Import
|
--import qualified Command.Import
|
||||||
|
@ -92,16 +92,16 @@ import qualified Command.Map
|
||||||
import qualified Command.Direct
|
import qualified Command.Direct
|
||||||
import qualified Command.Indirect
|
import qualified Command.Indirect
|
||||||
import qualified Command.Upgrade
|
import qualified Command.Upgrade
|
||||||
import qualified Command.Forget
|
--import qualified Command.Forget
|
||||||
import qualified Command.Proxy
|
import qualified Command.Proxy
|
||||||
import qualified Command.DiffDriver
|
import qualified Command.DiffDriver
|
||||||
--import qualified Command.Undo
|
--import qualified Command.Undo
|
||||||
import qualified Command.Version
|
import qualified Command.Version
|
||||||
#ifdef WITH_ASSISTANT
|
#ifdef WITH_ASSISTANT
|
||||||
import qualified Command.Watch
|
--import qualified Command.Watch
|
||||||
import qualified Command.Assistant
|
--import qualified Command.Assistant
|
||||||
#ifdef WITH_WEBAPP
|
#ifdef WITH_WEBAPP
|
||||||
import qualified Command.WebApp
|
--import qualified Command.WebApp
|
||||||
#endif
|
#endif
|
||||||
#ifdef WITH_XMPP
|
#ifdef WITH_XMPP
|
||||||
import qualified Command.XMPPGit
|
import qualified Command.XMPPGit
|
||||||
|
@ -111,7 +111,7 @@ import qualified Command.RemoteDaemon
|
||||||
import qualified Command.Test
|
import qualified Command.Test
|
||||||
#ifdef WITH_TESTSUITE
|
#ifdef WITH_TESTSUITE
|
||||||
import qualified Command.FuzzTest
|
import qualified Command.FuzzTest
|
||||||
import qualified Command.TestRemote
|
--import qualified Command.TestRemote
|
||||||
#endif
|
#endif
|
||||||
#ifdef WITH_EKG
|
#ifdef WITH_EKG
|
||||||
import System.Remote.Monitoring
|
import System.Remote.Monitoring
|
||||||
|
@ -131,9 +131,9 @@ 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
|
||||||
, Command.RmUrl.cmd
|
, Command.RmUrl.cmd
|
||||||
-- , Command.Import.cmd
|
-- , Command.Import.cmd
|
||||||
|
@ -158,8 +158,8 @@ cmds =
|
||||||
, Command.Schedule.cmd
|
, Command.Schedule.cmd
|
||||||
, Command.Ungroup.cmd
|
, Command.Ungroup.cmd
|
||||||
-- , Command.Vicfg.cmd
|
-- , Command.Vicfg.cmd
|
||||||
, Command.LookupKey.cmd
|
-- , Command.LookupKey.cmd
|
||||||
, Command.ContentLocation.cmd
|
-- , Command.ContentLocation.cmd
|
||||||
-- , Command.ExamineKey.cmd
|
-- , Command.ExamineKey.cmd
|
||||||
, Command.FromKey.cmd
|
, Command.FromKey.cmd
|
||||||
, Command.RegisterUrl.cmd
|
, Command.RegisterUrl.cmd
|
||||||
|
@ -178,7 +178,7 @@ cmds =
|
||||||
, Command.VPop.cmd
|
, Command.VPop.cmd
|
||||||
, Command.VCycle.cmd
|
, Command.VCycle.cmd
|
||||||
, Command.Fix.cmd
|
, Command.Fix.cmd
|
||||||
, Command.Expire.cmd
|
-- , Command.Expire.cmd
|
||||||
, Command.Repair.cmd
|
, Command.Repair.cmd
|
||||||
-- , Command.Unused.cmd
|
-- , Command.Unused.cmd
|
||||||
-- , Command.DropUnused.cmd
|
-- , Command.DropUnused.cmd
|
||||||
|
@ -197,16 +197,16 @@ cmds =
|
||||||
, Command.Direct.cmd
|
, Command.Direct.cmd
|
||||||
, Command.Indirect.cmd
|
, Command.Indirect.cmd
|
||||||
, Command.Upgrade.cmd
|
, Command.Upgrade.cmd
|
||||||
, Command.Forget.cmd
|
-- , Command.Forget.cmd
|
||||||
, Command.Proxy.cmd
|
, Command.Proxy.cmd
|
||||||
, Command.DiffDriver.cmd
|
, Command.DiffDriver.cmd
|
||||||
-- , Command.Undo.cmd
|
-- , Command.Undo.cmd
|
||||||
, Command.Version.cmd
|
, Command.Version.cmd
|
||||||
#ifdef WITH_ASSISTANT
|
#ifdef WITH_ASSISTANT
|
||||||
, Command.Watch.cmd
|
-- , Command.Watch.cmd
|
||||||
, Command.Assistant.cmd
|
-- , Command.Assistant.cmd
|
||||||
#ifdef WITH_WEBAPP
|
#ifdef WITH_WEBAPP
|
||||||
, Command.WebApp.cmd
|
-- , Command.WebApp.cmd
|
||||||
#endif
|
#endif
|
||||||
#ifdef WITH_XMPP
|
#ifdef WITH_XMPP
|
||||||
, Command.XMPPGit.cmd
|
, Command.XMPPGit.cmd
|
||||||
|
@ -216,7 +216,7 @@ cmds =
|
||||||
, Command.Test.cmd
|
, Command.Test.cmd
|
||||||
#ifdef WITH_TESTSUITE
|
#ifdef WITH_TESTSUITE
|
||||||
, Command.FuzzTest.cmd
|
, Command.FuzzTest.cmd
|
||||||
, Command.TestRemote.cmd
|
-- , Command.TestRemote.cmd
|
||||||
#endif
|
#endif
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ module Command (
|
||||||
noRepo,
|
noRepo,
|
||||||
noCommit,
|
noCommit,
|
||||||
noMessages,
|
noMessages,
|
||||||
withOptions,
|
|
||||||
withGlobalOptions,
|
withGlobalOptions,
|
||||||
next,
|
next,
|
||||||
stop,
|
stop,
|
||||||
|
@ -43,7 +42,7 @@ import qualified Options.Applicative as O
|
||||||
{- Generates a normal Command -}
|
{- Generates a normal Command -}
|
||||||
command :: String -> CommandSection -> String -> CmdParamsDesc -> (CmdParamsDesc -> CommandParser) -> Command
|
command :: String -> CommandSection -> String -> CmdParamsDesc -> (CmdParamsDesc -> CommandParser) -> Command
|
||||||
command name section desc paramdesc mkparser =
|
command name section desc paramdesc mkparser =
|
||||||
Command [] commonChecks False False name paramdesc
|
Command commonChecks False False name paramdesc
|
||||||
section desc (mkparser paramdesc) Nothing
|
section desc (mkparser paramdesc) Nothing
|
||||||
|
|
||||||
{- Simple option parser that takes all non-option params as-is. -}
|
{- 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 :: (String -> O.Parser (IO ())) -> Command -> Command
|
||||||
noRepo a c = c { cmdnorepo = Just (a (cmdparamdesc c)) }
|
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
|
{- Adds global options to a command's option parser, and modifies its seek
|
||||||
- option to first run actions for them.
|
- option to first run actions for them.
|
||||||
-}
|
-}
|
||||||
|
|
|
@ -35,7 +35,7 @@ import Logs.View (is_branchView)
|
||||||
import Annex.BloomFilter
|
import Annex.BloomFilter
|
||||||
|
|
||||||
cmd :: Command
|
cmd :: Command
|
||||||
cmd = withOptions [unusedFromOption, refSpecOption] $
|
cmd = -- withGlobalOptions [unusedFromOption, refSpecOption] $
|
||||||
command "unused" SectionMaintenance
|
command "unused" SectionMaintenance
|
||||||
"look for unused file content"
|
"look for unused file content"
|
||||||
paramNothing (withParams seek)
|
paramNothing (withParams seek)
|
||||||
|
|
|
@ -18,40 +18,41 @@ import qualified Remote
|
||||||
import qualified Backend
|
import qualified Backend
|
||||||
|
|
||||||
cmd :: Command
|
cmd :: Command
|
||||||
cmd = withOptions [rawOption] $ dontCheck repoExists $ noCommit $
|
cmd = dontCheck repoExists $ noCommit $
|
||||||
noRepo (parseparams startNoRepo) $
|
noRepo (seekNoRepo <$$> optParser) $
|
||||||
command "version" SectionQuery "show version info"
|
command "version" SectionQuery "show version info"
|
||||||
paramNothing (parseparams seek)
|
paramNothing (seek <$$> optParser)
|
||||||
where
|
|
||||||
parseparams = withParams
|
|
||||||
|
|
||||||
rawOption :: Option
|
data VersionOptions = VersionOptions
|
||||||
rawOption = flagOption [] "raw" "output only program version"
|
{ rawOption :: Bool
|
||||||
|
}
|
||||||
|
|
||||||
seek :: CmdParams -> CommandSeek
|
optParser :: CmdParamsDesc -> Parser VersionOptions
|
||||||
seek = withNothing $ ifM (getOptionFlag rawOption) (startRaw, start)
|
optParser _ = VersionOptions
|
||||||
|
<$> switch
|
||||||
|
( long "raw"
|
||||||
|
<> help "output only program version"
|
||||||
|
)
|
||||||
|
|
||||||
startRaw :: CommandStart
|
seek :: VersionOptions -> CommandSeek
|
||||||
startRaw = do
|
seek o
|
||||||
liftIO $ do
|
| rawOption o = liftIO showRawVersion
|
||||||
putStr SysConfig.packageversion
|
| otherwise = showVersion
|
||||||
hFlush stdout
|
|
||||||
stop
|
|
||||||
|
|
||||||
start :: CommandStart
|
seekNoRepo :: VersionOptions -> IO ()
|
||||||
start = do
|
seekNoRepo o
|
||||||
|
| rawOption o = showRawVersion
|
||||||
|
| otherwise = showPackageVersion
|
||||||
|
|
||||||
|
showVersion :: Annex ()
|
||||||
|
showVersion = do
|
||||||
v <- getVersion
|
v <- getVersion
|
||||||
liftIO $ do
|
liftIO $ do
|
||||||
|
|
||||||
showPackageVersion
|
showPackageVersion
|
||||||
vinfo "local repository version" $ fromMaybe "unknown" v
|
vinfo "local repository version" $ fromMaybe "unknown" v
|
||||||
vinfo "supported repository version" supportedVersion
|
vinfo "supported repository version" supportedVersion
|
||||||
vinfo "upgrade supported from repository versions" $
|
vinfo "upgrade supported from repository versions" $
|
||||||
unwords upgradableVersions
|
unwords upgradableVersions
|
||||||
stop
|
|
||||||
|
|
||||||
startNoRepo :: CmdParams -> IO ()
|
|
||||||
startNoRepo _ = showPackageVersion
|
|
||||||
|
|
||||||
showPackageVersion :: IO ()
|
showPackageVersion :: IO ()
|
||||||
showPackageVersion = do
|
showPackageVersion = do
|
||||||
|
@ -60,5 +61,10 @@ showPackageVersion = do
|
||||||
vinfo "key/value backends" $ unwords $ map B.name Backend.list
|
vinfo "key/value backends" $ unwords $ map B.name Backend.list
|
||||||
vinfo "remote types" $ unwords $ map R.typename Remote.remoteTypes
|
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 :: String -> String -> IO ()
|
||||||
vinfo k v = putStrLn $ k ++ ": " ++ v
|
vinfo k v = putStrLn $ k ++ ": " ++ v
|
||||||
|
|
|
@ -38,8 +38,7 @@ type CommandCleanup = Annex Bool
|
||||||
|
|
||||||
{- A command is defined by specifying these things. -}
|
{- A command is defined by specifying these things. -}
|
||||||
data Command = Command
|
data Command = Command
|
||||||
{ cmdoptions :: [Option] -- command-specific options
|
{ cmdcheck :: [CommandCheck] -- check stage
|
||||||
, cmdcheck :: [CommandCheck] -- check stage
|
|
||||||
, cmdnocommit :: Bool -- don't commit journalled state changes
|
, cmdnocommit :: Bool -- don't commit journalled state changes
|
||||||
, cmdnomessages :: Bool -- don't output normal messages
|
, cmdnomessages :: Bool -- don't output normal messages
|
||||||
, cmdname :: String
|
, cmdname :: String
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue