{"id":21928085,"url":"https://github.com/depp/simpleargs","last_synced_at":"2025-03-22T12:18:41.352Z","repository":{"id":57667386,"uuid":"251200604","full_name":"depp/simpleargs","owner":"depp","description":"Simple Command-Line Argument Parsing for Rust","archived":false,"fork":false,"pushed_at":"2020-04-06T17:52:56.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T11:17:58.453Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/depp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-30T04:23:38.000Z","updated_at":"2020-04-06T17:52:58.000Z","dependencies_parsed_at":"2022-09-02T14:01:28.114Z","dependency_job_id":null,"html_url":"https://github.com/depp/simpleargs","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/depp%2Fsimpleargs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/depp%2Fsimpleargs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/depp%2Fsimpleargs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/depp%2Fsimpleargs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/depp","download_url":"https://codeload.github.com/depp/simpleargs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244952830,"owners_count":20537475,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-28T22:20:41.060Z","updated_at":"2025-03-22T12:18:41.328Z","avatar_url":"https://github.com/depp.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimpleArgs: Simple Command-Line Argument Parsing for Rust\n\nThis is a simple, small library for parsing command-line arguments in Rust.\n\nYou write your own parser which iterates over the arguments. SimpleArgs interprets the raw arguments and gives you high-quality error messages.\n\n## Example\n\n```rust\nuse simpleargs::{Arg, Args, UsageError, OptionError};\nuse std::ffi::OsString;\nuse std::str::FromStr;\n\nfn parse_args\u003cT\u003e(mut args: Args\u003cT\u003e) -\u003e Result\u003c(), UsageError\u003cOsString\u003e\u003e\nwhere\n    T: Iterator\u003cItem = OsString\u003e,\n{\n    // The input file\n    let mut input: Option\u003cOsString\u003e = None;\n    // True if -flag was set\n    let mut flag = false;\n    // The value of -xvalue, if it was used\n    let mut xvalue: Option\u003ci32\u003e = None;\n    loop {\n        match args.next() {\n            Arg::Positional(arg) =\u003e if input.is_some() {\n                return Err(UsageError::UnexpectedArgument { arg });\n            } else {\n                input = Some(arg)\n            }\n            Arg::Named(arg) =\u003e arg.parse(|name, value| match name {\n                \"flag\" =\u003e {\n                    // parse() above will return an error for -flag=value,\n                    // because this function does not use 'value'.\n                    flag = true;\n                    Ok(())\n                }\n                \"xvalue\" =\u003e {\n                    // Call as_str() for a str, or as_osstr() for OsStr.\n                    xvalue = Some(i32::from_str(value.as_str()?)?);\n                    Ok(())\n                }\n                _ =\u003e Err(OptionError::Unknown),\n            })?,\n            Arg::End =\u003e break,\n            Arg::Error(err) =\u003e return Err(err),\n        }\n    }\n    let input = match input {\n        Some(path) =\u003e path,\n        None =\u003e return Err(UsageError::MissingArgument { name: \"input\".to_owned() }),\n    };\n    Ok(())\n}\n```\n\n## Goals and Non-Goals\n\n- Simple argument parsing and nothing else. This library does not provide usage mesasges for your CLI utility (write your own), it does not validate arguments (do that yourself), and it does not collect arguments or put them into structs for you.\n\n- Handle `OsString` or `String`, user’s choice. This library will correctly preserve invalid Unicode data if you want. You can do pathological things like pass `-flag=$'\\xff'` to your command-line tools. However, if you don’t want this, you can just use the string methods instead.\n\n- Decent error messages.\n\n  ```\n  $ my-tool -namee=abc\n  Error: unknown option -namee\n  $ my-tool -name=$'\\xff'\n  Error: invalid value \"\\xff\" for -name: invalid Unicode string\n  $ my-tool -count=1q\n  Error: invalid value \"0q\" for option -count: invalid digit found in string\n  ```\n\n## Limitations\n\nKnown limitations we intend to fix:\n\n- No Windows support yet! `OsString` is a different beast on Windows. No, we can’t write generic code that works both on Windows and non-Windows systems.\n\n## Opinions\n\nKnown limitations that accepted as the library’s design:\n\n- You don’t want to combine short options. You can have three separate options `-a`, `-b`, and `-c`, but you **cannot** combine all three into `-abc`. Combining short flags into one argument is only useful for the most commonly used interactive tools, like `ls`.\n\n- There is no difference between `-option` and `--option`. One or two hyphens are treated identically.\n\n- All options after `--` are treated as positional arguments.\n\n- Options cannot accept multiple parameters. If you want something like `-pos \u003cx\u003e \u003cy\u003e`, you will have to write it as `-pos \u003cx\u003e,\u003cy\u003e`.\n\n## Comparisons\n\n- [Clap](https://github.com/clap-rs/clap) is fancy and has tons of features. It lets you define how each argument is parsed or stored in a few different ways. SimpleArgs is for people who prefer a more minimal, explicit approach.\n\n- [Docopt](https://github.com/docopt/docopt.rs) is for people who want to write the documentation first, and have a library generate a parser from the documentation. SimpleArgs is for people who want to write the parser separately.\n\n- [StructOpt](https://github.com/TeXitoi/structopt) is essentially a flavor of Clap.\n\n- [getopts](https://docs.rs/getopts/0.2.21/getopts/) is somewhat more simple and limited.\n\n- [Seahorse](https://github.com/ksk001100/seahorse) is an entire command-line tool framework.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdepp%2Fsimpleargs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdepp%2Fsimpleargs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdepp%2Fsimpleargs/lists"}