add --version option
This commit is contained in:
parent
3b6ad40a02
commit
a0c17c434a
21
Main.hs
21
Main.hs
@ -13,8 +13,9 @@ import qualified Database.LevelDB as L
|
|||||||
import qualified Database.LevelDB.Streaming as LS
|
import qualified Database.LevelDB.Streaming as LS
|
||||||
|
|
||||||
-- Error handling
|
-- Error handling
|
||||||
import Control.Exception as BE
|
import Control.Exception as BE
|
||||||
import Control.Monad.Catch as CE
|
import Control.Monad.Catch as CE
|
||||||
|
import qualified System.Exit as E
|
||||||
|
|
||||||
-- Configuration
|
-- Configuration
|
||||||
import qualified Options.Applicative as O
|
import qualified Options.Applicative as O
|
||||||
@ -27,6 +28,10 @@ import qualified Data.Text as T
|
|||||||
import qualified Data.Text.IO as T
|
import qualified Data.Text.IO as T
|
||||||
import qualified Data.ByteString as B
|
import qualified Data.ByteString as B
|
||||||
|
|
||||||
|
-- Version information
|
||||||
|
import qualified Paths_bisc as Bisc
|
||||||
|
import Data.Version (showVersion)
|
||||||
|
|
||||||
-- Misc
|
-- Misc
|
||||||
import Data.List (nub)
|
import Data.List (nub)
|
||||||
import Data.Maybe (mapMaybe)
|
import Data.Maybe (mapMaybe)
|
||||||
@ -49,7 +54,8 @@ data Settings = Settings
|
|||||||
|
|
||||||
-- | Command line options
|
-- | Command line options
|
||||||
data Options = Options
|
data Options = Options
|
||||||
{ dryRun :: Bool -- ^ don't delete anything
|
{ version :: Bool -- ^ print version number
|
||||||
|
, dryRun :: Bool -- ^ don't delete anything
|
||||||
, configPath :: FilePath -- ^ config file path
|
, configPath :: FilePath -- ^ config file path
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,6 +65,11 @@ cliParser defConfig = O.info (O.helper <*> parser) infos
|
|||||||
where
|
where
|
||||||
parser = Options
|
parser = Options
|
||||||
<$> O.switch
|
<$> O.switch
|
||||||
|
( O.long "version"
|
||||||
|
<> O.short 'v'
|
||||||
|
<> O.help "Print the version number and exit"
|
||||||
|
)
|
||||||
|
<*> O.switch
|
||||||
( O.long "dry-run"
|
( O.long "dry-run"
|
||||||
<> O.short 'n'
|
<> O.short 'n'
|
||||||
<> O.help ("Don't actually remove anything, "<>
|
<> O.help ("Don't actually remove anything, "<>
|
||||||
@ -122,6 +133,10 @@ main = do
|
|||||||
defConfig <- D.getXdgDirectory D.XdgConfig ("bisc" </> "bisc.conf")
|
defConfig <- D.getXdgDirectory D.XdgConfig ("bisc" </> "bisc.conf")
|
||||||
opts <- O.execParser (cliParser defConfig)
|
opts <- O.execParser (cliParser defConfig)
|
||||||
|
|
||||||
|
when (version opts) $ do
|
||||||
|
putStrLn ("bisc " <> showVersion Bisc.version)
|
||||||
|
E.exitSuccess
|
||||||
|
|
||||||
run <- runAction <$> loadSettings opts
|
run <- runAction <$> loadSettings opts
|
||||||
run "Cookies" deleteCookies
|
run "Cookies" deleteCookies
|
||||||
run "QuotaManager" deleteQuotaOrigins
|
run "QuotaManager" deleteQuotaOrigins
|
||||||
|
Loading…
Reference in New Issue
Block a user