From e9ab8875d1dad2e4533ddbbbfa0c92609bc1b84a Mon Sep 17 00:00:00 2001 From: Cameron Ball Date: Mon, 18 Feb 2019 18:28:43 +0800 Subject: [PATCH] WIP CLI --- app/Main.hs | 47 ++++++++++++++++++++++++++++++++++++++++++++++- package.yaml | 1 + 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/app/Main.hs b/app/Main.hs index de1c1ab..601f13f 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -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 ", + "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 diff --git a/package.yaml b/package.yaml index 5330be3..4fca695 100644 --- a/package.yaml +++ b/package.yaml @@ -25,6 +25,7 @@ dependencies: - time - filepath - template +- json library: source-dirs: src -- 2.11.0