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