WIP CLI
[xyz.git] / app / Main.hs
1 module Main where
2
3 import Lib
4 import System.Environment
5 import System.Exit
6 import System.Directory
7 import Prelude hiding (init)
8 import Data.List (intercalate)
9 import Text.JSON
10 import Data.Text hiding (intercalate, unlines, init)
11
12 data Project = Project {
13 name :: Text,
14 description :: Text
15 } deriving (Show)
16
17 main :: IO ()
18 main = getArgs >>= parse
19
20 init :: IO ()
21 init = do
22 dirExists <- doesDirectoryExist "entries"
23 if dirExists
24 then putStrLn "Project already initialised"
25 else do createDirectory "entries"
26 putStrLn "Enter a name for your project:"
27 projectName <- getLine
28 putStrLn "Enter short description for your project:"
29 projectDescription <- getLine
30 writeFile "xyz.json" . encode . toJSObject $ [("name", projectName), ("description", projectDescription), ("theme", "xyz")]
31 putStrLn "Initialised empty project"
32
33
34 ununlines :: [String] -> String
35 ununlines = intercalate "\n\n"
36
37 usage :: IO ()
38 usage = putStr . ununlines $ [
39 "usage: xyz <command>",
40 "Commands:", unlines [
41 "\tinit\t\tInitialise a new site",
42 "\tbuild\t\tBuild the site"
43 ]
44 ]
45
46 parse ["init"] = init >> exit
47 parse ["build"] = putStrLn "would do a build" >> exit
48 parse [_] = usage >> exit
49 parse [] = usage >> exit
50
51 exit = exitWith ExitSuccess