Skip to content

Commit 82e25bb

Browse files
committed
add raw flag and fix hastebin link
1 parent 8bc7f69 commit 82e25bb

File tree

4 files changed

+35
-19
lines changed

4 files changed

+35
-19
lines changed

Cargo.lock

+14-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub fn build_app() -> App<'static, 'static> {
66
.about(crate_description!())
77
.after_help(
88
"If you invoke the subcommand without an argument or pipe, it will open interactively. \
9-
Type text there and press Ctrl-d on *nix or Ctrl-z on Windows to exit and paste the content. \
9+
Type text there and press Ctrl-d on unix or Ctrl-z on Windows to exit and paste the content. \
1010
\n\nReport issues at https://github.com/Ay-355/haste-cli"
1111
)
1212
.arg(
@@ -24,4 +24,12 @@ pub fn build_app() -> App<'static, 'static> {
2424
.short("l")
2525
.long("language")
2626
)
27+
.arg(
28+
Arg::with_name("raw")
29+
.help("Get the raw content link instead")
30+
.takes_value(false)
31+
.multiple(false)
32+
.short("r")
33+
.long("raw")
34+
)
2735
}

src/http.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use serde::Deserialize;
22

33
#[derive(Debug, Deserialize)]
44
struct HasteResponse {
5-
key: String
5+
key: String,
66
}
77

88
pub fn upload_content(content: String) -> Result<String, ureq::Error> {
9-
let json: HasteResponse = ureq::post("https://hastebin.com/documents")
10-
.send_string(&content.as_str())?
9+
let json: HasteResponse = ureq::post("https://www.toptal.com/developers/hastebin/documents")
10+
.send_string(content.as_str())?
1111
.into_json()?;
1212
Ok(json.key)
1313
}

src/main.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
3232
let matches = app::build_app().get_matches();
3333
let content = get_input(&matches)?;
3434
let key = http::upload_content(content)?;
35-
let url = format!("https://hastebin.com/{}", key);
35+
let url = format!(
36+
"https://toptal.com/developers/hastebin{}{}/",
37+
if matches.is_present("raw") {
38+
"/raw/"
39+
} else {
40+
"/"
41+
},
42+
key
43+
);
3644
println!("Success! {}", url);
3745
Ok(())
3846
}

0 commit comments

Comments
 (0)