diff options
| author | Jan HrubĂ˝ <jhruby.web@gmail.com> | 2017-03-13 08:56:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-03-13 08:56:05 +0100 |
| commit | 665f4118f603c5858217ed7a2f2f824b18ff4fc5 (patch) | |
| tree | f0167041edf71e90f2331b5025f603392a8de67a /toolsrc/src/commands_search.cpp | |
| parent | 1bec0fcb73073b5b1719f454c368a63f1bff625e (diff) | |
| parent | 1c9873a0daf625f67474aaf3e163c592c27ecb65 (diff) | |
| download | vcpkg-665f4118f603c5858217ed7a2f2f824b18ff4fc5.tar.gz vcpkg-665f4118f603c5858217ed7a2f2f824b18ff4fc5.zip | |
Merge pull request #1 from Microsoft/master
pull
Diffstat (limited to 'toolsrc/src/commands_search.cpp')
| -rw-r--r-- | toolsrc/src/commands_search.cpp | 108 |
1 files changed, 71 insertions, 37 deletions
diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp index ce02e9c3b..8bac858f1 100644 --- a/toolsrc/src/commands_search.cpp +++ b/toolsrc/src/commands_search.cpp @@ -1,58 +1,92 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "vcpkg_System.h" -#include "vcpkg.h" -#include <iostream> -#include <iomanip> +#include "Paragraphs.h" +#include "vcpkglib_helpers.h" +#include "SourceParagraph.h" -namespace fs = std::tr2::sys; - -namespace vcpkg +namespace vcpkg::Commands::Search { - template <class Pred> - static void do_print(const vcpkg_paths& paths, Pred predicate) + static const std::string OPTION_GRAPH = "--graph"; //TODO: This should find a better home, eventually + + static std::string replace_dashes_with_underscore(const std::string& input) { - for (auto it = fs::directory_iterator(paths.ports); it != fs::directory_iterator(); ++it) - { - const fs::path& path = it->path(); + std::string output = input; + std::replace(output.begin(), output.end(), '-', '_'); + return output; + } - try - { - auto pghs = get_paragraphs(path / "CONTROL"); - if (pghs.empty()) - continue; - auto srcpgh = SourceParagraph(pghs[0]); + static std::string create_graph_as_string(const std::vector<SourceParagraph>& source_paragraphs) + { + int empty_node_count = 0; - if (predicate(srcpgh.name)) - { - std::cout << std::left - << std::setw(20) << srcpgh.name << ' ' - << std::setw(16) << srcpgh.version << ' ' - << shorten_description(srcpgh.description) << '\n'; - } + std::string s; + s.append("digraph G{ rankdir=LR; edge [minlen=3]; overlap=false;"); + + for (const SourceParagraph& source_paragraph : source_paragraphs) + { + if (source_paragraph.depends.empty()) + { + empty_node_count++; + continue; } - catch (std::runtime_error const&) + + const std::string name = replace_dashes_with_underscore(source_paragraph.name); + s.append(Strings::format("%s;", name)); + for (const dependency& d : source_paragraph.depends) { + const std::string dependency_name = replace_dashes_with_underscore(d.name); + s.append(Strings::format("%s -> %s;", name, dependency_name)); } } + + s.append(Strings::format("empty [label=\"%d singletons...\"]; }", empty_node_count)); + return s; + } + + static void do_print(const SourceParagraph& source_paragraph) + { + System::println("%-20s %-16s %s", + source_paragraph.name, + source_paragraph.version, + details::shorten_description(source_paragraph.description)); } - void search_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { - args.check_max_args(1); - if (args.command_arguments.size() == 0) + static const std::string example = Strings::format("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::vector<SourceParagraph> source_paragraphs = Paragraphs::load_all_ports(paths.ports); + if (options.find(OPTION_GRAPH) != options.cend()) { - do_print(paths, [](std::string&) -> bool - { - return true; - }); + const std::string graph_as_string = create_graph_as_string(source_paragraphs); + System::println(graph_as_string); exit(EXIT_SUCCESS); } - // At this point there is 1 argument - do_print(paths, [&](std::string& port_name) -> bool - { - return Strings::case_insensitive_find(port_name, args.command_arguments[0]) != port_name.end(); - }); + if (args.command_arguments.empty()) + { + for (const SourceParagraph& source_paragraph : source_paragraphs) + { + do_print(source_paragraph); + } + } + else + { + // At this point there is 1 argument + for (const SourceParagraph& source_paragraph : source_paragraphs) + { + if (Strings::case_insensitive_ascii_find(source_paragraph.name, args.command_arguments[0]) == source_paragraph.name.end()) + { + continue; + } + + do_print(source_paragraph); + } + } System::println("\nIf your library is not listed, please open an issue at:\n" " https://github.com/Microsoft/vcpkg/issues"); |
