printable_shell_command/
shell_printable.rs

1use std::str::Utf8Error;
2
3use crate::FormattingOptions;
4
5pub trait ShellPrintable {
6    fn printable_invocation_string(&self) -> Result<String, Utf8Error>;
7    // Calls `.to_string_lossy()` on the program name and args.
8    fn printable_invocation_string_lossy(&self) -> String;
9
10    // Print the invocation to `stdout`.`
11    fn print_invocation(&mut self) -> Result<&mut Self, Utf8Error> {
12        println!("{}", self.printable_invocation_string_lossy());
13        Ok(self)
14    }
15    // Print the invocation to `stdout`.`
16    fn print_invocation_lossy(&mut self) -> &mut Self {
17        println!("{}", self.printable_invocation_string_lossy());
18        self
19    }
20}
21
22pub trait ShellPrintableWithOptions {
23    fn printable_invocation_string_with_options(
24        &self,
25        formatting_options: FormattingOptions,
26    ) -> Result<String, Utf8Error>;
27    // Calls `.to_string_lossy()` on the program name and args.
28    fn printable_invocation_string_lossy_with_options(
29        &self,
30        formatting_options: FormattingOptions,
31    ) -> String;
32
33    // Print the invocation to `stdout`.`
34    fn print_invocation_with_options(
35        &mut self,
36        formatting_options: FormattingOptions,
37    ) -> Result<&mut Self, Utf8Error> {
38        println!(
39            "{}",
40            self.printable_invocation_string_lossy_with_options(formatting_options)
41        );
42        Ok(self)
43    }
44    // Print the invocation to `stdout`.`
45    fn print_invocation_lossy_with_options(
46        &mut self,
47        formatting_options: FormattingOptions,
48    ) -> &mut Self {
49        println!(
50            "{}",
51            self.printable_invocation_string_lossy_with_options(formatting_options)
52        );
53        self
54    }
55}