mirror of
https://github.com/gay-pizza/jaarg.git
synced 2025-12-19 15:30:16 +00:00
Initial parser implementation and bin2h example program
This commit is contained in:
21
src/std.rs
Normal file
21
src/std.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
/* jaarg - Argument parser
|
||||
* SPDX-FileCopyrightText: (C) 2025 Gay Pizza Specifications
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
extern crate std;
|
||||
|
||||
use crate::{HandlerResult, Opt, Opts, ParseControl, ParseResult};
|
||||
|
||||
impl<ID: 'static> Opts<ID> {
|
||||
/// Wrapper around `parse` that gathers arguments from the command line and prints errors to stderr.
|
||||
///
|
||||
/// Requires std
|
||||
pub fn parse_env<'a>(&self, handler: impl FnMut(&ID, &Opt<ID>, &str, &str) -> HandlerResult<'a, ParseControl>
|
||||
) -> ParseResult {
|
||||
let mut argv = std::env::args();
|
||||
let argv0 = argv.next().unwrap();
|
||||
let program_name = std::path::Path::new(&argv0).file_name().unwrap().to_string_lossy();
|
||||
self.parse(&program_name, argv, handler, |e| { std::eprintln!("error: {e}") })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user