{"id":19706231,"url":"https://github.com/clap-rs/clap-port-flag","last_synced_at":"2025-12-12T14:43:45.159Z","repository":{"id":45874018,"uuid":"135905322","full_name":"clap-rs/clap-port-flag","owner":"clap-rs","description":"Easily add address \u0026 port flags to CLIs using Clap","archived":false,"fork":false,"pushed_at":"2023-12-18T18:00:01.000Z","size":73,"stargazers_count":15,"open_issues_count":7,"forks_count":2,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-06-11T10:21:47.828Z","etag":null,"topics":["clap","cli","rust"],"latest_commit_sha":null,"homepage":"","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/clap-rs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE-APACHE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-06-03T13:13:03.000Z","updated_at":"2024-05-20T09:04:52.000Z","dependencies_parsed_at":"2023-09-26T10:02:46.786Z","dependency_job_id":"4cddecf2-9445-43fc-9759-c57fc0bbad81","html_url":"https://github.com/clap-rs/clap-port-flag","commit_stats":{"total_commits":48,"total_committers":5,"mean_commits":9.6,"dds":0.375,"last_synced_commit":"98aed8588b0b68bec98ae33429dd04365ddf7766"},"previous_names":["rust-clique/clap-port-flag"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/clap-rs/clap-port-flag","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clap-rs%2Fclap-port-flag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clap-rs%2Fclap-port-flag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clap-rs%2Fclap-port-flag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clap-rs%2Fclap-port-flag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clap-rs","download_url":"https://codeload.github.com/clap-rs/clap-port-flag/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clap-rs%2Fclap-port-flag/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260899435,"owners_count":23079364,"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":["clap","cli","rust"],"created_at":"2024-11-11T21:34:42.279Z","updated_at":"2025-12-12T14:43:40.113Z","avatar_url":"https://github.com/clap-rs.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# clap-port-flag\n\n[![crates.io version][1]][2] [![build status][3]][4]\n[![downloads][5]][6] [![docs.rs docs][7]][8]\n\nEasily add a `--port` flag to CLIs using clap.\n\n- [Documentation][8]\n- [Crates.io][2]\n\n## Usage\n\n### Example: Base\n\nWith the following code in `src/main.rs`:\n\n```rust,no_run\nuse clap::Parser;\nuse clap_port_flag::Port;\n\n#[derive(Debug, Parser)]\nstruct Cli {\n    #[clap(flatten)]\n    port: Port,\n}\n\nfn main() {\n    let args = Cli::parse();\n    let _tcp_listener = args.port.bind().unwrap();\n}\n```\n\nWhen you run the binary, it'll provide the following output:\n\n```txt\nmy-cool-app 0.2.0\nAlice Person \u003calice@person.com\u003e\nApplication that does things over TCP.\n\nUSAGE:\n    main [OPTIONS]\n\nFLAGS:\n    -h, --help       Prints help information\n    -V, --version    Prints version information\n\nOPTIONS:\n        --listen-fd \u003cfd\u003e         A previously opened network socket. [env: LISTEN_FD=]\n    -a, --address \u003chostname\u003e     The network address to listen to. [default: 127.0.0.1]\n    -p, --port \u003cport\u003e            The network port to listen to. [env: PORT=]\n```\n\n### Example: Hyper\n\n```rust,no_run\nuse clap_port_flag::Port;\nuse futures::prelude::*;\nuse hyper::service::service_fn;\nuse hyper::{Body, Response, Request};\nuse clap::Parser;\n\n#[derive(Debug, Parser)]\nstruct Cli {\n    #[clap(flatten)]\n    port: Port,\n}\n\nasync fn hello(_: Request\u003cBody\u003e) -\u003e Result\u003cResponse\u003cString\u003e, std::convert::Infallible\u003e {\n    Ok(Response::new(String::from(\"Hello World!\")))\n}\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    let args = Cli::parse();\n    let listener = args.port.bind()?;\n    let listener = tokio::net::TcpListener::from_std(listener)?;\n    let addr = listener.local_addr()?;\n\n    println!(\"Server listening on {}\", addr);\n\n    let (stream, _) = listener.accept().await?;\n    if let Err(e) = hyper::server::conn::Http::new()\n        .serve_connection(stream, service_fn(hello))\n        .await\n    {\n        eprintln!(\"server error: {}\", e);\n    }\n    Ok(())\n}\n```\n\n## Installation\n\n```sh\n$ cargo add clap-port-flag\n```\n\n## Further Reading\n\n- [WhatWG URL spec](https://url.spec.whatwg.org/)\n- [nodejs.org/api/url](https://nodejs.org/api/url.html)\n\n## Acknowledgements\n\nThe original version of this crate was sketched out by\n[@TeXitoi](https://github.com/TeXitoi) in\n[rust-lang-nursery/cli-wg#37](https://github.com/rust-lang-nursery/cli-wg/issues/37).\n\n## License\n\n[MIT](./LICENSE-MIT) OR [Apache-2.0](./LICENSE-APACHE)\n\n[1]: https://img.shields.io/crates/v/clap-port-flag.svg?style=flat-square\n[2]: https://crates.io/crates/clap-port-flag\n[3]: https://img.shields.io/travis/rust-clique/clap-port-flag.svg?style=flat-square\n[4]: https://travis-ci.org/rust-clique/clap-port-flag\n[5]: https://img.shields.io/crates/d/clap-port-flag.svg?style=flat-square\n[6]: https://crates.io/crates/clap-port-flag\n[7]: https://docs.rs/clap-port-flag/badge.svg\n[8]: https://docs.rs/clap-port-flag\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclap-rs%2Fclap-port-flag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclap-rs%2Fclap-port-flag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclap-rs%2Fclap-port-flag/lists"}