forked from b3nj5m1n/xdg-ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xdgnj.hs
50 lines (41 loc) · 1.64 KB
/
xdgnj.hs
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
38
39
40
41
42
43
44
45
46
47
48
49
50
module Main where
import qualified AddProgram as PA
import qualified Checks as C
import Data.Semigroup ((<>))
import qualified EditProgram as PE
import Options.Applicative
import qualified PreviewProgram as PP
data Args = RunChecks
| AddProgram
| EditProgram String
| PreviewProgram String
| LintProgram String
| Lint
deriving Show
editProgram :: Parser Args
editProgram = EditProgram <$> argument str (metavar "PROGRAM")
previewProgram :: Parser Args
previewProgram = PreviewProgram <$> argument str (metavar "PROGRAM")
lintProgram :: Parser Args
lintProgram = LintProgram <$> argument str (metavar "PROGRAM")
argsParser :: Parser Args
argsParser = subparser
(command "run" (info (pure RunChecks) (progDesc "Run checks"))
<> command "add" (info (pure AddProgram) (progDesc "Add program"))
<> command "edit" (info editProgram (progDesc "Edit program config"))
<> command "prev" (info previewProgram (progDesc "Preview program config"))
<> command "lintp" (info lintProgram (progDesc "Lint program config"))
<> command "lint" (info (pure Lint) (progDesc "Lint all program configs")))
args :: ParserInfo Args
args = info (argsParser <**> helper)
( fullDesc
<> progDesc "xdg-ninja utilities")
main :: IO ()
main = do
args <- execParser args
case args of
RunChecks -> C.checkDir "./programs"
AddProgram -> PA.saveProgram
EditProgram filename -> PE.editProgram filename
PreviewProgram filename -> PP.previewProgramFile filename
_ -> print args