{"id":13395477,"url":"https://github.com/TeXitoi/structopt","last_synced_at":"2025-03-13T20:32:14.233Z","repository":{"id":37665023,"uuid":"80781523","full_name":"TeXitoi/structopt","owner":"TeXitoi","description":"Parse command line arguments by defining a struct.","archived":false,"fork":false,"pushed_at":"2024-01-07T23:29:29.000Z","size":643,"stargazers_count":2721,"open_issues_count":5,"forks_count":152,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-03-11T19:23:17.867Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TeXitoi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","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}},"created_at":"2017-02-03T00:04:25.000Z","updated_at":"2025-03-06T20:37:49.000Z","dependencies_parsed_at":"2024-02-01T17:44:49.265Z","dependency_job_id":null,"html_url":"https://github.com/TeXitoi/structopt","commit_stats":{"total_commits":368,"total_committers":72,"mean_commits":5.111111111111111,"dds":0.7282608695652174,"last_synced_commit":"c0933257c769e0a74445b82b083b14070c81ce9e"},"previous_names":[],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TeXitoi%2Fstructopt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TeXitoi%2Fstructopt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TeXitoi%2Fstructopt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TeXitoi%2Fstructopt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TeXitoi","download_url":"https://codeload.github.com/TeXitoi/structopt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243478461,"owners_count":20297264,"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-07-30T17:02:01.209Z","updated_at":"2025-03-13T20:32:13.936Z","avatar_url":"https://github.com/TeXitoi.png","language":"Rust","readme":"# StructOpt\n\n[![Build status](https://travis-ci.com/TeXitoi/structopt.svg?branch=master)](https://app.travis-ci.com/github/TeXitoi/structopt) [![](https://img.shields.io/crates/v/structopt.svg)](https://crates.io/crates/structopt) [![](https://docs.rs/structopt/badge.svg)](https://docs.rs/structopt)\n[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)\n\nParse command line arguments by defining a struct.  It combines [clap](https://crates.io/crates/clap) with custom derive.\n\n## Maintenance\n\nAs clap v3 is now out, and the structopt features are integrated into (almost as-is), structopt is now in maintenance mode: no new feature will be added.\n\nBugs will be fixed, and documentation improvements will be accepted.\n\nSee the [structopt -\u003e clap migration guide](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md#migrating)\n\n## Documentation\n\nFind it on [Docs.rs](https://docs.rs/structopt).  You can also check the [examples](https://github.com/TeXitoi/structopt/tree/master/examples) and the [changelog](https://github.com/TeXitoi/structopt/blob/master/CHANGELOG.md).\n\n## Example\n\nAdd `structopt` to your dependencies of your `Cargo.toml`:\n```toml\n[dependencies]\nstructopt = \"0.3\"\n```\n\nAnd then, in your rust file:\n```rust\nuse std::path::PathBuf;\nuse structopt::StructOpt;\n\n/// A basic example\n#[derive(StructOpt, Debug)]\n#[structopt(name = \"basic\")]\nstruct Opt {\n    // A flag, true if used in the command line. Note doc comment will\n    // be used for the help message of the flag. The name of the\n    // argument will be, by default, based on the name of the field.\n    /// Activate debug mode\n    #[structopt(short, long)]\n    debug: bool,\n\n    // The number of occurrences of the `v/verbose` flag\n    /// Verbose mode (-v, -vv, -vvv, etc.)\n    #[structopt(short, long, parse(from_occurrences))]\n    verbose: u8,\n\n    /// Set speed\n    #[structopt(short, long, default_value = \"42\")]\n    speed: f64,\n\n    /// Output file\n    #[structopt(short, long, parse(from_os_str))]\n    output: PathBuf,\n\n    // the long option will be translated by default to kebab case,\n    // i.e. `--nb-cars`.\n    /// Number of cars\n    #[structopt(short = \"c\", long)]\n    nb_cars: Option\u003ci32\u003e,\n\n    /// admin_level to consider\n    #[structopt(short, long)]\n    level: Vec\u003cString\u003e,\n\n    /// Files to process\n    #[structopt(name = \"FILE\", parse(from_os_str))]\n    files: Vec\u003cPathBuf\u003e,\n}\n\nfn main() {\n    let opt = Opt::from_args();\n    println!(\"{:#?}\", opt);\n}\n```\n\nUsing this example:\n```\n$ ./basic\nerror: The following required arguments were not provided:\n    --output \u003coutput\u003e\n\nUSAGE:\n    basic --output \u003coutput\u003e --speed \u003cspeed\u003e\n\nFor more information try --help\n$ ./basic --help\nbasic 0.3.0\nGuillaume Pinot \u003ctexitoi@texitoi.eu\u003e, others\nA basic example\n\nUSAGE:\n    basic [FLAGS] [OPTIONS] --output \u003coutput\u003e [--] [file]...\n\nFLAGS:\n    -d, --debug      Activate debug mode\n    -h, --help       Prints help information\n    -V, --version    Prints version information\n    -v, --verbose    Verbose mode (-v, -vv, -vvv, etc.)\n\nOPTIONS:\n    -l, --level \u003clevel\u003e...     admin_level to consider\n    -c, --nb-cars \u003cnb-cars\u003e    Number of cars\n    -o, --output \u003coutput\u003e      Output file\n    -s, --speed \u003cspeed\u003e        Set speed [default: 42]\n\nARGS:\n    \u003cfile\u003e...    Files to process\n$ ./basic -o foo.txt\nOpt {\n    debug: false,\n    verbose: 0,\n    speed: 42.0,\n    output: \"foo.txt\",\n    nb_cars: None,\n    level: [],\n    files: [],\n}\n$ ./basic -o foo.txt -dvvvs 1337 -l alice -l bob --nb-cars 4 bar.txt baz.txt\nOpt {\n    debug: true,\n    verbose: 3,\n    speed: 1337.0,\n    output: \"foo.txt\",\n    nb_cars: Some(\n        4,\n    ),\n    level: [\n        \"alice\",\n        \"bob\",\n    ],\n    files: [\n        \"bar.txt\",\n        \"baz.txt\",\n    ],\n}\n```\n\n## StructOpt rustc version policy\n\n- Minimum rustc version modification must be specified in the [changelog](https://github.com/TeXitoi/structopt/blob/master/CHANGELOG.md) and in the [travis configuration](https://github.com/TeXitoi/structopt/blob/master/.travis.yml).\n- Contributors can increment minimum rustc version without any justification if the new version is required by the latest version of one of StructOpt's dependencies (`cargo update` will not fail on StructOpt).\n- Contributors can increment minimum rustc version if the library user experience is improved.\n\n## License\n\nLicensed under either of\n\n- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or \u003chttps://www.apache.org/licenses/LICENSE-2.0\u003e)\n- MIT license ([LICENSE-MIT](LICENSE-MIT) or \u003chttps://opensource.org/licenses/MIT\u003e)\n\nat your option.\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n","funding_links":[],"categories":["Rust","Libraries","库 Libraries","库","[Rust](https://www.rust-lang.org/)","Rust 🦀"],"sub_categories":["Command-line","命令行 Command-line","命令行","Rust libraries","Useful awesome list for Ruby cli"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTeXitoi%2Fstructopt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTeXitoi%2Fstructopt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTeXitoi%2Fstructopt/lists"}