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
//! `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

#![deny(missing_docs)]

#[cfg(doc)]
use std::process::Command;

mod output_context;
pub use output_context::OutputContext;

mod try_wait_context;
pub use try_wait_context::TryWaitContext;

mod child_context;
pub use child_context::ChildContext;

mod output_like;
pub use output_like::OutputLike;

mod exec_error;
pub use exec_error::ExecError;

mod output_error;
pub use output_error::OutputError;

mod output_conversion_error;
pub use output_conversion_error::OutputConversionError;

mod wait_error;
pub use wait_error::WaitError;

mod error;
pub use error::Error;

mod command_display;
pub use command_display::CommandDisplay;

mod utf8_program_and_args;
pub use utf8_program_and_args::Utf8ProgramAndArgs;

mod debug_display;
pub(crate) use debug_display::DebugDisplay;

mod command_ext;
pub use command_ext::CommandExt;

mod child_ext;
pub use child_ext::ChildExt;