aboutsummaryrefslogtreecommitdiff
path: root/mingling/src/example_docs.rs
blob: bb65280236e4bb55c23384f4389bd08095cbd35f (plain) (blame)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
// Auto generated

/// `Mingling` Example - Async
///
///  After enabling the `async` feature:
///  1. The `chain!` macro will support using **async** functions,
///  2. The `exec` function of `Program` will return a `Future` for you to use with an async runtime
///
///  ## Enable Feature
///  Enable the `async` feature for mingling in `Cargo.toml`
///  ```toml
///  [dependencies]
///  mingling = { version = "...", features = ["async"] }
///  ```
///
///  # How to Run
///  ```bash
///  cargo run --manifest-path ./examples/example-async/Cargo.toml -- hello World
///  ```
///
/// Cargo.toml
/// ```ignore
/// [package]
/// name = "example-async"
/// version = "0.0.1"
/// edition = "2024"
///
/// [dependencies]
/// tokio = { version = "1", features = ["full"] }
/// mingling = { path = "../../mingling", features = ["async"] }
/// ```
///
/// main.rs
/// ```ignore
/// use mingling::prelude::*;
///
/// dispatcher!("hello", HelloCommand => HelloEntry);
///
/// // Use Tokio async runtime
/// #[tokio::main]
/// async fn main() {
///     let mut program = ThisProgram::new();
///     program.with_dispatcher(HelloCommand);
///
///     // Run program
///     program.exec().await;
/// }
///
/// pack!(Hello = String);
///
/// // You can freely use async / non-async functions to declare your Chain
///
/// #[chain]
/// // fn parse_name(prev: HelloEntry) -> Next {
/// async fn parse_name(prev: HelloEntry) -> Next {
///     let name = prev.first().cloned().unwrap_or_else(|| "World".to_string());
///     Hello::new(name).to_render()
/// }
///
/// // For renderers, you can still only use synchronous functions
/// #[renderer]
/// fn render_hello_who(prev: Hello) {
///     r_println!("Hello, {}!", *prev);
/// }
///
/// gen_program!();
/// ```
pub mod example_async {}
/// `Mingling` Example - Basic
///
///  # How to Run
///  ```bash
///  cargo run --manifest-path ./examples/example-basic/Cargo.toml -- hello World
///  ```
///
/// Cargo.toml
/// ```ignore
/// [package]
/// name = "example-basic"
/// version = "0.0.1"
/// edition = "2024"
///
/// [dependencies]
/// mingling = { path = "../../mingling" }
/// ```
///
/// main.rs
/// ```ignore
/// use mingling::prelude::*;
///
/// // Define dispatcher `HelloCommand`, directing subcommand "hello" to `HelloEntry`
/// dispatcher!("hello", HelloCommand => HelloEntry);
///
/// fn main() {
///     // Create program
///     let mut program = ThisProgram::new();
///
///     // Add dispatcher `HelloCommand`
///     program.with_dispatcher(HelloCommand);
///
///     // Run program
///     program.exec();
/// }
///
/// // Register wrapper type `Hello`, setting inner to `String`
/// pack!(Hello = String);
///
/// // Register chain to `ThisProgram`, handling logic from `HelloEntry`
/// #[chain]
/// fn parse_name(prev: HelloEntry) -> Next {
///     // Extract string from `HelloEntry` as argument
///     let name = prev.first().cloned().unwrap_or_else(|| "World".to_string());
///
///     // Build `Hello` type and route to renderer
///     Hello::new(name).to_render()
/// }
///
/// // Register renderer to `ThisProgram`, handling rendering of `Hello`
/// #[renderer]
/// fn render_hello_who(prev: Hello) {
///     // Print message
///     r_println!("Hello, {}!", *prev);
///
///     // Program ends here
/// }
///
/// // Generate program, default is `ThisProgram`
/// gen_program!();
/// ```
pub mod example_basic {}
/// `Mingling` Example - Completion
///
///  # How to Deploy
///  1. Enable the `comp` feature
///  ```toml
///  [dependencies]
///  mingling = { version = "...", features = [
///      "comp",  // Enable this feature
///      "parser"
///  ] }
///  ```
///
///  2. Add `mingling` as a build dependency, enabling the `builds` and `comp` features
///  ```toml
///  [build-dependencies]
///  mingling = { version = "...", features = [
///      "builds", // Enable this feature for build scripts
///      "comp"
///  ] }
///  ```
///
///  3. Write `build.rs` to generate completion scripts at compile time
///  ```ignore
///  use mingling::build::{build_comp_scripts, build_comp_scripts_with_bin_name};
///  fn main() {
///      // Generate completion scripts for the current program, using the Cargo package name as the binary filename
///      build_comp_scripts(env!("CARGO_PKG_NAME")).unwrap();
///
///      // Or, explicitly specify the binary filename
///      // build_comp_scripts("your_bin").unwrap();
///  }
///  ```
///
///  4. Write `main.rs`, adding completion logic for your command entry point
///  5. Execute `cargo install --path ./`, then run the corresponding completion script in your shell
///
/// Cargo.toml
/// ```ignore
/// [package]
/// name = "example-completion"
/// version = "0.0.1"
/// edition = "2024"
///
/// [dependencies]
/// mingling = { path = "../../mingling", features = ["comp", "parser"] }
/// ```
///
/// main.rs
/// ```ignore
/// use mingling::prelude::*;
/// use mingling::{
///     macros::{suggest, suggest_enum},
///     parser::{PickableEnum, Picker},
///     EnumTag, Groupped, ShellContext, Suggest,
/// };
///
/// // Define dispatcher `FruitCommand`, directing subcommand "fruit" to `FruitEntry`
/// dispatcher!("fruit", FruitCommand => FruitEntry);
///
/// #[completion(FruitEntry)]
/// fn comp_fruit_command(ctx: &ShellContext) -> Suggest {
///     if ctx.filling_argument_first("--name") {
///         return suggest!();
///     }
///     if ctx.filling_argument_first("--type") {
///         return suggest_enum!(FruitType);
///     }
///     if ctx.typing_argument() {
///         return suggest! {
///             "--name": "Fruit name",
///             "--type": "Fruit type"
///         }
///         .strip_typed_argument(ctx);
///     }
///     return suggest!();
/// }
///
/// fn main() {
///     let mut program = ThisProgram::new();
///     program.with_dispatcher(CompletionDispatcher);
///     program.with_dispatcher(FruitCommand);
///     program.exec();
/// }
///
/// #[derive(Groupped)]
/// struct FruitInfo {
///     name: String,
///     fruit_type: FruitType,
/// }
///
/// #[derive(Default, Debug, EnumTag)]
/// enum FruitType {
///     #[enum_desc("It's Apple")]
///     #[enum_rename("apple")]
///     FruitApple,
///
///     #[enum_desc("It's Banana")]
///     #[enum_rename("banana")]
///     FruitBanana,
///
///     #[enum_desc("It's Cherry")]
///     #[enum_rename("cherry")]
///     FruitCherry,
///
///     #[enum_desc("It's Date")]
///     #[enum_rename("date")]
///     FruitDate,
///
///     #[enum_desc("It's Elderberry")]
///     #[enum_rename("elderberry")]
///     FruitElderberry,
///
///     #[default]
///     #[enum_rename("unknown")]
///     Unknown,
/// }
///
/// impl PickableEnum for FruitType {}
///
/// #[chain]
/// fn parse_fruit_info(prev: FruitEntry) -> Next {
///     let picker = Picker::from(prev.inner);
///     let (fruit_name, fruit_type) = picker.pick("--name").pick("--type").unpack();
///     let info = FruitInfo {
///         name: fruit_name,
///         fruit_type,
///     };
///     info.to_render()
/// }
///
/// #[renderer]
/// fn render_fruit(prev: FruitInfo) {
///     match (prev.name.is_empty(), prev.fruit_type) {
///         (true, FruitType::Unknown) => {
///             r_println!("Fruit name is empty and type is unknown");
///         }
///         (true, fruit_type) => {
///             r_println!("Fruit name is empty, Type: {:?}", fruit_type);
///         }
///         (false, FruitType::Unknown) => {
///             r_println!("Fruit name: {}, Type is unknown", prev.name);
///         }
///         (false, fruit_type) => {
///             r_println!("Fruit name: {}, Type: {:?}", prev.name, fruit_type);
///         }
///     }
/// }
///
/// gen_program!();
/// ```
pub mod example_completion {}
/// `Mingling` Example - Dispatch Tree
///
///  # How to Deploy
///  1. Enable the `dispatch_tree` feature (`comp` is optional)
///  ```toml
///  mingling = { version = "...", features = [
///      "dispatch_tree",  // Enable this feature
///      "comp" // optional
///  ] }
///  ```
///
///  2. Using `cargo expand`:
///
///  ```bash
///  cargo expand --manifest-path examples/example-dispatch-tree/Cargo.toml > expanded.rs
///  cat expanded.rs
///  ```
///
/// Cargo.toml
/// ```ignore
/// [package]
/// name = "example-dispatch-tree"
/// version = "0.1.0"
/// edition = "2024"
///
/// [dependencies]
/// mingling = { path = "../../mingling", features = ["dispatch_tree", "comp"] }
/// ```
///
/// main.rs
/// ```ignore
/// #![allow(unused_mut)]
///
/// use mingling::prelude::*;
///
/// fn main() {
///     let mut program = ThisProgram::new();
///
///     // // After enabling `dispatch_tree`, this method will no longer exist
///     // program.with_dispatcher(CommandGreet);
///     //
///     // // The `CompletionDispatcher` automatically generated by `comp` will also be imported automatically
///     // program.with_dispatcher(CompletionDispatcher);
///
///     program.exec();
/// }
///
/// dispatcher!("greet", CommandGreet => EntryGreet);
/// dispatcher!("help", CommandHelp => EntryHelp);
/// dispatcher!("quit", CommandQuit => EntryQuit);
/// dispatcher!("list", CommandList => EntryList);
/// dispatcher!("status", CommandStatus => EntryStatus);
/// dispatcher!("save", CommandSave => EntrySave);
/// dispatcher!("load", CommandLoad => EntryLoad);
/// dispatcher!("config", CommandConfig => EntryConfig);
/// dispatcher!("run", CommandRun => EntryRun);
/// dispatcher!("debug", CommandDebug => EntryDebug);
/// dispatcher!("version", CommandVersion => EntryVersion);
///
/// gen_program!();
/// ```
pub mod example_dispatch_tree {}
/// `Mingling` Example - Exit Code
///
///  This example demonstrates how to modify the program's exit code using `ExitCodeSetup`.
///  By default, the program exits with code 0. This example shows:
///  1. Using `dispatcher!` to define an error command,
///  2. Using `chain!` to handle errors and set a custom exit code via `ProgramExitCode`,
///  3. Using `renderer!` to print an error message.
///
///  # How to Run
///  ```bash
///  cargo run --manifest-path ./examples/example-exit-code/Cargo.toml -- error
///  ```
///
/// Cargo.toml
/// ```ignore
/// [package]
/// name = "example-exit-code"
/// version = "0.1.0"
/// edition = "2024"
///
/// [dependencies]
/// mingling = { path = "../../mingling" }
/// ```
///
/// main.rs
/// ```ignore
/// use mingling::prelude::*;
/// use mingling::{res::ExitCode, setup::ExitCodeSetup};
///
/// fn main() {
///     let mut program = ThisProgram::new();
///     program.with_dispatcher(ErrorCommand);
///     program.with_setup(ExitCodeSetup::<ThisProgram>::default());
///     program.exec_and_exit();
/// }
///
/// dispatcher!("error", ErrorCommand => ErrorEntry);
/// pack!(ResultError = ());
///
/// #[chain]
/// fn handle_error_entry(_prev: ErrorEntry, ec: &mut ExitCode) -> Next {
///     ec.exit_code = 1;
///     return ResultError::default();
/// }
///
/// #[renderer]
/// fn render_error(_prev: ResultError, ec: &ExitCode) {
///     r_println!("Exit with exit code: {}", ec.exit_code);
/// }
///
/// gen_program!();
/// ```
pub mod example_exit_code {}
/// `Mingling` Example - General Renderer
///
///  ## Step1 - Enable Feature
///  Enable the `general_renderer` feature for mingling in `Cargo.toml`
///  ```toml
///  [dependencies]
///  mingling = { version = "...", features = ["general_renderer", "parser"] }
///  ```
///
///  ## Step2 - Add Dependencies
///  Add `serde` dependency to `Cargo.toml` for serialization support
///  ```toml
///  [dependencies]
///  serde = { version = "1", features = ["derive"] }
///  ```
///
///  ## Step3 - Write Code
///  Write the following content into `main.rs`
///
///  ## Step4 - Build and Run
///  ```bash
///  cargo run --manifest-path ./examples/example-general-renderer/Cargo.toml -- render Bob 22
///  cargo run --manifest-path ./examples/example-general-renderer/Cargo.toml -- render Bob 22 --json
///  cargo run --manifest-path ./examples/example-general-renderer/Cargo.toml -- render Bob 22 --yaml
///  ```
///
///  Will print:
///  ```plain
///  Bob is 22 years old
///  {"member_name":"Bob","member_age":22}
///  member_name: Bob
///  member_age: 22
///  ```
///
/// Cargo.toml
/// ```ignore
/// [package]
/// name = "example-general-renderer"
/// version = "0.0.1"
/// edition = "2024"
///
/// [dependencies]
/// mingling = { path = "../../mingling", features = [
///     "parser",
///     "general_renderer",
///     "json_serde_fmt",
///     "yaml_serde_fmt",
/// ] }
/// serde = { version = "1", features = ["derive"] }
/// ```
///
/// main.rs
/// ```ignore
/// use mingling::prelude::*;
/// use mingling::{parser::Picker, setup::GeneralRendererSetup, Groupped};
/// use serde::Serialize;
///
/// dispatcher!("render", RenderCommand => RenderCommandEntry);
///
/// fn main() {
///     let mut program = ThisProgram::new();
///     // Add `GeneralRendererSetup` to receive user input `--json` `--yaml` parameters
///     program.with_setup(GeneralRendererSetup);
///     program.with_dispatcher(RenderCommand);
///     program.exec();
/// }
///
/// // Manually implement Info struct
/// #[derive(Serialize, Groupped)]
/// struct Info {
///     #[serde(rename = "member_name")]
///     name: String,
///     #[serde(rename = "member_age")]
///     age: i32,
/// }
///
/// #[chain]
/// fn parse_render(prev: RenderCommandEntry) -> Next {
///     let (name, age) = Picker::new(prev.inner)
///         .pick::<String>(())
///         .pick::<i32>(())
///         .unpack();
///     Info { name, age }.to_render()
/// }
///
/// // Implement default renderer for when general_renderer is not specified
/// #[renderer]
/// fn render_info(prev: Info) {
///     r_println!("{} is {} years old", prev.name, prev.age);
/// }
///
/// gen_program!();
/// ```
pub mod example_general_renderer {}
/// `Mingling` Example - Picker
///
///  ## Step1 - Enable Feature
///  Enable the `parser` feature for mingling in `Cargo.toml`
///  ```toml
///  [dependencies]
///  mingling = { version = "...", features = ["parser"] }
///  ```
///
///  ## Step2 - Write Code
///  Write the following content into `main.rs`
///
///  ## Step3 - Build and Run
///  ```bash
///  cargo run --manifest-path ./examples/example-picker/Cargo.toml -- pick Bob
///  cargo run --manifest-path ./examples/example-picker/Cargo.toml -- pick Bob --age -15
///  cargo run --manifest-path ./examples/example-picker/Cargo.toml -- pick --age 99
///  ```
///
/// Cargo.toml
/// ```ignore
/// [package]
/// name = "example-picker"
/// version = "0.0.1"
/// edition = "2024"
///
/// [dependencies]
/// mingling = { path = "../../mingling", features = ["parser"] }
/// tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }
/// ```
///
/// main.rs
/// ```ignore
/// use mingling::prelude::*;
///
/// dispatcher!("pick", PickCommand => PickEntry);
///
/// fn main() {
///     let mut program = ThisProgram::new();
///     program.with_dispatcher(PickCommand);
///     program.exec();
/// }
///
/// pack!(NoNameProvided = ());
/// pack!(ParsedPickInput = (i32, String));
///
/// #[chain]
/// fn parse(prev: PickEntry) -> Next {
///     let picked = prev
///         // First extract the named argument
///         .pick_or("--age", 20)
///         .after(|n: i32| n.clamp(0, 100))
///         // Then sequentially extract the remaining arguments
///         .pick_or_route((), NoNameProvided::default().to_render())
///         .unpack();
///
///     match picked {
///         Ok(value) => ParsedPickInput::new(value).to_render(),
///         Err(e) => e,
///     }
/// }
///
/// #[renderer]
/// fn render_parsed_pick_input(prev: ParsedPickInput) {
///     let (age, name) = prev.inner;
///     r_println!("Picked: name = {}, age = {}", name, age);
/// }
///
/// #[renderer]
/// fn render_no_name_input(_prev: NoNameProvided) {
///     r_println!("No name provided.");
/// }
///
/// gen_program!();
/// ```
pub mod example_picker {}

