Skip to content

Commit 4eb01d9

Browse files
committed
new command todo
1 parent 82e25bb commit 4eb01d9

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/app.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
use clap::*;
2+
use std::path::Path;
23

34
pub fn build_app() -> App<'static, 'static> {
4-
App::new("haste")
5+
let mut app = App::new("haste")
56
.version(crate_version!())
67
.about(crate_description!())
78
.after_help(
89
"If you invoke the subcommand without an argument or pipe, it will open interactively. \
910
Type text there and press Ctrl-d on unix or Ctrl-z on Windows to exit and paste the content. \
1011
\n\nReport issues at https://github.com/Ay-355/haste-cli"
1112
)
13+
.setting(AppSettings::DisableHelpSubcommand)
1214
.arg(
1315
Arg::with_name("FILE")
1416
.help("The file you want to paste. Use '-' or nothing for standard input.")
@@ -32,4 +34,12 @@ pub fn build_app() -> App<'static, 'static> {
3234
.short("r")
3335
.long("raw")
3436
)
37+
38+
if Path::new("view").exists() {
39+
app
40+
} else {
41+
.subcommand(
42+
SubCommand::with_name("view")
43+
.about("Get the contents of a paste.")
44+
) }
3545
}

src/http.rs

+8
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@ pub fn upload_content(content: String) -> Result<String, ureq::Error> {
1111
.into_json()?;
1212
Ok(json.key)
1313
}
14+
15+
pub fn get_content(id: &str) -> Result<String, ureq::Error> {
16+
let content =
17+
ureq::get(format!("https://www.toptal.com/developers/hastebin/raw/{}", &id).as_str())
18+
.call()?
19+
.into_string()?;
20+
Ok(content)
21+
}

0 commit comments

Comments
 (0)