Minor refactoring
This commit is contained in:
parent
2d2aaef9f8
commit
9666ac727b
54
src/main.rs
54
src/main.rs
@ -119,46 +119,28 @@ async fn main() -> ResBE<()> {
|
||||
.get_matches();
|
||||
|
||||
|
||||
let outdir = match arguments.value_of("outdir") {
|
||||
Some(it) => it,
|
||||
None => "./"
|
||||
};
|
||||
let outdir = arguments.value_of("outdir").unwrap_or("./").to_string();
|
||||
|
||||
let into_file = match arguments.value_of("into_file") {
|
||||
Some(it) => Some(it.to_string()),
|
||||
None => None
|
||||
};
|
||||
let into_file = arguments.value_of("into_file").map(String::from);
|
||||
|
||||
let file_count = match arguments.value_of("file_count") {
|
||||
Some(it) => it,
|
||||
None => "1"
|
||||
};
|
||||
let file_count = arguments.value_of("file_count").unwrap_or("1");
|
||||
|
||||
let file_count: u32 = match file_count.parse() {
|
||||
Ok(it) => it,
|
||||
Err(_) => {
|
||||
let file_count: u32 = file_count.parse().unwrap_or_else(|_| {
|
||||
eprintln!("Invalid value for num-files: {}", file_count);
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
if file_count <= 0 {
|
||||
eprintln!("Invalid value for num-files: {}", file_count);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
let conn_count = match arguments.value_of("conn_count") {
|
||||
Some(it) => it,
|
||||
None => "1"
|
||||
};
|
||||
let conn_count = arguments.value_of("conn_count").unwrap_or("1");
|
||||
|
||||
let conn_count: u32 = match conn_count.parse() {
|
||||
Ok(it) => it,
|
||||
Err(_) => {
|
||||
let conn_count: u32 = conn_count.parse().unwrap_or_else(|_| {
|
||||
eprintln!("Invalid value for connections: {}", conn_count);
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
if conn_count <= 0 {
|
||||
eprintln!("Invalid value for connections: {}", conn_count);
|
||||
@ -188,7 +170,7 @@ async fn main() -> ResBE<()> {
|
||||
|
||||
|
||||
let mut cli_args = CLIArguments {
|
||||
outdir: outdir.to_string(),
|
||||
outdir: outdir,
|
||||
into_file: into_file,
|
||||
file_count: file_count,
|
||||
conn_count: conn_count,
|
||||
@ -225,15 +207,12 @@ async fn main() -> ResBE<()> {
|
||||
}
|
||||
|
||||
CLIAction::ResolveZippyUrl(url) => {
|
||||
match zippy::resolve_link(url).await {
|
||||
Ok(resolved_url) => {
|
||||
println!("{}", resolved_url);
|
||||
},
|
||||
Err(_e) => {
|
||||
let resolved_url = zippy::resolve_link(url).await.unwrap_or_else(|_| {
|
||||
println!("Zippyshare link could not be resolved");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
println!("{}", resolved_url);
|
||||
},
|
||||
|
||||
CLIAction::None => {
|
||||
@ -302,7 +281,6 @@ async fn download_multiple(cli_args: CLIArguments) -> ResBE<()> {
|
||||
rep.send(
|
||||
DlStatus::Message(format!("Zippyshare link could not be resolved: {}", url))
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -310,11 +288,7 @@ async fn download_multiple(cli_args: CLIArguments) -> ResBE<()> {
|
||||
url.to_string()
|
||||
};
|
||||
|
||||
let file_name = if let Some(arg_filename) = &arg_filename {
|
||||
arg_filename.to_string()
|
||||
} else {
|
||||
download::url_to_filename(&url)
|
||||
};
|
||||
let file_name = arg_filename.clone().unwrap_or_else(|| download::url_to_filename(&url));
|
||||
|
||||
|
||||
let into_file = outdir.join(Path::new(&file_name))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user