///
/// Cargo.toml
/// ```ignore
/// [package]
/// name = "example-repl"
/// version = "0.0.1"
/// edition = "2024"
///
/// [dependencies]
/// mingling = { path = "../../mingling", features = ["repl", "parser"] }
/// just_fmt = "0.1.2"
/// ```
///
/// main.rs
/// ```ignore
/// use mingling::{
///     REPL,
///     hook::ProgramHook,
///     prelude::*,
///     setup::{BasicREPLOutputSetup, BasicREPLPromptSetup, BasicREPLReadlineSetup},
///     this,
/// };
/// use std::{env::current_dir, path::PathBuf};
///
/// // Resource to store the current directory
/// #[derive(Clone)]
/// struct CurrentDir {
///     dir: PathBuf,
/// }
///
/// impl Default for CurrentDir {
///     fn default() -> Self {
///         Self {
///             dir: current_dir().unwrap(),
///         }
///     }
/// }
///
/// fn main() {
///     let mut program = ThisProgram::new();
///
///     // Add resource
///     program.with_resource(CurrentDir::default());
///
///     // Add dispatchers
///     program.with_dispatcher(ChangeDirectoryCommand);
///     program.with_dispatcher(ListCommand);
///     program.with_dispatcher(ExitCommand);
///     program.with_dispatcher(ClearCommand);
///
///     // Add setups
///     program.with_setup(BasicREPLReadlineSetup);
///     program.with_setup(BasicREPLOutputSetup);
///     program.with_setup(BasicREPLPromptSetup::func(|| {
///         let res = this::<ThisProgram>().res::<CurrentDir>().unwrap();
///         let dir_str: String = res.dir.to_string_lossy().into();
///         let prompt = format!(
///             "{}> ",
///             dir_str
///                 .replace(&['/', '\\'][..], ">")
///                 .trim_start_matches('>')
///                 .trim_end_matches('>')
///         );
///         prompt
///     }));
///
///     // Add hooks to handle REPL-related events
///     program.with_hook(ProgramHook::empty().on_repl_begin(|| {
///         // Print welcome message
///         println!("Welcome!")
///     }));
///
///     // Start the REPL loop
///     program.exec_repl();
/// }
///
/// // Create error route
/// pack!(ErrorDirectoryNotExist = PathBuf);
///
/// // Create commands: cd ls exit
/// dispatcher!("cd", ChangeDirectoryCommand => ChangeDirectoryEntry);
/// dispatcher!("ls", ListCommand => ListEntry);
/// dispatcher!("exit", ExitCommand => ExitEntry);
/// dispatcher!("clear", ClearCommand => ClearEntry);
///
/// // Define data needed for the cd command's execution phase
/// pack!(StateChangeDirectory = String);
///
/// // Define data needed for the ls command's rendering phase
/// pack!(ResultList = Vec<String>);
///
/// // Parse cd command arguments
/// #[chain]
/// fn parse_cd_args(prev: ChangeDirectoryEntry) -> Next {
///     let join = prev.pick(()).unpack();
///     StateChangeDirectory::new(join)
/// }
///
/// // Execute directory change
/// #[chain]
/// fn handle_cd(prev: StateChangeDirectory, current_dir: &mut CurrentDir) -> Next {
///     let join = prev.inner;
///     let new_dir = just_fmt::fmt_path::fmt_path(current_dir.dir.join(join)).unwrap_or_default();
///
///     // If the path is not found, route to error handling
///     if !new_dir.exists() {
///         return ErrorDirectoryNotExist::new(new_dir).to_render();
///     }
///
///     current_dir.dir = new_dir;
///     empty_result!()
/// }
///
/// // Get directory contents via the CurrentDir resource
/// #[chain]
/// fn handle_ls(_prev: ListEntry, current_dir: &CurrentDir) -> Next {
///     let dir = &current_dir.dir;
///     let entries: Vec<String> = std::fs::read_dir(dir)
///         .into_iter()
///         .flat_map(|rd| rd.filter_map(|e| e.ok()))
///         .map(|e| {
///             let name = e.file_name().to_string_lossy().to_string();
///             if e.file_type().map(|t| t.is_dir()).unwrap_or(false) {
///                 format!("{}/", name)
///             } else {
///                 name
///             }
///         })
///         .collect();
///
///     // Render ResultList
///     ResultList::new(entries).to_render()
/// }
///
/// // Render ResultList data
/// #[renderer]
/// fn render_list(list: ResultList) {
///     for item in list.inner {
///         r_println!("{}", item)
///     }
/// }
///
/// // Handle exit command event
/// #[chain]
/// fn handle_exit(
///     _prev: ExitEntry,
///     repl: &mut REPL, // Import REPL resource, registered in `exec_repl`, usable directly
/// ) {
///     // Set the REPL exit flag; REPL will exit after this loop iteration
///     repl.exit = true;
/// }
///
/// // Handle clear command event
/// #[chain]
/// fn handle_clear(_prev: ClearEntry) {
///     // Clear the terminal screen
///     print!("\x1B[2J\x1B[1;1H");
/// }
///
/// // Handle path not found event
/// #[renderer]
/// fn render_error_directory_not_exist(err: ErrorDirectoryNotExist) {
///     r_println!("Directory not found: {}", err.inner.display())
/// }
///
/// // Handle dispatcher not found event
/// #[renderer]
/// fn dispatcher_not_found(prev: DispatcherNotFound) {
///     r_println!("Command not found: \"{}\"", prev.join(", "))
/// }
///
/// gen_program!();
/// ```
pub mod example_repl {}
/// `Mingling` Example - Global Resource Injection
///
///  This example demonstrates how to use global resource injection in `#[chain]` functions.
///  You can inject both immutable (`&T`) and mutable (`&mut T`) references to global resources.
///
///  # How to Run
///  ```bash
///  cargo run --manifest-path ./examples/example-resources/Cargo.toml -- setup
///  ```
///
/// Cargo.toml
/// ```ignore
/// [package]
/// name = "example-resources"
/// version = "0.0.1"
/// edition = "2024"
///
/// [dependencies]
/// mingling = { path = "../../mingling", features = ["parser"] }
/// ```
///
/// main.rs
/// ```ignore
/// use mingling::prelude::*;
/// use std::{env::current_dir, path::PathBuf};
///
/// // Define a resource for storing global state
/// #[derive(Default, Clone)]
/// pub struct MyResource {
///     current_dir: PathBuf,
/// }
///
/// fn main() {
///     let mut program = ThisProgram::new();
///
///     // Add the resource to the program
///     program.with_resource(MyResource::default());
///
///     program.with_dispatcher(SetupCommand);
///     program.exec_and_exit();
/// }
///
/// dispatcher!("setup", SetupCommand => SetupEntry);
/// pack!(StateRead = ());
/// pack!(ResultCurrentDir = PathBuf);
///
/// #[chain]
/// fn setup(
///     _prev: SetupEntry,
///     resource: &mut MyResource, // Import the resource into `setup`
/// ) -> Next {
///     // Set the global resource
///     resource.current_dir = current_dir().unwrap();
///
///     StateRead::default()
/// }
///
/// #[chain]
/// fn read(_prev: StateRead, resource: &MyResource) -> Next {
///     // Read the global resource
///     let current_dir = resource.current_dir.clone();
///     ResultCurrentDir::new(current_dir).to_render()
/// }
///
/// #[renderer]
/// fn render_current_dir(dir: ResultCurrentDir) {
///     r_println!("Current dir: {}", dir.to_string_lossy())
/// }
///
/// gen_program!();
/// ```
pub mod example_resources {}