{"id":22297497,"url":"https://github.com/rustonaut/checked-command","last_synced_at":"2025-07-23T21:04:22.400Z","repository":{"id":57548886,"uuid":"90323746","full_name":"rustonaut/checked-command","owner":"rustonaut","description":"extension to `std::process::Command` which adds a output/status considering the programs `ExitStatus` when returning a Result","archived":false,"fork":false,"pushed_at":"2021-04-20T18:42:13.000Z","size":251,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"nightly","last_synced_at":"2025-07-03T00:57:27.194Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rustonaut.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-05T01:14:24.000Z","updated_at":"2023-09-01T22:46:56.000Z","dependencies_parsed_at":"2022-08-30T09:40:56.492Z","dependency_job_id":null,"html_url":"https://github.com/rustonaut/checked-command","commit_stats":null,"previous_names":["dathinab/checked-command"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/rustonaut/checked-command","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustonaut%2Fchecked-command","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustonaut%2Fchecked-command/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustonaut%2Fchecked-command/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustonaut%2Fchecked-command/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rustonaut","download_url":"https://codeload.github.com/rustonaut/checked-command/tar.gz/refs/heads/nightly","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustonaut%2Fchecked-command/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266747800,"owners_count":23978104,"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-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":[],"created_at":"2024-12-03T17:49:57.813Z","updated_at":"2025-07-23T21:04:22.315Z","avatar_url":"https://github.com/rustonaut.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# mapped-command\n\n*Version 0.2.x is a very thin wrapper to `std::process::Command` and can be found here: [in the 0.2 branch](https://github.com/rustonaut/checked-command/tree/0.2)*\n\nProvides an alternative to rust's `std::process::Command` which is more testable, flexible and prevents the way to easy class of bugs where the programmer forgets to check the exit\nstatus of a process as intuition tels us a \"failed command\" should return a error. (But the\nerror in `std::process::Command` is about failing to launch a sub-process and doesn't care\nabout exit codes at all).\n\nFor now this is focused on cases which wait until the subprocess is completed\nand then map the output (or do not care about the output).\n\nCurrently this type contains following features:\n\n- by default check the exit status\n\n- bundle a mapping of the captured stdout/stderr to an result into the command,\n  i.e. the `Command` type is `Command\u003cOutput, Error\u003e` e.g. `Command\u003cVec\u003cString\u003e, Error\u003e`.\n\n- implicitly define if stdout/stderr needs to be captured to prevent mistakes\n  wrt. this, this is done through through the same mechanism which is used to\n  define how the output is mapped, e.g. `Command::new(\"ls\", ReturnStdoutString)`\n  will implicitly enabled stdout capturing and disable `stderr` capturing.\n\n- allow replacing command execution with an callback, this is mainly used to\n  allow mocking the command.\n\n- besides allowing to decide weather the sub-process should inherit the environment and\n  which variables get removed/set/overwritten this type also allows you to whitelist which\n  env variables should be inherited.\n\n- do not have `\u0026mut self` pass through based API. This makes it more bothersome to create\n  functions which create and return commands, which this types intents to make simple so\n  that you can e.g. have a function like `fn ls_command() -\u003e Command\u003cVec\u003cString\u003e, Error\u003e`\n  which returns a command which if run runs the ls command and returns a vector of string\n  (or an error if spawning, running or utf8 validation fails).\n\n- be generic over Output and Error type but dynamic over how the captured stdout/err is\n  mapped to the given `Result\u003cOutput, Error\u003e`. This allows you to e.g. at runtime switch\n  between different function which create a command with the same output but on different\n  ways (i.e. with different called programs and output mapping, e.g. based on a config\n  setting).\n\n# Mini Example\n\nUse `cargo run --example readme` to run this:\n\n```rust\nuse mapped_command::{Command, CommandExecutionWithStringOutputError as Error, MapStdoutString};\n\nfn ls_command() -\u003e Command\u003cVec\u003cString\u003e, Error\u003e {\n    Command::new(\n        \"ls\",\n        MapStdoutString(|out| {\n            let lines = out.lines().map(Into::into).collect::\u003cVec\u003c_\u003e\u003e();\n            Ok(lines)\n        }),\n    )\n}\n\nfn main() {\n    let entries = ls_command().run().unwrap();\n    println!(\"ls:\");\n    for entry in entries {\n        println!(\"\\t{}\", entry);\n    }\n}\n```\n\nFor other examples e.g. about how the mocking works take a look at the [examples dir](./examples/) or the module level documentation produced by rustdoc which likely should be hosted [on docs.rs](https://docs.rs/mapped-command). Be aware that the link leads to the latest released version and might as such be out of sync if updates have not yet been released.\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustonaut%2Fchecked-command","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frustonaut%2Fchecked-command","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustonaut%2Fchecked-command/lists"}