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
// use super::flag::RFlag;
// use super::Flag;
// use clier_parser::Argv;
// // use proc_macro::TokenStream;
// // use syn::{self, parse_macro_input, Data, Fields, Ident};
// /// Handler
// pub type Handler = fn(args: CmdArgs) -> i32;
// /// The CmdArgs struct that is passed to all command handlers.
// #[derive(Debug, Clone)]
// pub struct CmdArgs {
// /// struct 'Argv' contains parsed flags and commands.
// pub args: Argv,
// /// Registered flags for the command by the struct 'Command::flag'.
// pub registered_flags: Vec<(String, Flag)>
// }
// #[derive(Debug, Clone, PartialEq)]
// pub(crate) struct RunnableCommand {
// /// The function to run command.
// pub handler: Handler,
// // /// Usage of the command. Displayed in help.
// // pub usage: Option<String>,
// /// Registered Flags that are required for command to run. Passed down with [crate::hooks::use_flags] hook.
// pub flags: Option<Vec<RFlag>>,
// /// The description of the command.
// pub description: String // / Subcommands of the command.
// // pub children: Option<Vec<RCommand>>,
// }
// /// The Command struct to initialize a new command.
// /// ## Non-complete example:
// /// ```rust
// /// use clier::builder::{RCommand, Flag};
// ///
// /// let command = RCommand::new(
// /// /* command name: */ "command",
// /// /* description: */ "description",
// /// /* handler: */ |_args| {
// /// /* Your logic */
// /// 0 // <-- i32: Exit Code of program, success = 0
// /// })
// /// .flag("flag-name", Some('f'), "flag description" /* <-- In help */);
// /// ```
// /// Alot of these properties/builder methods are no necesserialy required, but are usefull for the user in the help output.
// #[derive(Debug, Clone)]
// pub struct RCommand {
// /// Name
// pub name: String,
// /// The function to run command.
// pub handler: Handler,
// // / Usage of the command. Displayed in help.
// // pub usage: Option<String>,
// /// Registered Flags that are required for command to run. Passed down with [crate::hooks::use_flags] hook.
// pub flags: Option<Vec<RFlag>>,
// /// The description of the command.
// pub description: String,
// /// Subcommands of the command.
// pub children: Option<Vec<RCommand>>
// }
// impl RCommand {
// /// The Command struct to initialize a new command.
// /// ## Non-complete example:
// /// ```rust
// /// use clier::builder::{RCommand, Flag};
// ///
// /// let command = RCommand::new(
// /// /* command name: */ "command",
// /// /* description: */ "description",
// /// /* handler: */ |_args| {
// /// /* Your logic */
// /// 0 // <-- i32: Exit Code of program, success = 0
// /// })
// /// .flag("flag-name", Some('f'), "flag description" /* <-- In help */);
// /// ```
// /// Alot of these properties/builder methods are no necesserialy required, but are usefull for the user in the help output.
// /// # Panics
// /// Panics if name contains a dot, internal reasons.
// pub fn new(name: &str, description: &str, handler: Handler) -> Self {
// let name_contains_dot = !name.contains('.');
// assert!(name_contains_dot);
// Self {
// name: name.to_string(),
// description: description.to_string(),
// flags: None,
// // usage: None,
// handler,
// children: None
// }
// }
// /// Adds a flag to [RCommand]
// pub fn flag(mut self, name: &str, short: Option<char>, description: &str) -> Self {
// let mut flags = self.flags.unwrap_or_default();
// let mut flag = RFlag::new(name, description.to_string());
// if let Some(short) = short {
// flag = flag.short(short);
// }
// flags.push(flag);
// self.flags = Some(flags);
// self
// }
// /// It is possible to add subcommands to a command:
// /// ```rust
// /// use clier::builder::{Flag, RCommand};
// ///
// /// let command = RCommand::new(
// /// /* command name: */ "command",
// /// /* description: */ "description",
// /// /* handler: */ |_args| {
// /// /* Your logic */
// /// 0 // <-- i32: Exit Code of program, success = 0
// /// })
// /// .flag("flag-name", Some('t'), "flag description" /* <-- In help */);
// ///
// /// command.subcommand(
// /// "subcommand",
// /// "description",
// /// |_args| {
// /// /* Your logic */
// /// 0 // <-- i32: Exit Code of program, success = 0
// /// });
// /// ```
// ///
// /// It has almost the same methods and builder methods as a [RCommand]
// pub fn subcommand(mut self, name: &str, description: &str, handler: Handler) -> Self {
// let new_command = Self::new(name, description, handler);
// // if let Some(usage) = usage {
// // new_command = new_command.usage(usage);
// // }
// let mut children = self.children.unwrap_or_default();
// children.push(new_command);
// self.children = Some(children);
// self
// }
// }