hopper/src/main.rs

68 lines
1.7 KiB
Rust

use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use structopt::StructOpt;
#[derive(StructOpt, Debug)]
enum Command {
#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)]
Install { package_name: String },
#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)]
Remove { package_name: String },
#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)]
Update,
#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)]
Clean,
}
#[derive(StructOpt, Debug)]
#[structopt(name = "hopper", setting = structopt::clap::AppSettings::ColoredHelp)]
struct Args {
/// Path to configuration file
#[structopt(short, long, parse(from_os_str))]
config: Option<PathBuf>,
/// Path to mod lockfile
#[structopt(short, long, parse(from_os_str))]
lockfile: Option<PathBuf>,
#[structopt(subcommand)]
command: Command,
}
impl Args {
fn load_config(&self) -> Result<Config, confy::ConfyError> {
if let Some(config_path) = &self.config {
confy::load_path(config_path)
} else {
confy::load("hopper")
}
}
}
#[derive(Deserialize, Serialize, Debug)]
struct Upstream {
/// Modrinth main server address
server_address: String,
}
impl Default for Upstream {
fn default() -> Self {
Self {
server_address: "api.modrinth.com".into()
}
}
}
#[derive(Deserialize, Serialize, Debug, Default)]
struct Config {
/// Configuration for the upstream Modrinth server
upstream: Upstream,
}
fn main() -> Result<(), confy::ConfyError> {
let args = Args::from_args();
let config = args.load_config()?;
println!("args: {:#?}\nconfig: {:#?}", args, config);
Ok(())
}