{"id":30876534,"url":"https://github.com/tailwags/sap","last_synced_at":"2025-09-08T02:48:50.029Z","repository":{"id":50650686,"uuid":"519449158","full_name":"tailwags/sap","owner":"tailwags","description":"🌿 A small, simple and sweet argument parser for Rust","archived":false,"fork":false,"pushed_at":"2025-09-05T19:38:16.000Z","size":178,"stargazers_count":8,"open_issues_count":4,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-05T21:22:00.656Z","etag":null,"topics":["args","argument-parsing","commandlineparser","rust"],"latest_commit_sha":null,"homepage":"https://docs.rs/sap","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tailwags.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-07-30T07:25:59.000Z","updated_at":"2025-09-05T19:38:20.000Z","dependencies_parsed_at":"2025-05-19T12:37:50.071Z","dependency_job_id":"6f38f4a8-70b7-46b6-9a5a-72769a60b2fe","html_url":"https://github.com/tailwags/sap","commit_stats":null,"previous_names":["tailwags/sap"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tailwags/sap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tailwags%2Fsap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tailwags%2Fsap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tailwags%2Fsap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tailwags%2Fsap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tailwags","download_url":"https://codeload.github.com/tailwags/sap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tailwags%2Fsap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274125757,"owners_count":25226491,"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","status":"online","status_checked_at":"2025-09-08T02:00:09.813Z","response_time":121,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["args","argument-parsing","commandlineparser","rust"],"created_at":"2025-09-08T02:48:48.920Z","updated_at":"2025-09-08T02:48:50.018Z","avatar_url":"https://github.com/tailwags.png","language":"Rust","readme":"# 🌿 Sap\n\n_A small, simple and sweet argument parser for Rust_\n\n[![Crates.io](https://img.shields.io/crates/v/sap.svg)](https://crates.io/crates/sap)\n[![Documentation](https://docs.rs/sap/badge.svg)](https://docs.rs/sap)\n[![License](https://img.shields.io/crates/l/sap.svg)](LICENSE)\n\nSap is a minimal, zero-dependency Unix command-line argument parser for Rust. It provides full control over argument parsing with an iterator-based API that handles GNU-style options while maintaining simplicity and flexibility.\n\n## ✨ Features\n\n- **GNU-style option parsing**: Support for short (`-a`), long (`--verbose`), and combined options (`-abc`)\n- **Flexible value handling**: Options with values via `--name=value` or separate arguments\n- **POSIX compliance**: Handle `--` separator and `-` (stdin) arguments correctly\n- **Zero dependencies**: Pure Rust implementation with no external crates\n- **Iterator-based**: Works with any `Iterator\u003cItem = Into\u003cString\u003e\u003e` for maximum flexibility\n- **Comprehensive error handling**: Descriptive error messages for invalid input\n\n## 🚀 Quick Start\n\nAdd Sap to your `Cargo.toml`:\n\n```toml\n[dependencies]\nsap = \"0.0.5\"\n```\n\n## 📖 Usage\n\n### Basic Example\n\n```rust\nuse sap::{Parser, Argument};\n\n// Parse from command line arguments\nlet mut parser = Parser::from_env().unwrap();\n\nwhile let Some(arg) = parser.forward().unwrap() {\n    match arg {\n        Argument::Short('v') =\u003e println!(\"Verbose mode enabled\"),\n        Argument::Long(\"help\") =\u003e println!(\"Help requested\"),\n        Argument::Long(\"file\") =\u003e {\n            if let Some(filename) = parser.value() {\n                println!(\"Processing file: {}\", filename);\n            }\n        }\n        Argument::Value(val) =\u003e println!(\"Positional argument: {}\", val),\n        Argument::Stdio =\u003e println!(\"Reading from stdin\"),\n    }\n}\n```\n\n### Parsing Custom Arguments\n\n```rust\nuse sap::{Parser, Argument};\n\n// Parse from any iterator of string-like values\nlet mut parser = Parser::from_arbitrary([\"myprogram\", \"-v\", \"--file=input.txt\"]).unwrap();\n\nwhile let Some(arg) = parser.forward().unwrap() {\n    match arg {\n        Argument::Short('v') =\u003e println!(\"Verbose mode enabled\"),\n        Argument::Long(\"file\") =\u003e {\n            if let Some(filename) = parser.value() {\n                println!(\"Processing file: {}\", filename);\n            }\n        }\n        Argument::Value(val) =\u003e println!(\"Positional argument: {}\", val),\n        _ =\u003e {}\n    }\n}\n```\n\n## 🎯 Argument Types\n\nSap recognizes four types of arguments:\n\n- **`Argument::Short(char)`** - Short options like `-v`, `-x`, and combined ones like `-abc`\n- **`Argument::Long(\u0026str)`** - Long options like `--verbose`, `--file`, including values like `--file=foo.txt`\n- **`Argument::Value(Cow\u003cstr\u003e)`** - Positional arguments and operands\n- **`Argument::Stdio`** - The special `-` argument (stdin/stdout)\n\n## 📚 Complete Example\n\nHere's a more comprehensive example showing a typical CLI application:\n\n```rust\nuse sap::{Parser, Argument, Result};\n\nfn main() -\u003e Result\u003c()\u003e {\n    let mut parser = Parser::from_env()?;\n    let mut verbose = false;\n    let mut output_file = None;\n    let mut input_files = Vec::new();\n\n    while let Some(arg) = parser.forward()? {\n        match arg {\n            Argument::Short('v') | Argument::Long(\"verbose\") =\u003e {\n                verbose = true;\n            }\n            Argument::Short('h') | Argument::Long(\"help\") =\u003e {\n                print_help(parser.name());\n                return Ok(());\n            }\n            Argument::Short('o') | Argument::Long(\"output\") =\u003e {\n                output_file = parser.value();\n                if output_file.is_none() {\n                    eprintln!(\"Error: --output requires a value\");\n                    std::process::exit(1);\n                }\n            }\n            Argument::Value(file) =\u003e {\n                input_files.push(file.into_owned());\n            }\n            Argument::Stdio =\u003e {\n                input_files.push(\"-\".to_string());\n            }\n            unknown =\u003e {\n                eprintln!(\"Error: {}\", unknown.into_error(parser.value()));\n                std::process::exit(1);\n            }\n        }\n    }\n\n    if verbose {\n        println!(\"Verbose mode enabled\");\n        if let Some(ref output) = output_file {\n            println!(\"Output file: {}\", output);\n        }\n        println!(\"Input files: {:?}\", input_files);\n    }\n\n    Ok(())\n}\n\nfn print_help(program_name: \u0026str) {\n    println!(\"Usage: {} [OPTIONS] [FILES...]\", program_name);\n    println!(\"Options:\");\n    println!(\"  -v, --verbose    Enable verbose output\");\n    println!(\"  -o, --output     Specify output file\");\n    println!(\"  -h, --help       Show this help message\");\n}\n```\n\n## 🔍 Real-World Examples\n\nFor comprehensive examples of Sap in action, check out [**puppyutils**](https://github.com/puppyutils/puppyutils) - a collection of Unix utilities reimplemented in Rust. Sap was originally created as the argument parser for this project, so you'll find extensive real-world usage patterns.\n\n## 🤝 Acknowledgments\n\nSpecial thanks to [Esther](https://github.com/esther-ff) who wrote the original parser design for this library \u003c3\n\n## License\n\nThis project is licensed under the\n[Apache-2.0 License](http://www.apache.org/licenses/LICENSE-2.0). For more\ninformation, please see the [LICENSE](LICENSE) file.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftailwags%2Fsap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftailwags%2Fsap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftailwags%2Fsap/lists"}