cargo_modules/command/dependencies/
options.rs1use std::{fmt::Display, str::FromStr};
6
7use clap::Parser;
8
9use crate::options::{GeneralOptions, ProjectOptions};
10
11#[derive(Copy, Clone, PartialEq, Eq, Debug)]
12pub enum LayoutAlgorithm {
13 None,
14 Dot,
15 Neato,
16 Twopi,
17 Circo,
18 Fdp,
19 Sfdp,
20}
21
22impl FromStr for LayoutAlgorithm {
23 type Err = &'static str;
24
25 fn from_str(s: &str) -> Result<Self, Self::Err> {
26 match s {
27 "none" => Ok(Self::None),
28 "dot" => Ok(Self::Dot),
29 "neato" => Ok(Self::Neato),
30 "twopi" => Ok(Self::Twopi),
31 "circo" => Ok(Self::Circo),
32 "fdp" => Ok(Self::Fdp),
33 "sfdp" => Ok(Self::Sfdp),
34 _ => Err("Unrecognized layout"),
35 }
36 }
37}
38
39impl Display for LayoutAlgorithm {
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41 f.write_str(match self {
42 Self::None => "none",
43 Self::Dot => "dot",
44 Self::Neato => "neato",
45 Self::Twopi => "twopi",
46 Self::Circo => "circo",
47 Self::Fdp => "fdp",
48 Self::Sfdp => "sfdp",
49 })
50 }
51}
52
53#[derive(Copy, Clone, PartialEq, Eq, Debug)]
54pub enum SplinesType {
55 None,
56 Line,
57 Spline,
58 Ortho,
59}
60
61impl FromStr for SplinesType {
62 type Err = &'static str;
63
64 fn from_str(s: &str) -> Result<Self, Self::Err> {
65 match s {
66 "none" => Ok(Self::None),
67 "line" => Ok(Self::Line),
68 "spline" => Ok(Self::Spline),
69 "ortho" => Ok(Self::Ortho),
70 _ => Err("Unrecognized splines' type"),
71 }
72 }
73}
74
75impl Display for SplinesType {
76 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
77 f.write_str(match self {
78 Self::None => "none",
79 Self::Line => "line",
80 Self::Spline => "spline",
81 Self::Ortho => "ortho",
82 })
83 }
84}
85
86#[derive(Parser, Clone, PartialEq, Eq, Debug)]
87#[group(id = "GenerateSelectionOptions")]
88pub struct Options {
89 #[command(flatten)]
90 pub general: GeneralOptions,
91
92 #[command(flatten)]
93 pub project: ProjectOptions,
94
95 #[command(flatten)]
96 pub selection: SelectionOptions,
97
98 #[arg(long = "acyclic", conflicts_with = "focus_on")]
100 pub acyclic: bool,
101
102 #[arg(long = "layout", default_value = "neato")]
105 pub layout: LayoutAlgorithm,
106
107 #[arg(long = "splines", default_value = "line")]
110 pub splines: SplinesType,
111
112 #[arg(long = "focus-on")]
115 pub focus_on: Option<String>,
116
117 #[arg(long = "max-depth")]
120 pub max_depth: Option<usize>,
121
122 #[arg(long = "cfg-test")]
124 pub cfg_test: bool,
125}
126
127#[derive(Parser, Clone, PartialEq, Eq, Debug)]
134#[group(id = "SelectionOptions")]
135pub struct SelectionOptions {
136 #[arg(long = "no-externs")]
138 pub no_externs: bool,
139
140 #[arg(long = "no-fns")]
142 pub no_fns: bool,
143
144 #[clap(long = "no-modules")]
146 pub no_modules: bool,
147
148 #[clap(long = "no-owns")]
150 pub no_owns: bool,
151
152 #[arg(long = "no-sysroot")]
154 pub no_sysroot: bool,
155
156 #[arg(long = "no-traits")]
158 pub no_traits: bool,
159
160 #[arg(long = "no-types")]
162 pub no_types: bool,
163
164 #[arg(long = "no-uses")]
166 pub no_uses: bool,
167
168 #[arg(long = "no-private")]
170 pub no_private: bool,
171
172 #[arg(long = "no-pub-crate")]
174 pub no_pub_crate: bool,
175
176 #[arg(
178 long = "no-pub-module",
179 value_delimiter = ',',
180 conflicts_with = "no_pub_modules"
181 )]
182 pub no_pub_module: Vec<String>,
183
184 #[arg(long = "no-pub-modules", conflicts_with = "no_pub_module")]
186 pub no_pub_modules: bool,
187
188 #[arg(long = "no-pub-super")]
190 pub no_pub_super: bool,
191}