diff --git a/README.md b/README.md
index 2d8654e62..91ae1bb69 100644
--- a/README.md
+++ b/README.md
@@ -127,6 +127,7 @@ local
local:drush-aliases (drush-aliases) Find the project's Drush aliases
local:init (init) Create a local project file structure from a Git repository
project
+ project:delete Delete a project
project:get (get) Clone and build a project locally
project:list (projects) Get a list of all active projects
project:metadata Read or set metadata for a project
diff --git a/src/Application.php b/src/Application.php
index 05197b9e5..4c5cc9c02 100644
--- a/src/Application.php
+++ b/src/Application.php
@@ -131,6 +131,7 @@ protected function getCommands()
$commands[] = new Command\Local\LocalDrushAliasesCommand();
$commands[] = new Command\Local\LocalDirCommand();
$commands[] = new Command\Local\LocalInitCommand();
+ $commands[] = new Command\Project\ProjectDeleteCommand();
$commands[] = new Command\Project\ProjectGetCommand();
$commands[] = new Command\Project\ProjectListCommand();
$commands[] = new Command\Project\ProjectMetadataCommand();
diff --git a/src/Command/PlatformCommand.php b/src/Command/PlatformCommand.php
index 92e217392..106bf5120 100644
--- a/src/Command/PlatformCommand.php
+++ b/src/Command/PlatformCommand.php
@@ -568,6 +568,16 @@ public function clearEnvironmentsCache(Project $project = null)
self::$cache->delete('environments:' . $project->id);
}
+ /**
+ * Clear the projects cache.
+ *
+ * Use this after deleting projects/users.
+ */
+ protected function clearProjectsCache()
+ {
+ self::$cache->delete('projects');
+ }
+
/**
* @param Project $project
* @param Environment[] $environments
diff --git a/src/Command/Project/ProjectDeleteCommand.php b/src/Command/Project/ProjectDeleteCommand.php
new file mode 100644
index 000000000..54a29495f
--- /dev/null
+++ b/src/Command/Project/ProjectDeleteCommand.php
@@ -0,0 +1,63 @@
+setName('project:delete')
+ ->setDescription('Delete a project');
+ $this->addProjectOption();
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $this->validateInput($input);
+ $project = $this->getSelectedProject();
+ $client = $this->getClient();
+
+ $account = $client->getAccountInfo();
+ if ($account['uuid'] != $project->owner) {
+ $this->stdErr->writeln("Only the project's owner can delete it.");
+ return 1;
+ }
+
+ /** @var \Platformsh\Cli\Helper\PlatformQuestionHelper $questionHelper */
+ $questionHelper = $this->getHelper('question');
+ $title = $project->title;
+
+ $confirmQuestion = "You are about to delete the project:"
+ . "\n $title ({$project->id})"
+ . "\n\n * This action is irreversible>."
+ . "\n * Your site will no longer be accessible."
+ . "\n * All data associated with this project will be deleted, including backups."
+ . "\n * You will be charged at the end of the month for any remaining project costs."
+ . "\n\nAre you sure you want to delete this project?";
+ if (!$questionHelper->confirm($confirmQuestion, $input, $output, false)) {
+ return 1;
+ }
+
+ if ($input->isInteractive() && strlen($title)) {
+ $confirmName = $questionHelper->askInput("Type the project title to confirm", $input, $this->stdErr);
+ if ($confirmName !== $title) {
+ $this->stdErr->writeln("Incorrect project title (expected: $title)");
+ return 1;
+ }
+ }
+
+ $subscriptionId = $project->getSubscriptionId();
+ $subscription = $client->getSubscription($subscriptionId);
+
+ $result = $subscription->delete();
+ $this->clearProjectsCache();
+
+ $this->stdErr->writeln("\nThe project $title ({$project->id}) was deleted.");
+ return 0;
+ }
+}