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
//! Procedural macros to derive traits for CLI construction.
//!
//! - [`Container`] for dispatching enums to subcommands.
//! - [`File`] for deserializing values from files, implementing clap's
//! `value_parser`.
use TokenStream;
/// Derive the [`Container`] trait for structs and enums.
///
/// Looks for clap's `#[command]` in structs to generate a `next()` that can
/// dispatch to the next command which was initially parsed. Any structs without
/// `#[command]` will have a `next()` that returns `None`.
///
/// For commands with subcommands, the enum must also have
/// `#[derive(Container)]`.
///
/// # Examples
///
/// ```
/// use cata::Container;
/// use clap::{Parser, Subcommand};
///
/// #[derive(Parser, Container)]
/// pub struct Root {
/// #[command(subcommand)]
/// pub cmd: RootCmd,
/// }
///
/// #[derive(Subcommand, Container)]
/// pub enum RootCmd {
/// Child(Child)
/// }
///
/// #[derive(Parser, Container)]
/// pub struct Child {}
/// ```
///
/// [`Container`]: cata::command::Container
/// Implement value parsing for arbitrary structs deserialized from files.
///
/// Implements the [`ValueParserFactory`] trait for struct which uses the
/// [`File<T>`] value parser to deserialize a path passed in as an argument into
/// the provided struct.
///
/// # Examples
///
/// ```
/// use cata::File;
///
/// #[derive(Clone, Debug, Deserialize)]
/// struct Thing {
/// single: String,
/// }
///
/// #[derive(clap::Parser)]
/// struct Cmd {
/// input: Thing,
/// }
/// ```
///
/// [`Container`]: cata::command::Container
/// [`ValueParserFactory`]: clap::builder::ValueParserFactory