| mod commands; |
| mod graph; |
| mod parse; |
| mod portage; |
| |
| use std::env; |
| |
| use clap::{App, Arg, SubCommand}; |
| |
| #[macro_use] |
| extern crate rental; |
| |
| fn main() -> anyhow::Result<()> { |
| let config_path = env::var("XDG_CONFIG_HOME").unwrap_or(env::var("HOME").unwrap() + "/.config") |
| + "/drydock/config.toml"; |
| let mut config = config::Config::new(); |
| config.merge(config::File::with_name(&config_path)).unwrap(); |
| |
| let args = App::new("drydock") |
| .version("0.0.1") |
| .about("A tool for Portage profile analysis and introspection.") |
| .subcommand( |
| SubCommand::with_name("parents") |
| .about("Show the inheritance tree for the target profile.") |
| .arg( |
| Arg::with_name("profile") |
| .takes_value(true) |
| .required(true) |
| .multiple(true) |
| .help("The target profile. Example: chromiumos:base"), |
| ) |
| .arg( |
| Arg::with_name("tree") |
| .long("tree") |
| .takes_value(false) |
| .help("Print an indented tree of the profile parent structure."), |
| ) |
| .arg( |
| Arg::with_name("graph") |
| .long("graph") |
| .takes_value(false) |
| .help("Print graphviz dot formatting for the profile parent structure."), |
| ), |
| ) |
| .subcommand( |
| SubCommand::with_name("eval") |
| .about("Print the final value of a config variable for a profile.") |
| .arg( |
| Arg::with_name("profile") |
| .short("p") |
| .long("profile") |
| .takes_value(true) |
| .required(true) |
| .help("The target profile to query."), |
| ) |
| .arg( |
| Arg::with_name("variable") |
| .takes_value(true) |
| .required(true) |
| .multiple(false), |
| ), |
| ) |
| .subcommand( |
| SubCommand::with_name("blame") |
| .about("Show the value of a variable for a profile annotated with the sources of that variable's contents.") |
| .arg( |
| Arg::with_name("profile") |
| .short("p") |
| .long("profile") |
| .takes_value(true) |
| .required(true) |
| .help("The target profile to query."), |
| ) |
| .arg( |
| Arg::with_name("variable") |
| .takes_value(true) |
| .required(true) |
| .multiple(false), |
| ), |
| ) |
| .subcommand( |
| SubCommand::with_name("dump_debug") |
| .about("Dump debug information for an overlay.") |
| .arg( |
| Arg::with_name("overlay") |
| .short("o") |
| .long("overlay") |
| .takes_value(true) |
| .required(true) |
| .help("The target overlay to query."), |
| ), |
| ) |
| .get_matches(); |
| |
| match args.subcommand() { |
| ("blame", Some(sub_args)) => commands::blame(&config, sub_args)?, |
| ("dump_debug", Some(sub_args)) => commands::dump_debug(&config, sub_args)?, |
| ("eval", Some(sub_args)) => commands::eval(&config, sub_args)?, |
| ("parents", Some(sub_args)) => commands::parents(&config, sub_args)?, |
| _ => unimplemented!(), |
| }; |
| |
| Ok(()) |
| } |