aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2018-04-18 18:52:22 -0700
committerAlexander Karatarakis <alkarata@microsoft.com>2018-04-18 18:52:50 -0700
commit8fcb1073abe8611fa24b43f7c1cda0d7404e108e (patch)
tree2660073768ff0f95b552759f64facb9a2d08ea01
parenta4b35f14baac9ccaadca7c6daf6dea39cb9817a2 (diff)
downloadvcpkg-8fcb1073abe8611fa24b43f7c1cda0d7404e108e.tar.gz
vcpkg-8fcb1073abe8611fa24b43f7c1cda0d7404e108e.zip
[vcpkg edit] Now accepts multiple ports as arg
-rw-r--r--toolsrc/src/vcpkg/commands.edit.cpp70
1 files changed, 43 insertions, 27 deletions
diff --git a/toolsrc/src/vcpkg/commands.edit.cpp b/toolsrc/src/vcpkg/commands.edit.cpp
index 82569dd07..b6324565c 100644
--- a/toolsrc/src/vcpkg/commands.edit.cpp
+++ b/toolsrc/src/vcpkg/commands.edit.cpp
@@ -1,5 +1,6 @@
#include "pch.h"
+#include <vcpkg/base/strings.h>
#include <vcpkg/base/system.h>
#include <vcpkg/commands.h>
#include <vcpkg/help.h>
@@ -52,11 +53,42 @@ namespace vcpkg::Commands::Edit
const CommandStructure COMMAND_STRUCTURE = {
Help::create_example_string("edit zlib"),
1,
- 1,
+ 10,
{EDIT_SWITCHES, {}},
&valid_arguments,
};
+ static std::vector<std::string> create_editor_arguments(const VcpkgPaths& paths,
+ const ParsedArguments& options,
+ const std::vector<std::string>& ports)
+ {
+ if (Util::Sets::contains(options.switches, OPTION_ALL))
+ {
+ return Util::fmap(ports, [&](const std::string& port_name) -> std::string {
+ const auto portpath = paths.ports / port_name;
+ const auto portfile = portpath / "portfile.cmake";
+ const auto buildtrees_current_dir = paths.buildtrees / port_name;
+ return Strings::format(R"###("%s" "%s" "%s")###",
+ portpath.u8string(),
+ portfile.u8string(),
+ buildtrees_current_dir.u8string());
+ });
+ }
+
+ if (Util::Sets::contains(options.switches, OPTION_BUILDTREES))
+ {
+ return Util::fmap(ports, [&](const std::string& port_name) -> std::string {
+ return (paths.buildtrees / port_name).u8string();
+ });
+ }
+
+ return Util::fmap(ports, [&](const std::string& port_name) -> std::string {
+ const auto portpath = paths.ports / port_name;
+ const auto portfile = portpath / "portfile.cmake";
+ return Strings::format(R"###("%s" "%s")###", portpath.u8string(), portfile.u8string());
+ });
+ }
+
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
{
static const fs::path VS_CODE_INSIDERS = fs::path{"Microsoft VS Code Insiders"} / "Code - Insiders.exe";
@@ -65,10 +97,14 @@ namespace vcpkg::Commands::Edit
auto& fs = paths.get_filesystem();
const ParsedArguments options = args.parse_arguments(COMMAND_STRUCTURE);
- const std::string port_name = args.command_arguments.at(0);
- const fs::path portpath = paths.ports / port_name;
- Checks::check_exit(VCPKG_LINE_INFO, fs.is_directory(portpath), R"(Could not find port named "%s")", port_name);
+ const std::vector<std::string>& ports = args.command_arguments;
+ for (auto&& port_name : ports)
+ {
+ const fs::path portpath = paths.ports / port_name;
+ Checks::check_exit(
+ VCPKG_LINE_INFO, fs.is_directory(portpath), R"(Could not find port named "%s")", port_name);
+ }
std::vector<fs::path> candidate_paths;
auto maybe_editor_path = System::get_environment_variable("EDITOR");
@@ -107,29 +143,9 @@ namespace vcpkg::Commands::Edit
}
const fs::path env_editor = *it;
- if (Util::Sets::contains(options.switches, OPTION_BUILDTREES))
- {
- const auto buildtrees_current_dir = paths.buildtrees / port_name;
-
- const auto cmd_line =
- Strings::format(R"("%s" "%s" -n)", env_editor.u8string(), buildtrees_current_dir.u8string());
- Checks::exit_with_code(VCPKG_LINE_INFO, System::cmd_execute(cmd_line));
- }
-
- if (Util::Sets::contains(options.switches, OPTION_ALL))
- {
- const auto buildtrees_current_dir = paths.buildtrees / port_name;
-
- const auto cmd_line = Strings::format(
- R"("%s" "%s" "%s" -n)", env_editor.u8string(), portpath.u8string(), buildtrees_current_dir.u8string());
- Checks::exit_with_code(VCPKG_LINE_INFO, System::cmd_execute(cmd_line));
- }
-
- const auto cmd_line = Strings::format(
- R"("%s" "%s" "%s" -n)",
- env_editor.u8string(),
- portpath.u8string(),
- (portpath / "portfile.cmake").u8string());
+ const std::vector<std::string> arguments = create_editor_arguments(paths, options, ports);
+ const auto args_as_string = Strings::join(" ", arguments);
+ const auto cmd_line = Strings::format(R"("%s" %s -n)", env_editor.u8string(), args_as_string);
Checks::exit_with_code(VCPKG_LINE_INFO, System::cmd_execute(cmd_line));
}
}