wasp/waspc/cli/Main.hs

73 lines
1.8 KiB
Haskell
Raw Normal View History

module Main where
import System.Environment
2020-10-29 15:15:13 +03:00
import Paths_waspc (version)
import Data.Version (showVersion)
import Command (runCommand)
2020-11-04 17:26:35 +03:00
import Command.Db (runDbCommand, studio)
import Command.CreateNewProject (createNewProject)
import Command.Start (start)
import Command.Clean (clean)
2020-09-19 17:11:09 +03:00
import Command.Compile (compile)
import Command.Db.Migrate (migrateSave, migrateUp)
main :: IO ()
main = do
args <- getArgs
case args of
["new", projectName] -> runCommand $ createNewProject projectName
["start"] -> runCommand start
["clean"] -> runCommand clean
2020-09-19 17:11:09 +03:00
["compile"] -> runCommand compile
("db":dbArgs) -> dbCli dbArgs
2020-10-29 15:15:13 +03:00
["version"] -> printVersion
_ -> printUsage
printUsage :: IO ()
printUsage = putStrLn $ unlines
[ "Usage:"
, " wasp <command> [command-args]"
, ""
, "Commands:"
, " new <project-name>"
, " start"
, " clean"
, " db <commmand> [command-args]"
2020-10-29 15:15:13 +03:00
, " version"
, ""
, "Examples:"
, " wasp new MyApp"
, " wasp start"
2020-10-29 15:15:13 +03:00
, " wasp db migrate-save \"init\""
, ""
, "Documentation is available at https://wasp-lang.dev/docs ."
]
2020-10-29 15:15:13 +03:00
printVersion :: IO ()
printVersion = putStrLn $ showVersion version
-- TODO(matija): maybe extract to a separate module, e.g. DbCli.hs?
dbCli :: [String] -> IO ()
dbCli args = case args of
["migrate-save", migrationName] -> runDbCommand $ migrateSave migrationName
["migrate-up"] -> runDbCommand migrateUp
2020-11-04 17:26:35 +03:00
["studio"] -> runDbCommand studio
_ -> printDbUsage
printDbUsage :: IO ()
printDbUsage = putStrLn $ unlines
[ "Usage:"
, " wasp db <command> [command-args]"
, ""
, "Commands:"
, " migrate-save <migration-name>"
, " migrate-up"
2020-11-04 17:26:35 +03:00
, " studio"
, ""
, "Examples:"
, " wasp db migrate-save \"Added description field.\""
, " wasp db migrate-up"
]