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
/*!
`interactive_clap::ToCli` derive
This module describes the derive logic of `#cli_name` struct used as `CliVariant` in
implementation of `interactive_clap::ToCli`, which happens during derive of [`crate::InteractiveClap`] for `#name` struct.
```rust,ignore
#[derive(Debug, Default, Clone, clap::Parser, interactive_clap::ToCliArgs)]
#[clap(author, version, about, long_about = None)]
pub struct #cli_name {
#( #cli_fields, )*
}
impl interactive_clap::ToCli for #name {
type CliVariant = #cli_name;
}
```
Where `interactive_clap::ToCli` is:
```rust,ignore
pub trait ToCli {
type CliVariant;
}
```
Additionally a [`clap::Parser`](https://docs.rs/clap/4.5.24/clap/trait.Parser.html) adapter
for `#name` and `From<#name> for #cli_name` conversion are defined:
```rust,ignore
impl #name {
pub fn try_parse() -> Result<#cli_name, clap::Error> {
<#cli_name as clap::Parser>::try_parse()
}
pub fn parse() -> #cli_name {
<#cli_name as clap::Parser>::parse()
}
pub fn try_parse_from<I, T>(itr: I) -> Result<#cli_name, clap::Error>
where
I: ::std::iter::IntoIterator<Item = T>,
T: ::std::convert::Into<::std::ffi::OsString> + ::std::clone::Clone,
{
<#cli_name as clap::Parser>::try_parse_from(itr)
}
}
impl From<#name> for #cli_name {
fn from(args: #name) -> Self {
Self {
#( #fields_conversion, )*
}
}
}
```
*/
use TokenStream;
use quote;
/// returns the whole result `TokenStream` of derive logic of containing module
/// describes derive of `#cli_name` struct based on input `#name` struct
pub
/// describes logic of derive of [`clap::Parser`](https://docs.rs/clap/4.5.24/clap/trait.Parser.html) adapter
/// for `#name` struct, which returns instances of `#cli_name` struct
/// describes the derive of `impl From<#name> for #cli_name`