1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//! `command_error` provides the [`CommandExt`] trait, which runs a command and checks its exit
//! status:
//!
//! ```
//! # use indoc::indoc;
//! use std::process::Command;
//! use command_error::CommandExt;
//!
//! let err = Command::new("sh")
//! .args(["-c", "echo puppy; false"])
//! .output_checked_utf8()
//! .unwrap_err();
//!
//! assert_eq!(
//! err.to_string(),
//! indoc!(
//! "`sh` failed: exit status: 1
//! Command failed: `sh -c 'echo puppy; false'`
//! Stdout:
//! puppy"
//! )
//! );
//! ```
//!
//! Error messages are detailed and helpful. Additional methods are provided for overriding
//! the default success logic (for that weird tool that thinks `2` is a reasonable exit code) and
//! for transforming the output (for example, to parse command output as JSON while retaining
//! information about the command that produced the output in the error message).
//!
//! ## Enforcing use of `command_error`
//!
//! If you'd like to make sure that [`CommandExt`] methods are used instead of the plain
//! [`Command`] methods in your project, you can add a stanza like this to
//! [`clippy.toml`][clippy-config] at your project root:
//!
//! ```toml
//! [[disallowed-methods]]
//! path = "std::process::Command::output"
//! reason = "Use command_error::CommandExt::output_checked[_with][_utf8]"
//!
//! [[disallowed-methods]]
//! path = "std::process::Command::status"
//! reason = "Use command_error::CommandExt::status_checked[_with]"
//!
//! [[disallowed-methods]]
//! path = "std::process::Command::spawn"
//! reason = "Use command_error::CommandExt::spawn_checked"
//!
//! [[disallowed-methods]]
//! path = "std::process::Child::try_wait"
//! reason = "Use command_error::ChildExt::try_wait_checked[_with]"
//!
//! [[disallowed-methods]]
//! path = "std::process::Child::wait"
//! reason = "Use command_error::ChildExt::wait_checked[_with]"
//!
//! [[disallowed-methods]]
//! path = "std::process::Child::wait_with_output"
//! reason = "Use command_error::ChildExt::output_checked[_with][_utf8]"
//! ```
//!
//! [clippy-config]: https://doc.rust-lang.org/clippy/configuration.html
use Command;
pub use OutputContext;
pub use TryWaitContext;
pub use ChildContext;
pub use OutputLike;
pub use ExecError;
pub use OutputError;
pub use OutputConversionError;
pub use WaitError;
pub use Error;
pub use CommandDisplay;
pub use Utf8ProgramAndArgs;
pub use DebugDisplay;
pub use CommandExt;
pub use ChildExt;