aboutsummaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 58ae99f..7e72a0a 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -9,16 +9,19 @@ import Data.Maybe (fromJust)
import Data.Version (showVersion)
import Database.MySQL.Base (ConnectInfo(..))
import Database.MySQL.Base.Types (Option(ReadDefaultFile, ReadDefaultGroup))
-import Paths_juandelacosa (version) -- from cabal
+import Paths_juandelacosa (getDataDir, version) -- from cabal
import System.Environment (getArgs)
-import Text.RawString.QQ (r)
+import Text.InterpolatedString.Perl6 (qc)
import qualified System.Console.Docopt.NoTH as O
import Server (server)
-usage :: String
-usage = "juandelacosa " ++ showVersion version
- ++ " manage MariaDB user and roles" ++ [r|
+usage :: IO String
+usage = do
+ dataDir <- getDataDir
+ return $
+ "juandelacosa " ++ showVersion version
+ ++ " manage MariaDB user and roles" ++ [qc|
Usage:
juandelacosa [options]
@@ -27,6 +30,8 @@ Options:
-f, --file=MYCNF Read this MySQL client config file
-g, --group=GROUP Read this options group in the above file [default: client]
+ -d, --datadir=DIR Data directory including static files [default: {dataDir}]
+
-s, --socket=SOCK Listen on this UNIX-socket [default: /tmp/juandelacosa.sock]
-p, --port=PORT Instead of UNIX-socket, listen on this TCP port (localhost)
@@ -36,7 +41,7 @@ Options:
main :: IO()
main = do
- doco <- O.parseUsageOrExit usage
+ doco <- O.parseUsageOrExit =<< usage
args <- O.parseArgsOrExit doco =<< getArgs
if args `O.isPresent` O.longOption "help"
then putStrLn $ O.usage doco
@@ -46,6 +51,7 @@ main = do
group = fromJust $ O.getArg args $ O.longOption "group"
port = O.getArg args $ O.longOption "port"
socket = fromJust $ O.getArg args $ O.longOption "socket"
+ datadir = fromJust $ O.getArg args $ O.longOption "datadir"
-- XXX: mysql package maps empty strings to NULL
-- which is what we need, see documentation for mysql_real_connect()
let myInfo = ConnectInfo {
@@ -63,5 +69,5 @@ main = do
let listen = case port of
Nothing -> Right socket
Just p -> Left $ read p
- server listen myInfo
+ server listen myInfo datadir