diff options
author | James Crayne <jim.crayne@gmail.com> | 2019-10-17 03:09:47 +0000 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2020-01-01 19:43:44 -0500 |
commit | 03c5291a9bc3bf76f63d6929abdf4eaf25dbd18e (patch) | |
tree | bb8ca903bd9bdbbe11e98a9b45d3b5dd5df19ac3 /dht/examples/dhtd.hs | |
parent | b7e7e047d07b1277b13cf3bf4fa28ceac5ecda2a (diff) |
--help for dhtd
Diffstat (limited to 'dht/examples/dhtd.hs')
-rw-r--r-- | dht/examples/dhtd.hs | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/dht/examples/dhtd.hs b/dht/examples/dhtd.hs index 2772416b..e0b58539 100644 --- a/dht/examples/dhtd.hs +++ b/dht/examples/dhtd.hs | |||
@@ -47,6 +47,7 @@ import GHC.Conc (threadStatus,ThreadStatus(..)) | |||
47 | import GHC.Stats | 47 | import GHC.Stats |
48 | import Network.Socket | 48 | import Network.Socket |
49 | import System.Environment | 49 | import System.Environment |
50 | import System.Exit | ||
50 | import System.IO | 51 | import System.IO |
51 | import System.Mem | 52 | import System.Mem |
52 | import System.Posix.Process | 53 | import System.Posix.Process |
@@ -121,6 +122,7 @@ import DebugTag | |||
121 | import LocalChat | 122 | import LocalChat |
122 | import ToxChat | 123 | import ToxChat |
123 | import MUC | 124 | import MUC |
125 | import Data.Either | ||
124 | 126 | ||
125 | 127 | ||
126 | pshow :: Show a => a -> B.ByteString | 128 | pshow :: Show a => a -> B.ByteString |
@@ -1135,10 +1137,33 @@ sensibleDefaults = Options | |||
1135 | , verboseTags = [XUnexpected, XUnused] | 1137 | , verboseTags = [XUnexpected, XUnused] |
1136 | } | 1138 | } |
1137 | 1139 | ||
1140 | data ShowHelp = ShowHelp | ||
1141 | deriving (Eq,Show) | ||
1142 | |||
1143 | usage ShowHelp | ||
1144 | = let { cs = [ ([["--help"]] ,["display this help"]) | ||
1145 | , ([["--dhtkey ",dhtkey] | ||
1146 | ,["--dht-key ",dhtkey]],["use ",dhtkey," as the dht key"]) | ||
1147 | , ([["-4"]] ,["Use IPv4 only"]) | ||
1148 | , ([["-v ",tags]] ,["Enable or disable specified DebugTags.\n DebugTags = ", listDebugTags]) | ||
1149 | ] ; | ||
1150 | dhtkey ="<dhtkey>" ; | ||
1151 | tags = "[-]Tag1,[-]Tag2,... " ; | ||
1152 | -- TODO: word-wrap listDebugTags for terminal width | ||
1153 | listDebugTags = intercalate ", " $ map ((drop 1) . show) ([minBound .. maxBound]::[DebugTag]) ; | ||
1154 | } in do | ||
1155 | putStrLn "dhtd OPTIONS\n" | ||
1156 | forM cs $ \(how,what) -> do | ||
1157 | forM how $ putStrLn . (" "++) . concat | ||
1158 | putStr "\t" | ||
1159 | putStrLn . concat $ what | ||
1160 | exitFailure | ||
1161 | |||
1138 | -- bt=<port>,tox=<port> | 1162 | -- bt=<port>,tox=<port> |
1139 | -- -4 | 1163 | -- -4 |
1140 | parseArgs :: [String] -> Options -> Options | 1164 | parseArgs :: [String] -> Options -> Either ShowHelp Options |
1141 | parseArgs [] opts = opts | 1165 | parseArgs [] opts = Right opts |
1166 | parseArgs ("--help":args) opts = Left ShowHelp | ||
1142 | parseArgs ("--dhtkey":k:args) opts = parseArgs args opts | 1167 | parseArgs ("--dhtkey":k:args) opts = parseArgs args opts |
1143 | { dhtkey = decodeSecret $ B.pack k } | 1168 | { dhtkey = decodeSecret $ B.pack k } |
1144 | parseArgs ("--dht-key":k:args) opts = parseArgs args opts | 1169 | parseArgs ("--dht-key":k:args) opts = parseArgs args opts |
@@ -1619,8 +1644,9 @@ initJabber opts ssvar announcer mbtox toxdhts toxchat = case portxmpp opts of | |||
1619 | main :: IO () | 1644 | main :: IO () |
1620 | main = do | 1645 | main = do |
1621 | args <- getArgs | 1646 | args <- getArgs |
1622 | let opts = parseArgs args sensibleDefaults | 1647 | let eopts = parseArgs args sensibleDefaults |
1623 | print opts | 1648 | either usage print eopts -- quits on left |
1649 | let Right opts = eopts | ||
1624 | 1650 | ||
1625 | swarms <- Mainline.newSwarmsDatabase | 1651 | swarms <- Mainline.newSwarmsDatabase |
1626 | -- Restore peer database before forking the listener thread. | 1652 | -- Restore peer database before forking the listener thread. |