aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/commands_export.cpp
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2017-04-21 14:21:06 -0700
committerAlexander Karatarakis <alkarata@microsoft.com>2017-04-21 18:06:53 -0700
commit0c47e6e04ac211719da62d302a1dbd147854dd93 (patch)
tree872504bb9a068489c3f508b1cd040241442395fd /toolsrc/src/commands_export.cpp
parent75e3838582eb7b94ecb57793718ec626cefbda81 (diff)
downloadvcpkg-0c47e6e04ac211719da62d302a1dbd147854dd93.tar.gz
vcpkg-0c47e6e04ac211719da62d302a1dbd147854dd93.zip
`export`: Refactoring
Diffstat (limited to 'toolsrc/src/commands_export.cpp')
-rw-r--r--toolsrc/src/commands_export.cpp61
1 files changed, 36 insertions, 25 deletions
diff --git a/toolsrc/src/commands_export.cpp b/toolsrc/src/commands_export.cpp
index fe7be85b5..d86e14ab5 100644
--- a/toolsrc/src/commands_export.cpp
+++ b/toolsrc/src/commands_export.cpp
@@ -76,6 +76,41 @@ namespace vcpkg::Commands::Export
}
}
+ static void do_nuget_export(const VcpkgPaths& paths, const fs::path& exported_dir_path)
+ {
+ Files::Filesystem& fs = paths.get_filesystem();
+
+ const std::string exported_dir_filename = exported_dir_path.filename().string();
+ const std::string nuget_id = "vcpkg-" + exported_dir_filename;
+ const std::string nupkg_version = "1.0.0";
+
+ const std::string nuspec_file_content = create_nuspec_file_contents(exported_dir_filename, nuget_id, nupkg_version);
+
+ const fs::path nuspec_file_path = paths.root / "export.nuspec";
+ fs.write_contents(nuspec_file_path, nuspec_file_content);
+
+ const fs::path& nuget_exe = paths.get_nuget_exe();
+
+ // -NoDefaultExcludes is needed for ".vcpkg-root"
+ const std::wstring cmd_line = Strings::wformat(LR"("%s" pack -OutputDirectory "%s" "%s" -NoDefaultExcludes)", nuget_exe.native(), paths.root.native(), nuspec_file_path.native());
+
+ const int exit_code = System::cmd_execute_clean(cmd_line);
+ Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0, "Error: NuGet package creation failed");
+ }
+
+ static std::string create_exported_dir_filename()
+ {
+ const tm date_time = System::get_current_date_time();
+
+ // Format is: YYYY-mm-dd_HH-MM-SS
+ // 19 characters + 1 null terminating character will be written for a total of 20 chars
+ char mbstr[20];
+ const size_t bytes_written = std::strftime(mbstr, sizeof(mbstr), "%Y-%m-%d_%H-%M-%S", &date_time);
+ Checks::check_exit(VCPKG_LINE_INFO, bytes_written == 19, "Expected 19 bytes to be written, but %u were written", bytes_written);
+ const std::string date_time_as_string(mbstr);
+ return ("exported-" + date_time_as_string);
+ }
+
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet)
{
static const std::string OPTION_DRY_RUN = "--dry-run";
@@ -135,15 +170,7 @@ namespace vcpkg::Commands::Export
Checks::exit_success(VCPKG_LINE_INFO);
}
- const tm date_time = System::get_current_date_time();
-
- // Format is: YYYY-mm-dd_HH-MM-SS
- // 19 characters + 1 null terminating character will be written for a total of 20 chars
- char mbstr[20];
- const size_t bytes_written = std::strftime(mbstr, sizeof(mbstr), "%Y-%m-%d_%H-%M-%S", &date_time);
- Checks::check_exit(VCPKG_LINE_INFO, bytes_written == 19, "Expected 19 bytes to be written, but %u were written", bytes_written);
- const std::string date_time_as_string(mbstr);
- const std::string exported_dir_filename = ("exported-" + date_time_as_string);
+ const std::string exported_dir_filename = create_exported_dir_filename();
Files::Filesystem& fs = paths.get_filesystem();
const fs::path exported_dir_path = paths.root / exported_dir_filename;
@@ -177,22 +204,6 @@ namespace vcpkg::Commands::Export
System::println(System::Color::success, R"(Files exported at: "%s")", exported_dir_path.generic_string());
- const std::string nuget_id = "vcpkg-" + exported_dir_filename;
- const std::string nupkg_version = "1.0.0";
-
- const std::string nuspec_file_content = create_nuspec_file_contents(exported_dir_path.filename().string(), nuget_id, nupkg_version);
-
- const fs::path nuspec_file_path = paths.root / "export.nuspec";
- fs.write_contents(nuspec_file_path, nuspec_file_content);
-
- const fs::path& nuget_exe = paths.get_nuget_exe();
-
- // -NoDefaultExcludes is needed for ".vcpkg-root"
- const std::wstring cmd_line = Strings::wformat(LR"("%s" pack -OutputDirectory "%s" "%s" -NoDefaultExcludes)", nuget_exe.native(), paths.root.native(), nuspec_file_path.native());
-
- const int exit_code = System::cmd_execute_clean(cmd_line);
- Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0, "Error: NuGet package creation failed");
-
Checks::exit_success(VCPKG_LINE_INFO);
}
}