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