Skip to content

Commit ec0f029

Browse files
committed
Update documentation, bump version
1 parent 2b6be07 commit ec0f029

4 files changed

Lines changed: 55 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
* Make it obey --platform option
44
* Add -u as an alias for --update
5-
5+
* Make parsing more robust
66

77
# 0.5.1
88

@@ -12,7 +12,7 @@
1212

1313
* Obey XdgData for storing the files.
1414
* Also search pages from sunos directory now.
15-
* Support subcommansds ie. tldr git submodule will now work.
15+
* Support subcommands ie. tldr git submodule will now work.
1616

1717
# 0.4.0.2
1818

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,35 @@ Haskell client for tldr
1919
$ tldr --help
2020
tldr - Simplified and community-driven man pages
2121

22-
Usage: tldr [-v|--version] [--update] COMMAND
22+
Usage: tldr [-v|--version] ((-u|--update) | [-p|--platform PLATFORM] COMMAND)
2323
tldr Client program
2424

2525
Available options:
2626
-h,--help Show this help text
2727
-v,--version Show version
28-
--update Update tldr pages
28+
-u,--update Update offline cache of tldr pages
29+
-p,--platform PLATFORM Prioritize specfic platform while searching. Valid
30+
values include linux, osx, windows, sunos
2931
COMMAND name of the command
3032
```
3133

34+
Or a much better example of the usage:
35+
36+
``` shellsession
37+
$ tldr tldr
38+
tldr
39+
Simplified man pages.More information: https://tldr.sh.
40+
41+
- Get typical usages of a command (hint: this is how you got here!):
42+
tldr {{command}}
43+
44+
- Show the tar tldr page for linux:
45+
tldr -p {{linux}} {{tar}}
46+
47+
- Get help for a git subcommand:
48+
tldr {{git checkout}}
49+
```
50+
3251
## Snapshot
3352

3453
![tldr](https://cloud.githubusercontent.com/assets/737477/24076451/2a5a604c-0c57-11e7-9bf7-13d76e8e7f12.png)

app/Main.hs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE ScopedTypeVariables #-}
22
{-# LANGUAGE RecordWildCards #-}
3+
{-# LANGUAGE BangPatterns #-}
34

45
module Main
56
( main
@@ -8,6 +9,7 @@ module Main
89
import Control.Monad
910
import Data.List (intercalate)
1011
import Data.Semigroup ((<>))
12+
import qualified Data.Set as Set
1113
import Data.Version (showVersion)
1214
import GHC.IO.Handle.FD (stdout)
1315
import Options.Applicative
@@ -39,7 +41,10 @@ programOptions :: Parser TldrOpts
3941
programOptions = (TldrOpts <$> (updateIndexCommand <|> viewPageCommand))
4042

4143
updateIndexCommand :: Parser TldrCommand
42-
updateIndexCommand = flag' UpdateIndex (long "update" <> short 'u')
44+
updateIndexCommand =
45+
flag'
46+
UpdateIndex
47+
(long "update" <> short 'u' <> help "Update offline cache of tldr pages")
4348

4449
viewOptionsParser :: Parser ViewOptions
4550
viewOptionsParser = ViewOptions <$> platformFlag
@@ -51,7 +56,15 @@ viewPageCommand =
5156

5257
platformFlag :: Parser (Maybe String)
5358
platformFlag =
54-
optional (strOption (long "platform" <> short 'p' <> metavar "PLATFORM"))
59+
optional
60+
(strOption
61+
(long "platform" <> short 'p' <> metavar "PLATFORM" <>
62+
help
63+
("Prioritize specfic platform while searching. Valid values include " <>
64+
platformHelpValue)))
65+
where
66+
platformHelpValue :: String
67+
platformHelpValue = intercalate ", " platformDirs
5568

5669
tldrDirName :: String
5770
tldrDirName = "tldr"
@@ -60,7 +73,10 @@ repoHttpsUrl :: String
6073
repoHttpsUrl = "https://github.com/tldr-pages/tldr.git"
6174

6275
checkDirs :: [String]
63-
checkDirs = ["common", "linux", "osx", "windows", "sunos"]
76+
checkDirs = "common" : platformDirs
77+
78+
platformDirs :: [String]
79+
platformDirs = ["linux", "osx", "windows", "sunos"]
6480

6581
tldrInitialized :: IO Bool
6682
tldrInitialized = do
@@ -120,7 +136,16 @@ getCheckDirs :: ViewOptions -> [String]
120136
getCheckDirs voptions =
121137
case platformOption voptions of
122138
Nothing -> checkDirs
123-
Just platform -> ["common", platform]
139+
Just platform -> nubOrd $ ["common", platform] <> checkDirs
140+
141+
-- | Strip out duplicates
142+
nubOrd :: Ord a => [a] -> [a]
143+
nubOrd = loop mempty
144+
where
145+
loop _ [] = []
146+
loop !s (a:as)
147+
| a `Set.member` s = loop s as
148+
| otherwise = a : loop (Set.insert a s) as
124149

125150
handleTldrOpts :: TldrOpts -> IO ()
126151
handleTldrOpts TldrOpts {..} = do

tldr.cabal

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: tldr
2-
version: 0.5.1
2+
version: 0.6.0
33
synopsis: Haskell tldr client
44
description: Haskell tldr client with support for viewing tldr pages. Has offline
5-
cache for accessing pages.
5+
cache for accessing pages. Visit https://tldr.sh for more details.
66
homepage: https://github.com/psibi/tldr-hs#readme
77
license: BSD3
88
license-file: LICENSE
@@ -36,6 +36,7 @@ executable tldr
3636
, filepath
3737
, typed-process
3838
, semigroups
39+
, containers
3940
default-language: Haskell2010
4041

4142
test-suite tldr-test

0 commit comments

Comments
 (0)