aboutsummaryrefslogtreecommitdiff
path: root/src/Main.hs
blob: 7101af06e1437f5d97e9be62b683312b54afaf69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{-# LANGUAGE QuasiQuotes #-}
module Main (
  main
) where

import Data.Maybe (fromJust)
import Data.Version (showVersion)
import Paths_sproxy2 (version) -- from cabal
import System.Environment (getArgs)
import Text.InterpolatedString.Perl6 (qc)
import qualified System.Console.Docopt.NoTH as O

import Sproxy.Server (server)

usage :: String
usage =  "sproxy2 " ++ showVersion version ++
  " - HTTP proxy for authenticating users via OAuth2" ++ [qc|

Usage:
  sproxy2 [options]

Options:
  -c, --config=FILE        Configuration file [default: sproxy.yml]
  -h, --help               Show this message

|]

main :: IO ()
main = do
  doco <- O.parseUsageOrExit usage
  args <- O.parseArgsOrExit doco =<< getArgs
  if args `O.isPresent` O.longOption "help"
  then putStrLn $ O.usage doco
  else do
    let configFile = fromJust . O.getArg args $ O.longOption "config"
    server configFile