{"id":20122889,"url":"https://github.com/freaky/command-limits","last_synced_at":"2026-04-21T03:32:35.735Z","repository":{"id":142942502,"uuid":"501734090","full_name":"Freaky/command-limits","owner":"Freaky","description":"Build command lines that respect argument size limits","archived":false,"fork":false,"pushed_at":"2022-06-13T17:04:53.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-02T11:56:19.762Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Freaky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2022-06-09T16:43:33.000Z","updated_at":"2022-06-09T16:44:12.000Z","dependencies_parsed_at":"2023-04-07T07:01:07.565Z","dependency_job_id":null,"html_url":"https://github.com/Freaky/command-limits","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Freaky/command-limits","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freaky%2Fcommand-limits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freaky%2Fcommand-limits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freaky%2Fcommand-limits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freaky%2Fcommand-limits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Freaky","download_url":"https://codeload.github.com/Freaky/command-limits/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freaky%2Fcommand-limits/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32075235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T02:38:07.213Z","status":"ssl_error","status_checked_at":"2026-04-21T02:38:06.559Z","response_time":128,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-11-13T19:41:41.326Z","updated_at":"2026-04-21T03:32:35.719Z","avatar_url":"https://github.com/Freaky.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# command_limits\n\nDetect and enforce platform argument/environment size limits for command execution.\n\n## Synopsis\n\n```rust\npub struct CommandLimits {\n    pub arg_size: NonZeroUsize,\n    pub individual_arg_size: Option\u003cNonZeroUsize\u003e,\n    pub arg_count: Option\u003cNonZeroUsize\u003e,\n    pub env_size: Option\u003cNonZeroUsize\u003e,\n    pub individual_env_size: Option\u003cNonZeroUsize\u003e,\n    pub env_count: Option\u003cNonZeroUsize\u003e,\n}\n\npub enum Error {\n    InsufficientSpace,\n    TooMany,\n    TooLarge,\n}\n\npub type Result\u003cT\u003e = std::result::Result\u003cT, Error\u003e;\n\npub struct CommandBuilder { /* private */ }\n\nimpl CommandBuilder {\n    pub fn new\u003cS\u003e(command: S) -\u003e Result\u003cSelf\u003e\n    where\n        S: AsRef\u003cOsStr\u003e;\n\n    pub fn new_capture_env\u003cS\u003e(command: S) -\u003e Result\u003cSelf\u003e\n    where\n        S: AsRef\u003cOsStr\u003e;\n\n    pub fn with_limits\u003cS\u003e(command: S, limits: CommandLimits) -\u003e Result\u003cSelf\u003e\n    where\n        S: AsRef\u003cOsStr\u003e;\n\n    pub fn capture_with_limits\u003cS\u003e(command: S, limits: CommandLimits) -\u003e Result\u003cSelf\u003e\n    where\n        S: AsRef\u003cOsStr\u003e;\n\n    pub fn arg\u003cS\u003e(\u0026mut self, arg: S) -\u003e Result\u003c\u0026mut Self\u003e\n    where\n        S: AsRef\u003cOsStr\u003e;\n\n    pub fn args\u003cS\u003e(\u0026mut self, args: \u0026[S]) -\u003e Result\u003c\u0026mut Self\u003e\n    where\n        S: AsRef\u003cOsStr\u003e;\n\n    pub fn env\u003cK, V\u003e(\u0026mut self, key: K, value: V) -\u003e Result\u003c\u0026mut Self\u003e\n    where\n        K: AsRef\u003cOsStr\u003e,\n        V: AsRef\u003cOsStr\u003e;\n\n    pub fn env_remove\u003cK\u003e(\u0026mut self, key: K) -\u003e \u0026mut Self\n    where\n        K: AsRef\u003cOsStr\u003e;\n\n    pub fn inherit_env(\u0026mut self) -\u003e Result\u003c\u0026mut Self\u003e;\n    pub fn capture_env(\u0026mut self) -\u003e Result\u003c\u0026mut Self\u003e;\n    pub fn env_clear(\u0026mut self) -\u003e \u0026mut Self;\n    pub fn into_command(\u0026self) -\u003e std::process::Command;\n    pub fn get_program(\u0026self) -\u003e \u0026OsStr;\n    pub fn get_args(\u0026self) -\u003e \u0026[OsString];\n    pub fn get_limits(\u0026self) -\u003e CommandLimits;\n    pub fn arg_size(\u0026self) -\u003e usize;\n    pub fn env_size(\u0026self) -\u003e usize;\n}\n\nimpl From\u003c\u0026CommandBuilder\u003e for std::process::Command;\n```\n\n## Description\n\n`command_limits` provides a `CommandLimits` type specifying typical limits on the\nsize or number of command arguments and environment variables, and a `CommandBuilder`\nwhich uses it to provide a fallible interface for specifying them.\n\nThis allows for the reliable creation of long command lines across different platforms,\nwithout the need to shell out to `xargs(1)`.\n\n## Example\n\nTypical use is similar to that of `std::process::Command`, but with fallible methods\nfor specifying arguments and environment variables:\n\n```rust\nuse command_limits::CommandBuilder;\n\nlet mut cmd = CommandBuilder::new(\"echo\")?;\ncmd.arg(\"hello, world\")?.env(\"PATH\", \"/bin\")?;\ncmd.into_command().spawn()?;\n```\n\nBy executing `arg()` or `args()` until `Error::TooMany` or `Error::InsufficientSpace`\nis returned, an application can execute as long of a command as should be reasonably\nexpected to fit in the current environment.\n\n`Error::TooLarge` indicates the argument or environment variable exceeds maximal limits\nand cannot be specified even in principle.\n\nHere we use `CommandBuilder` to echo the contents of a vec in as few calls as possible.\n\n```rust\nfn echo_vec(items: Vec\u003cString\u003e) -\u003e Result\u003cdyn Error\u003e {\n    let base = CommandBuilder::new(\"/bin/echo\")?;\n    let mut cmd = base.clone();\n\n    for arg in items {\n        match cmd.arg(arg) {\n            Ok(_) =\u003e continue,\n            Err(Error::TooLarge) =\u003e continue,\n            Err(_) =\u003e {\n                cmd.into_command().status()?;\n                cmd = base.clone();\n            }\n        }\n    }\n\n    cmd.into_command().status()?;\n    Ok(());\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreaky%2Fcommand-limits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreaky%2Fcommand-limits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreaky%2Fcommand-limits/lists"}