Merge pull request #1106 from evil-e/master

Added option to search and list commands
This commit is contained in:
Robert Schumacher 2017-06-09 23:46:20 -07:00 committed by GitHub
commit 2e01b926d8
2 changed files with 37 additions and 17 deletions

View File

@ -7,12 +7,21 @@
namespace vcpkg::Commands::List
{
static void do_print(const StatusParagraph& pgh)
static const std::string OPTION_FULLDESC = "--x-full-desc"; // TODO: This should find a better home, eventually
static void do_print(const StatusParagraph& pgh, bool FullDesc)
{
System::println("%-27s %-16s %s",
pgh.package.displayname(),
pgh.package.version,
details::shorten_description(pgh.package.description));
if (FullDesc)
{
System::println("%-27s %-16s %s", pgh.package.displayname(), pgh.package.version, pgh.package.description);
}
else
{
System::println("%-27s %-16s %s",
pgh.package.displayname(),
pgh.package.version,
details::shorten_description(pgh.package.description));
}
}
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
@ -21,7 +30,8 @@ namespace vcpkg::Commands::List
"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"));
args.check_max_arg_count(1, example);
args.check_and_get_optional_command_arguments({});
const std::unordered_set<std::string> options =
args.check_and_get_optional_command_arguments({OPTION_FULLDESC});
const StatusParagraphs status_paragraphs = database_load_check(paths);
std::vector<StatusParagraph*> installed_packages = get_installed_ports(status_paragraphs);
@ -42,7 +52,7 @@ namespace vcpkg::Commands::List
{
for (const StatusParagraph* status_paragraph : installed_packages)
{
do_print(*status_paragraph);
do_print(*status_paragraph, options.find(OPTION_FULLDESC) != options.cend());
}
}
else
@ -56,7 +66,7 @@ namespace vcpkg::Commands::List
continue;
}
do_print(*status_paragraph);
do_print(*status_paragraph, options.find(OPTION_FULLDESC) != options.cend());
}
}

View File

@ -9,7 +9,8 @@
namespace vcpkg::Commands::Search
{
static const std::string OPTION_GRAPH = "--graph"; // TODO: This should find a better home, eventually
static const std::string OPTION_GRAPH = "--graph"; // TODO: This should find a better home, eventually
static const std::string OPTION_FULLDESC = "--x-full-desc"; // TODO: This should find a better home, eventually
static std::string replace_dashes_with_underscore(const std::string& input)
{
@ -46,12 +47,20 @@ namespace vcpkg::Commands::Search
return s;
}
static void do_print(const SourceParagraph& source_paragraph)
static void do_print(const SourceParagraph& source_paragraph, bool FullDesc)
{
System::println("%-20s %-16s %s",
source_paragraph.name,
source_paragraph.version,
details::shorten_description(source_paragraph.description));
if (FullDesc)
{
System::println(
"%-20s %-16s %s", source_paragraph.name, source_paragraph.version, source_paragraph.description);
}
else
{
System::println("%-20s %-16s %s",
source_paragraph.name,
source_paragraph.version,
details::shorten_description(source_paragraph.description));
}
}
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
@ -60,7 +69,8 @@ namespace vcpkg::Commands::Search
"The argument should be a substring to search for, or no argument to display all libraries.\n%s",
Commands::Help::create_example_string("search png"));
args.check_max_arg_count(1, example);
const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments({OPTION_GRAPH});
const std::unordered_set<std::string> options =
args.check_and_get_optional_command_arguments({OPTION_GRAPH, OPTION_FULLDESC});
auto sources_and_errors = Paragraphs::try_load_all_ports(paths.get_filesystem(), paths.ports);
@ -95,7 +105,7 @@ namespace vcpkg::Commands::Search
{
for (const SourceParagraph& source_paragraph : source_paragraphs)
{
do_print(source_paragraph);
do_print(source_paragraph, options.find(OPTION_FULLDESC) != options.cend());
}
}
else
@ -113,7 +123,7 @@ namespace vcpkg::Commands::Search
}
}
do_print(source_paragraph);
do_print(source_paragraph, options.find(OPTION_FULLDESC) != options.cend());
}
}