aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/commands_remove.cpp
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2016-09-18 20:50:08 -0700
committerAlexander Karatarakis <alkarata@microsoft.com>2016-09-18 20:54:03 -0700
commitccca198c1b1730b0241911cb56dc8e3504958b2a (patch)
treea2dd9b8b087a09afdcecc5cbb3377bed15127eb2 /toolsrc/src/commands_remove.cpp
downloadvcpkg-ccca198c1b1730b0241911cb56dc8e3504958b2a.tar.gz
vcpkg-ccca198c1b1730b0241911cb56dc8e3504958b2a.zip
Initial commit
Diffstat (limited to 'toolsrc/src/commands_remove.cpp')
-rw-r--r--toolsrc/src/commands_remove.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp
new file mode 100644
index 000000000..f5315ccb1
--- /dev/null
+++ b/toolsrc/src/commands_remove.cpp
@@ -0,0 +1,43 @@
+#include "vcpkg_Commands.h"
+#include "vcpkg.h"
+#include "vcpkg_System.h"
+
+namespace vcpkg
+{
+ static const std::string OPTION_PURGE = "--purge";
+
+ static void delete_directory(const fs::path& directory)
+ {
+ std::error_code ec;
+ fs::remove_all(directory, ec);
+ if (!ec)
+ {
+ System::println(System::color::success, "Cleaned up %s", directory.string());
+ }
+ if (fs::exists(directory))
+ {
+ System::println(System::color::warning, "Some files in %s were unable to be removed. Close any editors operating in this directory and retry.", directory.string());
+ }
+ }
+
+ void remove_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet)
+ {
+ const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments({OPTION_PURGE});
+ auto status_db = database_load_check(paths);
+
+ std::vector<package_spec> specs = args.parse_all_arguments_as_package_specs(default_target_triplet);
+ bool alsoRemoveFolderFromPackages = options.find(OPTION_PURGE) != options.end();
+
+ for (const package_spec& spec : specs)
+ {
+ deinstall_package(paths, spec, status_db);
+
+ if (alsoRemoveFolderFromPackages)
+ {
+ const fs::path spec_package_dir = paths.packages / spec.dir();
+ delete_directory(spec_package_dir);
+ }
+ }
+ exit(EXIT_SUCCESS);
+ }
+}