2017-01-27 12:49:09 -08:00
|
|
|
#include "pch.h"
|
2016-09-22 00:00:38 -07:00
|
|
|
#include "vcpkg_Commands.h"
|
|
|
|
#include "vcpkg_System.h"
|
2016-09-30 16:49:30 -07:00
|
|
|
#include "vcpkg_Input.h"
|
2016-09-22 00:00:38 -07:00
|
|
|
|
2017-01-12 22:03:57 -08:00
|
|
|
namespace vcpkg::Commands::Edit
|
2016-09-22 00:00:38 -07:00
|
|
|
{
|
2017-01-12 22:03:57 -08:00
|
|
|
void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
|
2016-09-22 00:00:38 -07:00
|
|
|
{
|
2017-01-12 22:03:57 -08:00
|
|
|
static const std::string example = Commands::Help::create_example_string("edit zlib");
|
2016-12-12 15:03:36 -08:00
|
|
|
args.check_exact_arg_count(1, example);
|
2016-09-30 18:21:38 -07:00
|
|
|
const std::string port_name = args.command_arguments.at(0);
|
2016-09-22 00:00:38 -07:00
|
|
|
|
2016-09-30 18:21:38 -07:00
|
|
|
const fs::path portpath = paths.ports / port_name;
|
2017-01-25 16:44:56 -08:00
|
|
|
Checks::check_exit(fs::is_directory(portpath), R"(Could not find port named "%s")", port_name);
|
2016-09-30 17:36:33 -07:00
|
|
|
|
2016-09-22 00:00:38 -07:00
|
|
|
// Find editor
|
2017-02-14 15:35:34 -08:00
|
|
|
const optional<std::wstring> env_EDITOR_optional = System::get_environmental_variable(L"EDITOR");
|
|
|
|
std::wstring env_EDITOR;
|
|
|
|
|
|
|
|
if (env_EDITOR_optional)
|
|
|
|
{
|
|
|
|
env_EDITOR = *env_EDITOR_optional;
|
|
|
|
}
|
|
|
|
else
|
2016-09-30 17:36:33 -07:00
|
|
|
{
|
|
|
|
static const std::wstring CODE_EXE_PATH = LR"(C:\Program Files (x86)\Microsoft VS Code\Code.exe)";
|
|
|
|
if (fs::exists(CODE_EXE_PATH))
|
|
|
|
{
|
|
|
|
env_EDITOR = CODE_EXE_PATH;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Checks::exit_with_message("Visual Studio Code was not found and the environmental variable EDITOR is not set");
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 00:00:38 -07:00
|
|
|
|
2017-01-12 17:03:21 -08:00
|
|
|
std::wstring cmdLine = Strings::wformat(LR"("%s" "%s" "%s" -n)", env_EDITOR, portpath.native(), (portpath / "portfile.cmake").native());
|
2016-09-22 00:00:38 -07:00
|
|
|
exit(System::cmd_execute(cmdLine));
|
|
|
|
}
|
|
|
|
}
|