1 -- This file is part of Diohsc
2 -- Copyright (C) 2020 Martin Bays <mbays@sdf.org>
4 -- This program is free software: you can redistribute it and/or modify
5 -- it under the terms of version 3 of the GNU General Public License as
6 -- published by the Free Software Foundation, or any later version.
8 -- You should have received a copy of the GNU General Public License
9 -- along with this program. If not, see http://www.gnu.org/licenses/.
13 module Opts
(usage
, parseArgs
, Opt
(..)) where
15 import System
.Console
.GetOpt
34 deriving (Eq
, Ord
, Show)
36 options
:: [OptDescr Opt
]
38 [ Option
['d
'] ["datadir"] (ReqArg DataDir
"PATH") "data and config directory (default: ~/.diohsc)"
39 , Option
['e
'] ["command"] (ReqArg OptCommand
"COMMAND") "execute command"
40 , Option
['f
'] ["file"] (ReqArg ScriptFile
"PATH") "execute commands from file (\"-\" for stdin)"
41 , Option
['p
'] ["prompt"] (NoArg Prompt
) "prompt for further commands after -e/-f"
42 , Option
['i
'] ["interact"] (NoArg Interactive
) "interactive mode (assumed unless -e/-f used)"
43 , Option
['b
'] ["batch"] (NoArg Batch
) "non-interactive mode (assumed if -e/-f used)"
44 , Option
['c
'] ["colour"] (NoArg Ansi
) "use ANSI colour (assumed if stdout is term)"
45 , Option
['C
'] ["no-colour"] (NoArg NoAnsi
) "do not use ANSI colour"
46 , Option
['g
'] ["ghost"] (NoArg Ghost
) "write nothing to filesystem (unless commanded)"
47 , Option
['r
'] ["restricted"] (NoArg Restricted
) "disallow shell and filesystem access"
48 , Option
['S
'] ["socks-host"] (ReqArg SocksHost
"HOST") "use SOCKS5 proxy"
49 , Option
['P
'] ["socks-port"] (ReqArg SocksPort
"PORT") "port for SOCKS5 proxy (default 1080)"
50 , Option
['v
'] ["version"] (NoArg Version
) "show version information"
51 , Option
['h
'] ["help"] (NoArg Help
) "show usage information"
55 usage
= usageInfo header options
56 where header
= "Usage: " ++ programName
++ " [OPTION...] [URI|PATH]"
58 parseArgs
:: [String] -> IO ([Opt
],[String])
60 case getOpt Permute options argv
of
61 (o
,n
,[]) -> return (o
,n
)
62 (_
,_
,errs
) -> ioError (userError (concat errs
++ usage
))