@@ -15,37 +15,39 @@ import GHC.IO.Handle.FD (stdout)
1515import Options.Applicative
1616import Paths_tldr (version )
1717import System.Directory
18- import System.Environment (getArgs )
18+ import System.Environment (getArgs , getExecutablePath )
1919import System.FilePath
2020import System.Process.Typed
2121import Tldr
2222
23- data TldrOpts =
24- TldrOpts
25- { tldrAction :: TldrCommand
26- }
27- deriving (Show )
23+ data TldrOpts = TldrOpts
24+ { tldrAction :: TldrCommand
25+ } deriving (Show )
2826
2927data TldrCommand
3028 = UpdateIndex
31- | ViewPage ViewOptions [String ]
29+ | ViewPage ViewOptions
30+ [String ]
31+ | About
3232 deriving (Show , Eq , Ord )
3333
34- data ViewOptions =
35- ViewOptions
36- { platformOption :: Maybe String
37- }
38- deriving (Show , Eq , Ord )
34+ data ViewOptions = ViewOptions
35+ { platformOption :: Maybe String
36+ } deriving (Show , Eq , Ord )
3937
4038programOptions :: Parser TldrOpts
41- programOptions = (TldrOpts <$> (updateIndexCommand <|> viewPageCommand))
39+ programOptions =
40+ (TldrOpts <$> (updateIndexCommand <|> viewPageCommand <|> aboutFlag))
4241
4342updateIndexCommand :: Parser TldrCommand
4443updateIndexCommand =
4544 flag'
4645 UpdateIndex
4746 (long " update" <> short ' u' <> help " Update offline cache of tldr pages" )
4847
48+ aboutFlag :: Parser TldrCommand
49+ aboutFlag = flag' About (long " about" <> short ' a' <> help " About this program" )
50+
4951viewOptionsParser :: Parser ViewOptions
5052viewOptionsParser = ViewOptions <$> platformFlag
5153
@@ -147,10 +149,22 @@ nubOrd = loop mempty
147149 | a `Set.member` s = loop s as
148150 | otherwise = a : loop (Set. insert a s) as
149151
152+ handleAboutFlag :: IO ()
153+ handleAboutFlag = do
154+ path <- getExecutablePath
155+ let content =
156+ unlines
157+ [ path <> " v" <> (showVersion version)
158+ , " Copyright (C) 2017 Sibi Prabakaran"
159+ , " Source available at https://github.com/psibi/tldr-hs"
160+ ]
161+ putStr content
162+
150163handleTldrOpts :: TldrOpts -> IO ()
151164handleTldrOpts TldrOpts {.. } = do
152165 case tldrAction of
153166 UpdateIndex -> updateTldrPages
167+ About -> handleAboutFlag
154168 ViewPage voptions pages -> do
155169 let npage = intercalate " -" pages
156170 fname <- getPagePath npage (getCheckDirs voptions)
0 commit comments