args
that follow
redef fun apply(args)
do
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 IniFile.from_file(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
src/nitpm.nit:64,2--91,4
redef fun apply(args)
do
if args.length != 1 then
print_local_help
exit 1
end
var name = args.first
var target_dir = nitpm_lib_dir / name
if not target_dir.file_exists or not target_dir.to_path.is_dir then
print_error "Package not found"
exit 1
end
check_git
var cmd = "cd {target_dir.escape_to_sh}; git pull"
if verbose then print "+ {cmd}"
var proc = new Process("sh", "-c", cmd)
proc.wait
if proc.status != 0 then
print_error "Upgrade failed"
exit 1
end
end
src/nitpm.nit:214,2--241,4
redef fun apply(args)
do
var opt_force = "-f"
var force = args.has(opt_force)
if force then args.remove(opt_force)
if args.is_empty then
print_local_help
exit 1
end
for name in args do
var clean_nitpm_lib_dir = nitpm_lib_dir.simplify_path
var target_dir = clean_nitpm_lib_dir / name
# Check validity of the package to delete
target_dir = target_dir.simplify_path
var within_dir = target_dir.has_prefix(clean_nitpm_lib_dir + "/") and
target_dir.length > clean_nitpm_lib_dir.length + 1
var valid_name = name.length > 0 and name.chars.first.is_lower
if not valid_name or not within_dir then
print_error "Package name '{name}' is invalid"
continue
end
if not target_dir.file_exists or not target_dir.to_path.is_dir then
print_error "Package not found"
exit 1
end
# Ask confirmation
if not force then
var response = prompt("Delete {target_dir.escape_to_sh}? [Y/n] ")
var accept = response != null and
(response.to_lower == "y" or response.to_lower == "yes" or response == "")
if not accept then return
end
var cmd = "rm -rf {target_dir.escape_to_sh}"
if verbose then print "+ {cmd}"
var proc = new Process("sh", "-c", cmd)
proc.wait
if proc.status != 0 then
print_error "Uninstall failed"
exit 1
end
end
end
src/nitpm.nit:252,2--302,4
redef fun apply(args)
do
var files = nitpm_lib_dir.files
var name_to_desc = new Map[String, nullable String]
var max_name_len = 0
# Collect package info
for file in files do
var ini_path = nitpm_lib_dir / file / "package.ini"
if verbose then print "- Reading ini file at {ini_path}"
var ini = new IniFile.from_file(ini_path)
var tags = ini["package.tags"]
name_to_desc[file] = tags
max_name_len = max_name_len.max(file.length)
end
# Sort in alphabetical order
var sorted_names = name_to_desc.keys.to_a
alpha_comparator.sort sorted_names
# Print with clear columns
for name in sorted_names do
var col0 = name.justify(max_name_len+1, 0.0)
var col1 = name_to_desc[name] or else ""
var line = col0 + col1
print line.trim
end
end
src/nitpm.nit:313,2--341,4
redef fun apply(args)
do
# Try first to help about a valid action
if args.length == 1 then
var command = commands.get_or_null(args.first)
if command != null then
command.print_local_help
return
end
end
print_help
end
src/nitpm.nit:352,2--364,4