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