Skip to content
This repository was archived by the owner on Jul 16, 2022. It is now read-only.

Commit b7cfefa

Browse files
committed
'delete' subcommand
1 parent 081d95d commit b7cfefa

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

src/api.rs

+16
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,22 @@ impl Client {
192192
}
193193
}
194194

195+
pub fn delete(&self, login: &Login, id: &str) -> Result<()> {
196+
let res = self
197+
.client
198+
.delete(&format!("https://api.github.com/gists/{}", id))
199+
.auth(&login)
200+
.send()?;
201+
if res.status().is_success() {
202+
Ok(())
203+
} else {
204+
Err(Error::new(ErrorKind::ApiWithStatus {
205+
status: res.status(),
206+
message: res.text()?,
207+
}))
208+
}
209+
}
210+
195211
pub fn request_verification_code(
196212
&self,
197213
client_id: &str,

src/app.rs

+10
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ fn list_gists(gists: &[api::GistResponse]) {
4242
}
4343
}
4444

45+
pub fn delete(login: &config::Login, id: &[String]) -> Result<()> {
46+
let client = api::Client::build()?;
47+
for i in id.into_iter() {
48+
client.delete(login, &i)?;
49+
println!("{}", i);
50+
}
51+
println!("Success!");
52+
Ok(())
53+
}
54+
4555
pub fn login(client_id: &str) -> Result<()> {
4656
let client = api::Client::build()?;
4757

src/bin/gist.rs

+13
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ enum Subcommand {
3737
Upload(Upload),
3838
/// Browse the gists
3939
List(List),
40+
/// Delete the gists
41+
Delete(Delete),
4042
}
4143

4244
#[derive(Debug, StructOpt)]
@@ -72,6 +74,13 @@ struct List {
7274
username: Option<String>,
7375
}
7476

77+
#[derive(Debug, StructOpt)]
78+
struct Delete {
79+
/// The ID of gist to delete
80+
#[structopt(required = true)]
81+
id: Vec<String>,
82+
}
83+
7584
fn main() -> Result<()> {
7685
let args = Args::from_args();
7786

@@ -89,6 +98,10 @@ fn main() -> Result<()> {
8998
gist::app::list(l.ok().as_ref(), opt.username.as_deref())
9099
}
91100
}
101+
Subcommand::Delete(opt) => {
102+
let l = select_account(args.account)?;
103+
gist::app::delete(&l, &opt.id)
104+
}
92105
}
93106
}
94107

0 commit comments

Comments
 (0)