aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/commands_create.cpp
diff options
context:
space:
mode:
authorJan HrubĂ˝ <jhruby.web@gmail.com>2017-03-13 08:56:05 +0100
committerGitHub <noreply@github.com>2017-03-13 08:56:05 +0100
commit665f4118f603c5858217ed7a2f2f824b18ff4fc5 (patch)
treef0167041edf71e90f2331b5025f603392a8de67a /toolsrc/src/commands_create.cpp
parent1bec0fcb73073b5b1719f454c368a63f1bff625e (diff)
parent1c9873a0daf625f67474aaf3e163c592c27ecb65 (diff)
downloadvcpkg-665f4118f603c5858217ed7a2f2f824b18ff4fc5.tar.gz
vcpkg-665f4118f603c5858217ed7a2f2f824b18ff4fc5.zip
Merge pull request #1 from Microsoft/master
pull
Diffstat (limited to 'toolsrc/src/commands_create.cpp')
-rw-r--r--toolsrc/src/commands_create.cpp63
1 files changed, 27 insertions, 36 deletions
diff --git a/toolsrc/src/commands_create.cpp b/toolsrc/src/commands_create.cpp
index 76ba644e4..b74693ed5 100644
--- a/toolsrc/src/commands_create.cpp
+++ b/toolsrc/src/commands_create.cpp
@@ -1,50 +1,41 @@
+#include "pch.h"
#include "vcpkg_Commands.h"
#include "vcpkg_System.h"
#include "vcpkg_Environment.h"
#include "vcpkg_Files.h"
+#include "vcpkg_Input.h"
+#include "vcpkglib.h"
-namespace vcpkg
+namespace vcpkg::Commands::Create
{
- void create_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet)
+ void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
{
- args.check_max_args(3);
- if (args.command_arguments.size() < 2)
- {
- System::println(System::color::error, "Error: create requires the archive's URL as the second argument.");
- print_usage();
- exit(EXIT_FAILURE);
- }
-
- expected<package_spec> current_spec = package_spec::from_string(args.command_arguments[0], default_target_triplet);
- if (const package_spec* spec = current_spec.get())
- {
- Environment::ensure_utilities_on_path(paths);
+ static const std::string example = Commands::Help::create_example_string(R"###(create zlib2 http://zlib.net/zlib1211.zip "zlib1211-2.zip")###");
+ args.check_max_arg_count(3, example);
+ args.check_min_arg_count(2, example);
+ args.check_and_get_optional_command_arguments({});
+ const std::string port_name = args.command_arguments.at(0);
+ const std::string url = args.command_arguments.at(1);
- // Space OR define the FILENAME with proper spacing
- std::wstring custom_filename = L" ";
- if (args.command_arguments.size() >= 3)
- {
- const std::string& zip_file_name = args.command_arguments.at(2);
- Checks::check_exit(!Files::has_invalid_chars_for_filesystem(zip_file_name),
- R"(Filename cannot contain invalid chars %s, but was %s)",
- Files::FILESYSTEM_INVALID_CHARACTERS, zip_file_name);
- custom_filename = Strings::format(LR"( -DFILENAME="%s" )", Strings::utf8_to_utf16(zip_file_name));
- }
+ const fs::path& cmake_exe = paths.get_cmake_exe();
- const std::wstring cmdline = Strings::format(LR"(cmake -DCMD=SCAFFOLD -DPORT=%s -DTARGET_TRIPLET=%s -DURL=%s%s-P "%s")",
- Strings::utf8_to_utf16(spec->name),
- Strings::utf8_to_utf16(spec->target_triplet.value),
- Strings::utf8_to_utf16(args.command_arguments.at(1)),
- custom_filename,
- paths.ports_cmake.generic_wstring());
+ std::vector<CMakeVariable> cmake_args
+ {
+ { L"CMD", L"CREATE" },
+ { L"PORT", port_name },
+ { L"URL", url }
+ };
- exit(System::cmd_execute(cmdline));
- }
- else
+ if (args.command_arguments.size() >= 3)
{
- System::println(System::color::error, "Error: %s: %s", current_spec.error_code().message(), args.command_arguments[0]);
- print_example(Strings::format("%s zlib:x64-windows", args.command).c_str());
- exit(EXIT_FAILURE);
+ const std::string& zip_file_name = args.command_arguments.at(2);
+ Checks::check_exit(!Files::has_invalid_chars_for_filesystem(zip_file_name),
+ R"(Filename cannot contain invalid chars %s, but was %s)",
+ Files::FILESYSTEM_INVALID_CHARACTERS, zip_file_name);
+ cmake_args.push_back({ L"FILENAME", zip_file_name });
}
+
+ const std::wstring cmd_launch_cmake = make_cmake_cmd(cmake_exe, paths.ports_cmake, cmake_args);
+ exit(System::cmd_execute_clean(cmd_launch_cmake));
}
}