This repository was archived by the owner on Jul 16, 2022. It is now read-only.
File tree 3 files changed +39
-0
lines changed
3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -192,6 +192,22 @@ impl Client {
192
192
}
193
193
}
194
194
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
+
195
211
pub fn request_verification_code (
196
212
& self ,
197
213
client_id : & str ,
Original file line number Diff line number Diff line change @@ -42,6 +42,16 @@ fn list_gists(gists: &[api::GistResponse]) {
42
42
}
43
43
}
44
44
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
+
45
55
pub fn login ( client_id : & str ) -> Result < ( ) > {
46
56
let client = api:: Client :: build ( ) ?;
47
57
Original file line number Diff line number Diff line change @@ -37,6 +37,8 @@ enum Subcommand {
37
37
Upload ( Upload ) ,
38
38
/// Browse the gists
39
39
List ( List ) ,
40
+ /// Delete the gists
41
+ Delete ( Delete ) ,
40
42
}
41
43
42
44
#[ derive( Debug , StructOpt ) ]
@@ -72,6 +74,13 @@ struct List {
72
74
username : Option < String > ,
73
75
}
74
76
77
+ #[ derive( Debug , StructOpt ) ]
78
+ struct Delete {
79
+ /// The ID of gist to delete
80
+ #[ structopt( required = true ) ]
81
+ id : Vec < String > ,
82
+ }
83
+
75
84
fn main ( ) -> Result < ( ) > {
76
85
let args = Args :: from_args ( ) ;
77
86
@@ -89,6 +98,10 @@ fn main() -> Result<()> {
89
98
gist:: app:: list ( l. ok ( ) . as_ref ( ) , opt. username . as_deref ( ) )
90
99
}
91
100
}
101
+ Subcommand :: Delete ( opt) => {
102
+ let l = select_account ( args. account ) ?;
103
+ gist:: app:: delete ( & l, & opt. id )
104
+ }
92
105
}
93
106
}
94
107
You can’t perform that action at this time.
0 commit comments