aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2017-02-06 19:19:45 +0100
committerCamil Staps2017-02-06 19:19:45 +0100
commitf4490637894cd670a97e2fe53aa359fd75465d09 (patch)
treed1ee85234ae328a372133595d3895774c0a01c3f
parentStart with repository and dependency resolution (diff)
Added help text
-rw-r--r--clpm.icl76
1 files 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 <command> [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 <OPT>",
+ "Add OPT to the clm arguments")
+ , ("-h, --help",
+ "Print this help text")
+ , ("-p <FILE>",
+ "Use FILE as package file instead of package.json")
+ , ("-r <HOST>",
+ "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 ' '