mirror of
https://github.com/cemu-project/vcpkg.git
synced 2025-02-23 02:57:09 +01:00
[vcpkg edit] Now accepts multiple ports as arg
This commit is contained in:
parent
a4b35f14ba
commit
8fcb1073ab
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user