MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / parse

Method parse

crates/update/src/proxy.rs:148–180  ·  view source on GitHub ↗
(args: &'a [OsString])

Source from the content-addressed store, hash-verified

146 }
147
148 fn parse(args: &'a [OsString]) -> anyhow::Result<Self> {
149 let mut args = args.iter();
150 let mut root_dir = None;
151 let mut maybe_subcommand = None;
152 while let Some(arg) = args.next() {
153 let is_arg_value = |s: &OsStr| !os_str_starts_with(arg, "-") || s == "-";
154 // "parse" only up to the first subcommand
155 if is_arg_value(arg) {
156 maybe_subcommand = Some(&**arg);
157 break;
158 } else if arg == "--" {
159 break;
160 }
161 let root_dir_arg = if arg == "--root-dir" {
162 args.next()
163 .filter(|s| is_arg_value(s))
164 .context("a value is required for '--root-dir <root_dir>' but none was supplied")?
165 } else if let Some(arg) = os_str_strip_prefix(arg, "--root-dir=") {
166 arg
167 } else {
168 continue;
169 };
170 anyhow::ensure!(
171 root_dir.is_none(),
172 "the argument '--root-dir <root_dir>' cannot be used multiple times"
173 );
174 root_dir = Some(RootDir(root_dir_arg.into()));
175 }
176 Ok(Self {
177 root_dir,
178 maybe_subcommand,
179 })
180 }
181}
182
183fn os_str_starts_with(s: &OsStr, pref: &str) -> bool {

Callers 1

reqwest_client_builderFunction · 0.45

Calls 6

os_str_starts_withFunction · 0.85
os_str_strip_prefixFunction · 0.85
iterMethod · 0.65
filterMethod · 0.65
OkFunction · 0.50
nextMethod · 0.45

Tested by

no test coverage detected