WIP CLI
authorCameron Ball <cameron@moodle.com>
Mon, 18 Feb 2019 10:28:43 +0000 (18:28 +0800)
committerCameron Ball <cameron@moodle.com>
Mon, 18 Feb 2019 10:28:43 +0000 (18:28 +0800)
app/Main.hs
package.yaml

index de1c1ab..601f13f 100644 (file)
@@ -1,6 +1,51 @@
 module Main where
 
 import Lib
+import System.Environment
+import System.Exit
+import System.Directory
+import Prelude hiding (init)
+import Data.List (intercalate)
+import Text.JSON
+import Data.Text hiding (intercalate, unlines, init)
+
+data Project = Project {
+  name :: Text,
+  description :: Text
+  } deriving (Show)
 
 main :: IO ()
-main = someFunc
+main = getArgs >>= parse
+
+init :: IO ()
+init = do
+  dirExists <- doesDirectoryExist "entries"
+  if dirExists
+    then putStrLn "Project already initialised"
+    else do createDirectory "entries"
+            putStrLn "Enter a name for your project:"
+            projectName <- getLine
+            putStrLn "Enter short description for your project:"
+            projectDescription <- getLine
+            writeFile "xyz.json" . encode . toJSObject $ [("name", projectName), ("description", projectDescription), ("theme", "xyz")]
+            putStrLn "Initialised empty project"
+
+
+ununlines :: [String] -> String
+ununlines = intercalate "\n\n"
+
+usage :: IO ()
+usage =  putStr . ununlines $ [
+  "usage: xyz <command>",
+  "Commands:", unlines [
+      "\tinit\t\tInitialise a new site",
+      "\tbuild\t\tBuild the site"
+                       ]
+  ]
+
+parse ["init"] = init >> exit
+parse ["build"] = putStrLn "would do a build" >> exit
+parse [_] = usage >> exit
+parse [] = usage >> exit
+
+exit = exitWith ExitSuccess
index 5330be3..4fca695 100644 (file)
@@ -25,6 +25,7 @@ dependencies:
 - time
 - filepath
 - template
+- json
 
 library:
   source-dirs: src