use std::{fmt::Display, str::FromStr};
use clap::Parser;
use crate::options::{GeneralOptions, ProjectOptions};
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum LayoutAlgorithm {
None,
Dot,
Neato,
Twopi,
Circo,
Fdp,
Sfdp,
}
impl FromStr for LayoutAlgorithm {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"none" => Ok(Self::None),
"dot" => Ok(Self::Dot),
"neato" => Ok(Self::Neato),
"twopi" => Ok(Self::Twopi),
"circo" => Ok(Self::Circo),
"fdp" => Ok(Self::Fdp),
"sfdp" => Ok(Self::Sfdp),
_ => Err("Unrecognized layout"),
}
}
}
impl Display for LayoutAlgorithm {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::None => "none",
Self::Dot => "dot",
Self::Neato => "neato",
Self::Twopi => "twopi",
Self::Circo => "circo",
Self::Fdp => "fdp",
Self::Sfdp => "sfdp",
})
}
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum SplinesType {
None,
Line,
Spline,
Ortho,
}
impl FromStr for SplinesType {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"none" => Ok(Self::None),
"line" => Ok(Self::Line),
"spline" => Ok(Self::Spline),
"ortho" => Ok(Self::Ortho),
_ => Err("Unrecognized splines' type"),
}
}
}
impl Display for SplinesType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::None => "none",
Self::Line => "line",
Self::Spline => "spline",
Self::Ortho => "ortho",
})
}
}
#[derive(Parser, Clone, PartialEq, Eq, Debug)]
#[group(id = "GenerateSelectionOptions")]
pub struct Options {
#[command(flatten)]
pub general: GeneralOptions,
#[command(flatten)]
pub project: ProjectOptions,
#[command(flatten)]
pub selection: SelectionOptions,
#[arg(long = "acyclic", conflicts_with = "focus_on")]
pub acyclic: bool,
#[arg(long = "layout", default_value = "neato")]
pub layout: LayoutAlgorithm,
#[arg(long = "splines", default_value = "line")]
pub splines: SplinesType,
#[arg(long = "focus-on")]
pub focus_on: Option<String>,
#[arg(long = "max-depth")]
pub max_depth: Option<usize>,
#[arg(long = "cfg-test")]
pub cfg_test: bool,
}
#[derive(Parser, Clone, PartialEq, Eq, Debug)]
#[group(id = "SelectionOptions")]
pub struct SelectionOptions {
#[arg(long = "no-externs")]
pub no_externs: bool,
#[arg(long = "no-fns")]
pub no_fns: bool,
#[clap(long = "no-modules")]
pub no_modules: bool,
#[clap(long = "no-owns")]
pub no_owns: bool,
#[arg(long = "no-sysroot")]
pub no_sysroot: bool,
#[arg(long = "no-traits")]
pub no_traits: bool,
#[arg(long = "no-types")]
pub no_types: bool,
#[arg(long = "no-uses")]
pub no_uses: bool,
#[arg(long = "no-private")]
pub no_private: bool,
#[arg(long = "no-pub-crate")]
pub no_pub_crate: bool,
#[arg(
long = "no-pub-module",
value_delimiter = ',',
conflicts_with = "no_pub_modules"
)]
pub no_pub_module: Vec<String>,
#[arg(long = "no-pub-modules", conflicts_with = "no_pub_module")]
pub no_pub_modules: bool,
#[arg(long = "no-pub-super")]
pub no_pub_super: bool,
}