MCPcopy Create free account
hub / github.com/JamieMason/syncpack / parse

Method parse

src/cli.rs:121–199  ·  view source on GitHub ↗

Parse all command-line arguments from the user into a `Cli` struct

(args: &[String])

Source from the content-addressed store, hash-verified

119impl Cli {
120 /// Parse all command-line arguments from the user into a `Cli` struct
121 pub fn parse(args: &[String]) -> Result<Self, SyncpackError> {
122 fn from_arg_matches(subcommand: Subcommand, matches: &ArgMatches) -> Cli {
123 let cwd = env::current_dir().unwrap();
124 let dependencies = get_patterns(matches, "dependencies");
125 let dependency_types = get_patterns(matches, "dependency-types");
126 let packages = get_patterns(matches, "packages");
127 let specifier_types = get_patterns(matches, "specifier-types");
128 let filters = if dependencies.is_empty() && dependency_types.is_empty() && packages.is_empty() && specifier_types.is_empty() {
129 None
130 } else {
131 Some(GroupSelector::new(
132 dependencies,
133 dependency_types,
134 "CLI filters".to_string(),
135 packages,
136 specifier_types,
137 ))
138 };
139 Cli {
140 check: (matches!(&subcommand, Subcommand::Format | Subcommand::Update)) && matches.get_flag("check"),
141 config_path: matches.get_one::<PathBuf>("config").map(|config_path| {
142 if config_path.is_absolute() {
143 config_path.clone()
144 } else {
145 cwd.join(config_path)
146 }
147 }),
148 interactive: matches!(&subcommand, Subcommand::Update)
149 && matches.try_get_one::<bool>("interactive").ok().flatten().copied().unwrap_or(false),
150 no_cache: matches!(&subcommand, Subcommand::Update)
151 && matches.try_get_one::<bool>("no-cache").ok().flatten().copied().unwrap_or(false),
152 cwd,
153 disable_ansi: matches.get_flag("no-ansi"),
154 dry_run: (matches!(&subcommand, Subcommand::Fix | Subcommand::Format | Subcommand::Update)) && matches.get_flag("dry-run"),
155 filters,
156 log_levels: get_log_levels(matches),
157 reporter: get_reporter(&subcommand, matches),
158 show_hints: should_show(matches, "hints"),
159 show_ignored: should_show(matches, "ignored"),
160 show_instances: should_show(matches, "instances"),
161 show_status_codes: should_show(matches, "statuses"),
162 sort: get_order_by(matches),
163 source_patterns: get_patterns(matches, "source"),
164 source_mode: get_source_mode(matches),
165 subcommand,
166 target: get_target(matches),
167 }
168 }
169
170 fn from_deprecated(subcommand: Subcommand) -> Cli {
171 Cli {
172 subcommand,
173 ..Default::default()
174 }
175 }
176
177 create()
178 .try_get_matches_from(args)

Callers 1

Calls 1

createFunction · 0.85

Tested by

no test coverage detected