updated main()

This commit is contained in:
Emma Tebibyte 2023-04-19 01:03:28 -04:00
parent 570adfc17d
commit 49691bd68c
Signed by: emma
GPG Key ID: 6D661C738815E7DD
3 changed files with 27 additions and 20 deletions

15
Cargo.lock generated
View File

@ -370,15 +370,6 @@ version = "0.2.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
[[package]]
name = "libc-print"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06cea5d58bd9ba4717bbf5c6c5bb11bb6e9e76685b7fff34039b80f50ce86c11"
dependencies = [
"libc",
]
[[package]]
name = "libloading"
version = "0.7.4"
@ -1009,12 +1000,12 @@ dependencies = [
[[package]]
name = "yacexits"
version = "0.2.0"
source = "git+https://git.tebibyte.media/yac/yacexits.git?branch=c-entry#d2af983f4ad18dec2af0604d7f34b7863daa5c25"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53fe740dd05c1bbc919431e842e6c1bea30195e0518ae99cae35b7f0730ddc18"
dependencies = [
"bindgen",
"libc",
"libc-print",
]
[[package]]

View File

@ -22,4 +22,4 @@ serde_json = "1"
tokio = { version = "1", features = ["full"] }
toml = "0.7.3"
xdg = "2.4.1"
yacexits = { git = "https://git.tebibyte.media/yac/yacexits.git", branch = "c-entry", version = "0.2.0" }
yacexits = "0.1.5"

View File

@ -19,8 +19,6 @@
* Hopper. If not, see <https://www.gnu.org/licenses/>.
*/
#![no_main]
mod api;
mod args;
mod client;
@ -33,9 +31,13 @@ use client::*;
use config::*;
use hopfile::*;
use std::env::args;
use yacexits::{
exit,
EX_OSERR,
EX_SOFTWARE,
EX_USAGE,
};
struct AppContext {
@ -43,12 +45,26 @@ struct AppContext {
config: Config,
}
#[tokio::main]
#[no_mangle]
async fn rust_main(arguments: yacexits::Args) -> Result<u32, (String, u32)> {
let argv: Vec<&str> = arguments.into_iter().collect();
let args = Arguments::from_args(argv.clone().into_iter())
fn main() {
let argv = args().collect::<Vec<String>>();
match rust_main(argv.clone()) {
Ok(code) => exit(code),
Err((message, code)) => {
if code == EX_USAGE {
eprintln!("Usage: {} {}", argv[0], message);
} else {
eprintln!("{}: {}", argv[0], message);
}
exit(code);
},
};
}
#[tokio::main]
async fn rust_main(argv: Vec<String>) -> Result<u32, (String, u32)> {
let args = Arguments::from_args(argv.clone().iter().map(|s| s.as_str()))
.map_err(|err| { ArgsError::from(err) })?;
let config = Config::read_config()?;