pub fn from_slice<'input, T: Facet<'static>>(
args: &'input [&'input str],
) -> Result<T, ArgsErrorWithInput>Expand description
Parse command line arguments into a Facet-compatible type
Examples found in repository?
examples/demo_errors.rs (line 96)
81fn main() {
82 let scenarios = [
83 ("Top-level help", vec!["--help"]),
84 ("Missing required subcommand", vec![]),
85 ("Unknown subcommand", vec!["notacommand"]),
86 ("Subcommand help", vec!["clone", "--help"]),
87 ("Nested subcommand help", vec!["remote", "add", "--help"]),
88 ];
89
90 for (description, args_vec) in &scenarios {
91 println!("\n{}", "=".repeat(80));
92 println!("SCENARIO: {}", description);
93 println!("Args: {:?}", args_vec);
94 println!("{}", "=".repeat(80));
95
96 let result = args::from_slice::<GitArgs>(args_vec);
97 match result {
98 Ok(_) => println!("✓ Successfully parsed arguments"),
99 Err(e) => {
100 let is_help = e.is_help_request();
101 println!(
102 "\n{} {}",
103 if is_help {
104 "ℹ️ Help requested"
105 } else {
106 "❌ Error"
107 },
108 if is_help {
109 "(exit code: 0)"
110 } else {
111 "(exit code: 1)"
112 }
113 );
114 println!("\n{:?}\n", Report::new(e));
115 }
116 }
117 }
118
119 println!("\n{}", "=".repeat(80));
120 println!("Summary:");
121 println!(" • Help requests exit with code 0 and show colored help");
122 println!(" • Errors exit with code 1 and show diagnostic with suggestions");
123 println!(" • Subcommand help works with: <subcommand> --help");
124 println!("{}", "=".repeat(80));
125}