From a3aa0c9d68a86665cf351999844700976a36854e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Sat, 3 Mar 2018 16:11:04 -0500 Subject: [PATCH] nitpm: install packages listed in package.ini by default MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- src/picnit.nit | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/src/picnit.nit b/src/picnit.nit index 5df3bcd..bac74eb 100644 --- a/src/picnit.nit +++ b/src/picnit.nit @@ -55,17 +55,50 @@ class CommandInstall super Command redef fun name do return "install" - redef fun usage do return "picnit install [package or git-repository]" - redef fun description do return "Install a package by its name or from a git-repository" + redef fun usage do return "picnit install [package0 [package1 ...]]" + redef fun description do return "Install packages by name, Git repository address or from the local package.ini" redef fun apply(args) do - if args.length != 1 then - print_local_help - exit 1 + if args.not_empty then + # Install each package + for arg in args do + # Parse each arg as an import string, with versions and commas + install_packages arg + end + else + # Install packages from local package.ini + var ini_path = "package.ini" + if not ini_path.file_exists then + print_error "Local `package.ini` not found." + print_local_help + exit 1 + end + + var ini = new ConfigTree(ini_path) + var import_line = ini["package.import"] + if import_line == null then + print_error "The local `package.ini` declares no external dependencies." + exit 0 + abort + end + + install_packages import_line end + end - var package_id = args.first + # Install packages defined by the `import_line` + private fun install_packages(import_line: String) + do + var imports = import_line.parse_import + for name, ext_package in imports do + install_package(ext_package.id, ext_package.version) + end + end + + # Install the `package_id` at `version` + private fun install_package(package_id: String, version: nullable String) + do if package_id.is_package_name then # Ask a centralized server # TODO choose a future safe URL -- 1.7.9.5