Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "getargs"
version = "0.5.0"
version = "0.6.0"
authors = ["Jasmine Tai <jtai@jtai.ca>", "LoganDark"]
edition = "2021"
license = "MIT"
Expand Down
6 changes: 3 additions & 3 deletions examples/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn parse_args<'a, I: Iterator<Item = &'a str>>(
}

let subcommand_name = opts
.next_positional()
.next_positional()?
.ok_or(UsageError::MissingSubcommand)?;
let subcommand = match subcommand_name {
"c" | "create" => parse_create_args(opts)?,
Expand All @@ -86,7 +86,7 @@ fn parse_create_args<'a, I: Iterator<Item = &'a str>>(
}
}

let args = opts.positionals().collect();
let args = opts.positionals()?.collect();
Ok(Subcommand::Create { output, args })
}

Expand All @@ -104,7 +104,7 @@ fn parse_delete_args<'a, I: Iterator<Item = &'a str>>(
}
}

let args = opts.positionals().collect();
let args = opts.positionals()?.collect();
Ok(Subcommand::Delete { backup, args })
}

Expand Down
2 changes: 1 addition & 1 deletion examples/no_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() {
}
}

for positional in opts.positionals() {
for positional in opts.positionals().expect("calling Options::positionals") {
eprintln!("positional argument: {}", positional);
}
}
2 changes: 1 addition & 1 deletion examples/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ optional value.
}
}

for arg in opts.positionals() {
for arg in opts.positionals().unwrap() {
eprintln!("positional: {:?}", arg)
}
}
6 changes: 3 additions & 3 deletions examples/subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn parse<'arg, I: Iterator<Item = &'arg str>>(
println!("option for base command: {opt}");
}

let subcommand = opts.next_positional();
let subcommand = opts.next_positional()?;
println!("subcommand: {subcommand:?}");
match subcommand {
None => println!("no subcommand"),
Expand All @@ -35,7 +35,7 @@ fn parse_run<'arg, I: Iterator<Item = &'arg str>>(
_ => println!("'run' subcommand got unknown option {opt:?}"),
}
}
for pos in opts.positionals() {
for pos in opts.positionals()? {
println!("positional arg: {pos}");
}
Ok(())
Expand All @@ -53,7 +53,7 @@ fn parse_test<'arg, I: Iterator<Item = &'arg str>>(
_ => println!("'test' subcommand got unknown option {opt:?}"),
}
}
for pos in opts.positionals() {
for pos in opts.positionals()? {
println!("positional arg: {pos}");
}
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ pub enum Error<A: Argument> {
/// [`Options::next_opt`][crate::Options::next_opt] or
/// [`Options::next_arg`][crate::Options::next_arg] is called
/// without the value being consumed.
DoesNotRequireValue(Opt<A>),
RequiresNoValue(Opt<A>),
}

impl<'arg, S: Display, A: Argument<ShortOpt = S> + Display + 'arg> Display for Error<A> {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
match self {
Error::RequiresValue(opt) => write!(f, "option requires a value: {}", opt),
Error::DoesNotRequireValue(opt) => {
Error::RequiresNoValue(opt) => {
write!(f, "option does not require a value: {}", opt)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl<'opts, A: Argument, I: Iterator<Item = A>> Iterator for Positionals<'opts,
type Item = A;

fn next(&mut self) -> Option<Self::Item> {
self.inner.next_positional()
self.inner.next_positional().unwrap()
}
}

Expand Down
Loading