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
// ==============================================================
// ==============================================================
//! Utility library for working with ```cli``` output ergonomically.
//!
//! This is not a logging alternative, it's intended to produce output for end user consumption.
//!
//! It handles three levels of verbosity that can be set dynamically at runtime:
//!
//! * Quite - no output
//! * Terse - used to provide minimal user output
//! * Verbose - used to provide elaborated and/or additional user output
//!
//! ### Output Macros
//!
//! * `debug!` - conditionally compiled console debugging output - \[`debug`\]
//!
//! * `report!` - conditional console output according to verbosity level - \[`debug`|`release`\]
//!
//! \* _debug! is intended to be used during application development_
//!
//! \* _all other debugging and telemetry output is most likely better served with a logging library_
//!
//! ### Conditional Code Evaluation
//!
//! * `eval!` - conditional code execution according to verbosity level - \[`debug`|`release`\]
//!
//! * `release!` - conditional code execution according to verbosity level - \[`release`\]
extern crate quote;
extern crate syn;
use TokenStream;
use ToTokens;
/// Conditionally prints to `io::stdout` or evaluates an expression when the code
/// is compiled unoptimized with debug assertions, otherwise does not include
/// the message or expression. _for a message a new line is not appended_
///
/// ## Anatomy of the `debug!` macro
///
/// In order to print to `io:stdout`, `debug!` accepts the same input as the `std`
/// library [`print!`] macro. Otherwise it accepts a valid expression.
///
/// ### Examples
/// * Printing to `io::stdout`
///
/// ```no_run
/// # use::cli_toolbox::debug;
/// debug! { "DBG: debugging information - {}", 42 }
/// ```
///
/// * Evaluating Expression
///
/// ```no_run
/// # use::cli_toolbox::debug;
/// debug! { validate_some_important_such_and_such(); }
/// # fn validate_some_important_such_and_such() {}
/// ```
///
/// ## Panics
///
/// Just like the [`print!`] macros used to write the output, this also panics if
/// writing to `io::stdout` fails.
///
/// [`print!`]: <https://doc.rust-lang.org/std/macro.print.html>
/// Conditionally prints to `io::stdout` when the code is compiled unoptimized
/// with debug assertions, otherwise does not include the message. _a new line is appended_
///
/// ## Anatomy of the `debugln!` macro
///
/// `debug!` accepts the same input as the `std` library [`println!`] macro.
///
/// ### Example
///
/// Printing a line to `io::stdout`
///
/// ```no_run
/// # use::cli_toolbox::debugln;
/// debugln! { "DBG: debugging information - {}", 42 }
/// ```
///
/// ## Panics
///
/// Just like the [`println!`] macros used to write the output, this also panics if
/// writing to `io::stdout` fails.
///
/// [`println!`]: <https://doc.rust-lang.org/std/macro.println.html>
/// Conditionally evaluates expressions when intended verbosity matches active verbosity.
///
/// The `eval` macro uses the [`Verbosity`] crate to determine when and what to evaluate.
///
/// _\* See the [`Verbosity`] crate to learn how to set the verbosity level._
///
/// ## Anatomy of the `eval!` macro
///
/// Input consists of an optional intended verbosity level, defaulting to `terse`
/// if it is not specifically provided. The remainder of the macro input expects
/// an expression and then an optional semicolon terminator.
///
/// ### Examples
///
/// * Evaluates when `default`, which is `terse`
/// ```no_run
/// # use::cli_toolbox::eval;
/// # let bar = 42;
/// eval! { foo(bar); }
/// # fn foo(_value: usize) {}
/// ```
///
/// * Evaluates when `terse`
/// ```no_run
/// # use::cli_toolbox::eval;
/// # let bar = 42;
/// eval! { @terse foo(bar); }
/// # fn foo(_value: usize) {}
/// ```
///
/// * Evaluates when `verbose`
/// ```no_run
/// # use::cli_toolbox::eval;
/// # let bar = 42;
/// eval! { @verbose foo(bar); }
/// # fn foo(_value: usize) {}
/// ```
///
/// [`Verbosity`]: <https://crates.io/crates/verbosity>
/// Conditionally evaluates expressions when intended verbosity matches active verbosity
/// and only when the code is compiled optimized.
///
/// The `release` macro uses the [`Verbosity`] crate to determine when and what to evaluate.
///
/// _\* See the [`Verbosity`] crate to learn how to set the verbosity level._
///
/// ## Anatomy of the `release!` macro
///
/// Input consists of an optional intended verbosity level, defaulting to `terse`
/// if it is not specifically provided. The remainder of the macro input expects
/// an expression and then an optional semicolon terminator.
///
/// ### Examples
///
/// * Evaluates when `default`, which is `terse`
/// ```no_run
/// # use::cli_toolbox::release;
/// # let bar = 42;
/// release! { foo(bar); }
/// # fn foo(_value: usize) {}
/// ```
///
/// * Evaluates when `terse`
/// ```no_run
/// # use::cli_toolbox::release;
/// # let bar = 42;
/// release! { @terse foo(bar); }
/// # fn foo(_value: usize) {}
/// ```
///
/// * Evaluates when `verbose`
/// ```no_run
/// # use::cli_toolbox::release;
/// # let bar = 42;
/// release! { @verbose foo(bar); }
/// # fn foo(_value: usize) {}
/// ```
///
/// [`Verbosity`]: <https://crates.io/crates/verbosity>
/// Conditionally prints to `io::stdout` or `io::stderr` when intended verbosity matches
/// active verbosity,<br/>does not append a new line.
///
///
/// ## Anatomy of the `report!` macro
///
/// Conditionally prints to `io::stdout` or `io::stderr` when intended verbosity matches
/// active verbosity,<br/>appends a new line.
///
///
/// ## Anatomy of the `reportln!` macro
///