2017-01-28 04:49:09 +08:00
|
|
|
#include "pch.h"
|
2017-04-28 09:08:52 +08:00
|
|
|
|
2016-09-22 14:54:23 +08:00
|
|
|
#include "vcpkg_Commands.h"
|
|
|
|
#include "vcpkg_System.h"
|
2017-04-28 09:08:52 +08:00
|
|
|
#include "vcpkglib.h"
|
2016-09-22 14:54:23 +08:00
|
|
|
|
2017-01-13 14:03:57 +08:00
|
|
|
namespace vcpkg::Commands::List
|
2016-09-22 14:54:23 +08:00
|
|
|
{
|
2017-06-10 14:45:52 +08:00
|
|
|
static const std::string OPTION_FULLDESC = "--x-full-desc"; // TODO: This should find a better home, eventually
|
2017-05-17 09:10:00 +08:00
|
|
|
|
|
|
|
static void do_print(const StatusParagraph& pgh, bool FullDesc)
|
2016-11-08 06:39:52 +08:00
|
|
|
{
|
2017-05-17 09:10:00 +08:00
|
|
|
if (FullDesc)
|
|
|
|
{
|
2017-08-23 06:59:27 +08:00
|
|
|
System::println("%-30s %-16s %s", pgh.package.displayname(), pgh.package.version, pgh.package.description);
|
2017-05-17 09:10:00 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-23 06:59:27 +08:00
|
|
|
System::println("%-30s %-16s %s",
|
|
|
|
vcpkg::shorten_text(pgh.package.displayname(), 30),
|
|
|
|
vcpkg::shorten_text(pgh.package.version, 16),
|
|
|
|
vcpkg::shorten_text(pgh.package.description, 71));
|
2017-05-17 09:10:00 +08:00
|
|
|
}
|
2016-11-08 06:39:52 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:29:11 +08:00
|
|
|
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
|
2016-09-22 14:54:23 +08:00
|
|
|
{
|
2016-11-08 06:39:52 +08:00
|
|
|
static const std::string example = Strings::format(
|
2017-04-28 09:08:52 +08:00
|
|
|
"The argument should be a substring to search for, or no argument to display all installed libraries.\n%s",
|
|
|
|
Commands::Help::create_example_string("list png"));
|
2016-12-13 07:03:36 +08:00
|
|
|
args.check_max_arg_count(1, example);
|
2017-06-10 14:45:52 +08:00
|
|
|
const std::unordered_set<std::string> options =
|
|
|
|
args.check_and_get_optional_command_arguments({OPTION_FULLDESC});
|
2016-09-22 14:54:23 +08:00
|
|
|
|
2016-11-08 06:39:52 +08:00
|
|
|
const StatusParagraphs status_paragraphs = database_load_check(paths);
|
2017-03-30 07:00:41 +08:00
|
|
|
std::vector<StatusParagraph*> installed_packages = get_installed_ports(status_paragraphs);
|
2016-11-08 06:39:52 +08:00
|
|
|
|
|
|
|
if (installed_packages.empty())
|
|
|
|
{
|
|
|
|
System::println("No packages are installed. Did you mean `search`?");
|
2017-03-23 08:45:39 +08:00
|
|
|
Checks::exit_success(VCPKG_LINE_INFO);
|
2016-09-22 14:54:23 +08:00
|
|
|
}
|
2016-11-08 06:39:52 +08:00
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
std::sort(installed_packages.begin(),
|
|
|
|
installed_packages.end(),
|
|
|
|
[](const StatusParagraph* lhs, const StatusParagraph* rhs) -> bool {
|
2017-03-30 07:00:41 +08:00
|
|
|
return lhs->package.displayname() < rhs->package.displayname();
|
2016-11-08 06:39:52 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
if (args.command_arguments.size() == 0)
|
2016-09-22 14:54:23 +08:00
|
|
|
{
|
2017-03-30 07:00:41 +08:00
|
|
|
for (const StatusParagraph* status_paragraph : installed_packages)
|
2016-11-08 06:39:52 +08:00
|
|
|
{
|
2017-05-17 09:10:00 +08:00
|
|
|
do_print(*status_paragraph, options.find(OPTION_FULLDESC) != options.cend());
|
2016-11-08 06:39:52 +08:00
|
|
|
}
|
2016-09-22 14:54:23 +08:00
|
|
|
}
|
2016-11-08 06:39:52 +08:00
|
|
|
else
|
2016-09-22 14:54:23 +08:00
|
|
|
{
|
2016-11-08 06:39:52 +08:00
|
|
|
// At this point there is 1 argument
|
2017-03-30 07:00:41 +08:00
|
|
|
for (const StatusParagraph* status_paragraph : installed_packages)
|
2016-11-08 06:39:52 +08:00
|
|
|
{
|
2017-03-30 07:00:41 +08:00
|
|
|
const std::string displayname = status_paragraph->package.displayname();
|
2016-11-08 06:39:52 +08:00
|
|
|
if (Strings::case_insensitive_ascii_find(displayname, args.command_arguments[0]) == displayname.end())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-05-17 09:10:00 +08:00
|
|
|
do_print(*status_paragraph, options.find(OPTION_FULLDESC) != options.cend());
|
2016-11-08 06:39:52 +08:00
|
|
|
}
|
2016-09-22 14:54:23 +08:00
|
|
|
}
|
2016-11-08 06:39:52 +08:00
|
|
|
|
2017-03-23 08:45:39 +08:00
|
|
|
Checks::exit_success(VCPKG_LINE_INFO);
|
2016-09-22 14:54:23 +08:00
|
|
|
}
|
|
|
|
}
|