From f4490637894cd670a97e2fe53aa359fd75465d09 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 6 Feb 2017 19:19:45 +0100 Subject: Added help text --- clpm.icl | 76 ++++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 21 deletions(-) diff --git a/clpm.icl b/clpm.icl index ad627fa..26b98f4 100644 --- a/clpm.icl +++ b/clpm.icl @@ -1,5 +1,6 @@ module clpm +import _SystemArray from StdFunc import flip, o import StdFile import StdList @@ -26,6 +27,8 @@ import System.File import CLPM.Package import CLPM.Repository +CLPM_VERSION :== (0,1,0) + :: Action = NoAction | Install @@ -36,24 +39,27 @@ import CLPM.Repository , action :: Action , repository :: String , clm_options :: [String] + , show_help :: Bool } instance zero Arguments where zero = { package_file = PACKAGE_FILE - , action = NoAction - , repository = REPOSITORY - , clm_options = [] + , action = NoAction + , repository = REPOSITORY + , clm_options = [] + , show_help = False } Start w # (io,w) = stdio w -# ((missed, args), w) = appFst (parseArgs [] zero o tl) $ getCommandLine w +# ((missed, args), w) = appFst (parseArgs zero o tl) $ getCommandLine w | not (isEmpty missed) # io = foldr (flip (<<<)) io ["Unknown option: " + m + "\n" \\ m <- missed] - # (_,w) = fclose io w - = w + = snd $ fclose io w +| args.show_help + = snd $ fclose (io <<< HELP_TEXT) w # (pkg,w) = readPackage args.package_file w | isError pkg # io = io <<< fromError pkg <<< "\n" @@ -106,23 +112,51 @@ make opts pkg io w " " + pkg.main + " -o " + pkg.main) w = (io,w) -parseArgs :: [String] Arguments [String] -> ([String], Arguments) -parseArgs miss args [] - = (miss, args) -parseArgs miss args ["-p":name:rest] - = parseArgs miss {args & package_file = name} rest -parseArgs miss args ["-r":repo:rest] - = parseArgs miss {args & repository = repo} rest -parseArgs miss args ["-c":opt:rest] - = parseArgs miss {args & clm_options = args.clm_options ++ [opt]} rest -parseArgs miss args ["install":rest] - = parseArgs miss {args & action = Install} rest -parseArgs miss args ["make":rest] - = parseArgs miss {args & action = Make} rest -parseArgs miss args [a:rest] - = parseArgs [a:miss] args rest +parseArgs :: (Arguments [String] -> ([String], Arguments)) +parseArgs = pa [] +where + pa :: [String] Arguments [String] -> ([String], Arguments) + pa miss args [] = (miss, args) + pa miss args ["-h":rest] = pa miss {args & show_help = True} rest + pa miss args ["--help":rest] = pa miss {args & show_help = True} rest + pa miss args ["-p":name:rest] = pa miss {args & package_file = name} rest + pa miss args ["-r":repo:rest] = pa miss {args & repository = repo} rest + pa miss args ["-c":opt:rest] = pa miss {args & clm_options = args.clm_options ++ [opt]} rest + pa miss args ["install":rest] = pa miss {args & action = Install} rest + pa miss args ["make":rest] = pa miss {args & action = Make} rest + pa miss args [a:rest] = pa [a:miss] args rest syscall :: !String !*World -> !*(!Int, !*World) syscall cmd w = code { ccall system "s:I:A" } + +HELP_TEXT =: + "CLPM - A Clean Package Manager - v" + toString CLPM_VERSION + "\r\n\r\n" + + "Usage: clpm [option]\r\n\r\n" + + foldl (+) "Commands:\r\n" + [pad 2 12 cmd + desc + "\r\n" \\ (cmd,desc) <- cmds] + "\r\n" + + foldl (+) "Options:\r\n" + [pad 2 12 opt + desc + "\r\n" \\ (opt,desc) <- opts] +where + cmds = + [ ("make", "Build package using clm") + , ("install", "Install package dependencies") + ] + + opts = + [ ("-c ", + "Add OPT to the clm arguments") + , ("-h, --help", + "Print this help text") + , ("-p ", + "Use FILE as package file instead of package.json") + , ("-r ", + "Use HOST as repository provider instead of " + REPOSITORY) + ] + + pad :: Int Int String -> String + pad l r s + | size s > r = p l + s + "\r\n" + p (l + r) + | otherwise = p l + s + p (r - size s) + where p i = toString $ repeatn i ' ' -- cgit v1.2.3