Skip to content

Commit f14ca92

Browse files
committed
[lib] Clean up main run function
1 parent e0ab755 commit f14ca92

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,13 @@ fn print_completion<G: Generator>(gen: G, cmd: &mut Command) {
4949
generate(gen, cmd, cmd.get_name().to_string(), &mut io::stdout())
5050
}
5151

52-
/// Reads from stdin and uploads to a pastebin backend
53-
pub fn pastry() -> Result<String> {
52+
pub fn run() -> Result<()> {
5453
let args = Args::parse();
5554

5655
match &args.command {
5756
Some(Commands::Completion { shell }) => {
5857
print_completion(*shell, &mut Args::command());
59-
return Ok("".to_string());
58+
return Ok(());
6059
}
6160
None => {}
6261
}
@@ -75,5 +74,11 @@ pub fn pastry() -> Result<String> {
7574
}),
7675
};
7776
let url = endpoint_api.upload(result);
78-
url
77+
match url {
78+
Ok(url) => {
79+
print!("{}", url);
80+
Ok(())
81+
}
82+
Err(err) => Err(err),
83+
}
7984
}

src/main.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
use pastry as lib;
1+
use std::process::ExitCode;
22

3-
use anyhow::Result;
3+
use pastry;
44

5-
fn main() -> Result<()> {
6-
print!("{}", lib::pastry()?);
7-
Ok(())
5+
fn main() -> ExitCode {
6+
let result = pastry::run();
7+
match result {
8+
Ok(_) => ExitCode::SUCCESS,
9+
Err(err) => {
10+
eprintln!("{}", err);
11+
ExitCode::FAILURE
12+
}
13+
}
814
}

0 commit comments

Comments
 (0)