]> Git — Sourcephile - majurity.git/blob - hjugement-cli/src/Hjugement/CLI.hs
protocol: fix ToJSON ElectionCrypto
[majurity.git] / hjugement-cli / src / Hjugement / CLI.hs
1 {-# LANGUAGE AllowAmbiguousTypes #-}
2 {-# LANGUAGE OverloadedStrings #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# LANGUAGE TypeApplications #-}
5 {-# LANGUAGE NamedFieldPuns #-}
6 {-# OPTIONS_GHC -Wno-missing-signatures #-}
7 module Hjugement.CLI where
8
9 import Control.Applicative (Applicative(..), Alternative(..))
10 import Control.Monad (Monad(..))
11 import Data.Bool
12 import Data.Either (Either(..))
13 import Data.Function (($), (.))
14 import Data.Functor ((<$>), (<$))
15 import Data.Int (Int)
16 import Data.List.NonEmpty (NonEmpty(..))
17 import Data.Maybe (Maybe(..), fromMaybe)
18 import Data.Ord (Ord(..))
19 import Data.Semigroup (Semigroup(..))
20 import Data.String (String)
21 import Data.Text (Text)
22 import Data.Void (Void)
23 import Symantic.CLI as CLI
24 import System.Environment (getArgs)
25 import System.IO (IO, FilePath, print, stderr, putStrLn)
26 import Text.Show (Show(..))
27 import Type.Reflection (Typeable)
28 import qualified Data.Set as Set
29 import qualified Data.Text as Text
30 import qualified Data.Text.Lazy.IO as TL
31 import qualified Data.Version as Version
32 import qualified Paths_hjugement_cli as Hjugement
33 import qualified Symantic.Document as Doc
34 import qualified System.IO as IO
35
36 import Hjugement.CLI.Utils
37 import Hjugement.CLI.Administrator
38 import Hjugement.CLI.Registrar
39 import Hjugement.CLI.Trustee
40
41 progname :: Text
42 progname = "hjugement"
43
44 api =
45 program "hjugement" $
46 (api_options <?> api_agent) <!>
47 api_help True <!>
48 api_version
49 run =
50 run_agent :!:
51 run_help api :!:
52 run_version
53
54 api_agent =
55 rule "AGENT" $
56 api_administrator <!>
57 api_trustee <!>
58 api_registrar
59 run_agent params =
60 run_administrator params :!:
61 run_trustee params :!:
62 run_registrar params
63
64 api_version =
65 "Print the version."
66 `helps`
67 tag (TagLong "version") nothing
68 <.> response @Doc
69 run_version =
70 return (Doc.from version <> Doc.newline)
71 version :: Text
72 version =
73 progname <> "-" <>
74 Text.pack (Version.showVersion Hjugement.version)
75
76 parseAPI = parser @Void @Doc api run