]> Git — Sourcephile - majurity.git/blob - hjugement-cli/src/Hjugement/CLI.hs
protocol: add verification of trustees' public key
[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 import Hjugement.CLI.Voter
41
42 progname :: Text
43 progname = "hjugement"
44
45 api =
46 program "hjugement" $
47 (api_options <?> api_agent) <!>
48 api_help True <!>
49 api_version
50 run =
51 run_agent :!:
52 run_help api :!:
53 run_version
54
55 api_agent =
56 rule "AGENT" $
57 api_administrator <!>
58 api_trustee <!>
59 api_registrar <!>
60 api_voter
61 run_agent params =
62 run_administrator params :!:
63 run_trustee params :!:
64 run_registrar params :!:
65 run_voter params
66
67 api_version =
68 "Print the version."
69 `helps`
70 tag (TagLong "version") nothing
71 <.> response @Doc
72 run_version =
73 return (Doc.from version <> Doc.newline)
74 version :: Text
75 version =
76 progname <> "-" <>
77 Text.pack (Version.showVersion Hjugement.version)
78
79 parseAPI = parser @Void @Doc api run