Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #402 from cloudflare/alewis/feat-delete-namespace
Browse files Browse the repository at this point in the history
feat: #341 delete namespace
  • Loading branch information
ashleymichal authored Aug 7, 2019
2 parents d72fe22 + 71822bc commit 1c02235
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/content/kv_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ $ wrangler kv create "new kv namespace"
title: "new kv namespace",
}
```

### `delete <namespace-id>`

#### Usage

``` sh
$ wrangler kv delete f7b02e7fc70443149ac906dd81ec1791
🌀 Deleting namespace f7b02e7fc70443149ac906dd81ec1791 🌀
✨ Success
```
25 changes: 25 additions & 0 deletions src/commands/kv/delete_namespace.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use cloudflare::apiclient::APIClient;

use cloudflare::workerskv::remove_namespace::RemoveNamespace;

use crate::terminal::message;

pub fn delete_namespace(id: &str) -> Result<(), failure::Error> {
let client = super::api_client()?;
let account_id = super::account_id()?;

let msg = format!("Deleting namespace {}", id);
message::working(&msg);

let response = client.request(&RemoveNamespace {
account_identifier: &account_id,
namespace_identifier: id,
});

match response {
Ok(_success) => message::success("Success"),
Err(e) => super::print_error(e),
}

Ok(())
}
2 changes: 2 additions & 0 deletions src/commands/kv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ use crate::settings;
use crate::terminal::message;

mod create_namespace;
mod delete_namespace;

pub use create_namespace::create_namespace;
pub use delete_namespace::delete_namespace;

fn api_client() -> Result<HTTPAPIClient, failure::Error> {
let user = settings::global_user::GlobalUser::new()?;
Expand Down
10 changes: 10 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ fn run() -> Result<(), failure::Error> {
Arg::with_name("title")
)
)
.subcommand(
SubCommand::with_name("delete")
.arg(
Arg::with_name("id")
)
)
)
.subcommand(
SubCommand::with_name("generate")
Expand Down Expand Up @@ -253,6 +259,10 @@ fn run() -> Result<(), failure::Error> {
let title = create_matches.value_of("title").unwrap();
commands::kv::create_namespace(title)?;
}
("delete", Some(delete_matches)) => {
let id = delete_matches.value_of("id").unwrap();
commands::kv::delete_namespace(id)?;
}
("", None) => message::warn("kv expects a subcommand"),
_ => unreachable!(),
}
Expand Down

0 comments on commit 1c02235

Please sign in to comment.