hopper/src/main.rs

84 lines
2.1 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (c) 20212022 Marceline Cramer <mars@tebibyte.media>
* Copyright (c) 20222023 Emma Tebibyte <emma@tebibyte.media>
* Copyright (c) 2022 Spookdot <https://git.tebibyte.media/spookdot/>
* Copyright (c) 20222023 [ ] <https://git.tebibyte.media/BlankParenthesis/>
* SPDX-License-Identifier: AGPL-3.0-or-later
*
* This file is part of Hopper.
*
* Hopper is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* Hopper is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with
* Hopper. If not, see <https://www.gnu.org/licenses/>.
*/
mod api;
mod args;
mod client;
mod config;
mod hopfile;
use api::*;
use args::*;
use client::*;
use config::*;
use hopfile::*;
use std::env::args;
use yacexits::{
exit,
EX_OSERR,
EX_SOFTWARE,
EX_USAGE,
};
struct AppContext {
args: Arguments,
config: Config,
}
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()?;
let ctx = AppContext { args, config };
match ctx.args.sub {
// Command::Get(search_args) => cmd_get(&ctx, search_args).await,
// Command::Init(hopfile_args) => cmd_init(hopfile_args).await,
_ => {
let message = format!(
"{}: Unimplemented subcommand.", ctx.args.sub
);
Err((message, EX_SOFTWARE))
},
}?
}