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
// Copyright 2018 David Roundy <roundyd@physics.oregonstate.edu>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![deny(missing_docs)]

//! This crate defines the `ClapMe` trait and its custom derive.
//!
//! To learn to use clapme, you should read [the clapme guide](guide/index.html).

extern crate clap as _clap;
extern crate meval;

#[allow(unused_imports)]
#[macro_use]
extern crate clapme_derive;

#[doc(hidden)]
pub use clapme_derive::*;

use std::str::FromStr;
use std::ffi::OsString;

pub mod guide;

/// Re-export of clap
pub mod clap {
    pub use _clap::*;
}

/// Information needed to set up an argument.
#[derive(Clone)]
pub struct ArgInfo<'a> {
    /// The name of the argument, which is also its long flag.
    pub name: &'a str,
    /// Is the argument required?
    pub required: bool,
    /// Flags that are required by this argument.
    pub required_flags: &'a [&'a str],
    /// Flags that are in conflict with this argument.
    pub conflicted_flags: Vec<String>,
    /// Flag is required unless one of these other flags is present.
    pub required_unless_one: Vec<String>,
    /// Can we repeat the flag?
    pub multiple: bool,
    /// Help string (if any)
    pub help: &'a str,
}

impl<'a> ArgInfo<'a> {
    /// A new `ArgInfo` with sensible defaults.
    pub fn new(name: &'a str) -> Self {
        ArgInfo {
            name: name,
            required: true,
            required_flags: &[],
            multiple: false,
            help: "",
            conflicted_flags: Vec::new(),
            required_unless_one: Vec::new(),
        }
    }
}

/// Any type of trait `ClapMe` can be used as an argument value.
pub trait ClapMe : Sized {
    /// Updates and returns the corresponding `clap::App`.
    fn with_clap<T>(_info: ArgInfo,
                    app: clap::App,
                    f: impl FnOnce(clap::App) -> T) -> T {
        f(app)
    }
    /// Parses the clap info to obtain a value.  `None` is returned if
    /// the argument was not required, and was also not provided.
    fn from_clap(_name: &str, _app: &clap::ArgMatches) -> Option<Self> {
        None
    }
    /// Parses the clap info to obtain a value.  `None` is returned if
    /// the argument was not required, and was also not provided.
    fn requires_flags(name: &str) -> Vec<String> {
        vec![name.to_string()]
    }
    /// The help message for this struct.  This is most useful for
    /// test cases.
    fn help_message(cmdname: &str) -> String {
        let info = ArgInfo::new("");
        Self::with_clap(info, clap::App::new(cmdname),
                        |a| {
                            let mut help_data = Vec::new();
                            a.write_help(&mut help_data).unwrap();
                            String::from_utf8_lossy(&help_data).into_owned()
                        })
    }

    /// Parse command line arguments.
    fn from_args() -> Self {
        Self::with_clap(ArgInfo::new(""),
                        clap::App::new("foo"),
                        |a| {
                            let matches = a.get_matches();
                            Self::from_clap("", &matches).unwrap()
                        })
    }

    /// Parse arguments given through an iterable thing such as a `Vec` or a slice.
    fn from_iter<I,T>(args: I) -> Result<Self, clap::Error>
        where
        I: IntoIterator<Item = T>,
        T: Into<OsString> + Clone,
    {
        Self::with_clap(ArgInfo::new(""),
                        clap::App::new("foo"),
                        |a| {
                            let matches = a.get_matches_from_safe(args)?;
                            Ok(Self::from_clap("", &matches).unwrap())
                        })
    }
}

impl ClapMe for bool {
    fn with_clap<T>(info: ArgInfo, app: clap::App,
                    f: impl FnOnce(clap::App) -> T) -> T {
        let conflicts: Vec<_> = info.conflicted_flags.iter().map(AsRef::as_ref).collect();
        f(app.arg(clap::Arg::with_name(info.name).long(info.name)
                  .requires_all(info.required_flags)
                  .conflicts_with_all(&conflicts)
                  .help(&info.help)))
    }
    fn from_clap(name: &str, matches: &clap::ArgMatches) -> Option<Self> {
        Some(matches.is_present(name))
    }
    fn requires_flags(_name: &str) -> Vec<String> {
        vec![]
    }
}

macro_rules! impl_fromstr {
    ($t:ty, $tyname:expr) => {
        impl ClapMe for $t {
            fn with_clap<T>(info: ArgInfo, app: clap::App,
                            f: impl FnOnce(clap::App) -> T) -> T {
                let conflicts: Vec<_> = info.conflicted_flags.iter().map(AsRef::as_ref).collect();
                let ruo: Vec<_> = info.required_unless_one.iter().map(AsRef::as_ref).collect();
                if info.name == "" {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .requires_all(info.required_flags)
                              .required(info.required)
                              .help(&info.help)
                              .validator(|s| Self::from_str(&s).map(|_| ())
                                         .map_err(|e| e.to_string()))))
                } else if ruo.len() > 0 {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .long(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .requires_all(info.required_flags)
                              .required(info.required)
                              .conflicts_with_all(&conflicts)
                              .required_unless_one(&ruo)
                              .help(&info.help)
                              .validator(|s| Self::from_str(&s).map(|_| ())
                                         .map_err(|e| e.to_string()))))
                } else {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .long(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .requires_all(info.required_flags)
                              .required(info.required)
                              .conflicts_with_all(&conflicts)
                              .help(&info.help)
                              .validator(|s| Self::from_str(&s).map(|_| ())
                                         .map_err(|e| e.to_string()))))
                }
            }
            fn from_clap(name: &str, matches: &clap::ArgMatches) -> Option<Self> {
                // println!("from {} {:?}", name, matches.value_of(name));
                matches.value_of(name).map(|s| Self::from_str(s).unwrap())
            }
        }

        impl ClapMe for Vec<$t> {
            fn with_clap<TT>(info: ArgInfo, app: clap::App,
                             f: impl FnOnce(clap::App) -> TT) -> TT {
                let conflicts: Vec<_> = info.conflicted_flags.iter().map(AsRef::as_ref).collect();
                if info.name == "" {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .required(false)
                              .requires_all(info.required_flags)
                              .multiple(true)
                              .help(&info.help)
                              .validator(|s| <$t>::from_str(&s).map(|_| ())
                                         .map_err(|_| "oops".to_owned()))))
                } else {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .long(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .required(false)
                              .requires_all(info.required_flags)
                              .conflicts_with_all(&conflicts)
                              .multiple(true)
                              .help(&info.help)
                              .validator(|s| <$t>::from_str(&s).map(|_| ())
                                         .map_err(|_| "oops".to_owned()))))
                }
            }
            fn from_clap(name: &str, matches: &clap::ArgMatches) -> Option<Self> {
                Some(matches.values_of(name).unwrap_or(clap::Values::default())
                     .map(|s| <$t>::from_str(s).unwrap()).collect())
            }
            fn requires_flags(_name: &str) -> Vec<String> {
                vec![]
            }
        }
    }
}

fn str_to_f64(s: &str) -> Result<f64, String> {
    meval::eval_str(s).map_err(|e| e.to_string())
}

macro_rules! impl_rustyard {
    ($t:ty, $tyname:expr) => {
        impl ClapMe for $t {
            fn with_clap<T>(info: ArgInfo, app: clap::App,
                            f: impl FnOnce(clap::App) -> T) -> T {
                let conflicts: Vec<_> = info.conflicted_flags.iter().map(AsRef::as_ref).collect();
                let ruo: Vec<_> = info.required_unless_one.iter().map(AsRef::as_ref).collect();
                if info.name == "" {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .requires_all(info.required_flags)
                              .required(info.required)
                              .help(&info.help)
                              .validator(|s| str_to_f64(&s).map(|_| ()))))
                } else if ruo.len() > 0 {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .long(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .requires_all(info.required_flags)
                              .required(info.required)
                              .conflicts_with_all(&conflicts)
                              .required_unless_one(&ruo)
                              .help(&info.help)
                              .validator(|s| str_to_f64(&s).map(|_| ()))))
                } else {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .long(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .requires_all(info.required_flags)
                              .required(info.required)
                              .conflicts_with_all(&conflicts)
                              .help(&info.help)
                              .validator(|s| str_to_f64(&s).map(|_| ()))))
                }
            }
            fn from_clap(name: &str, matches: &clap::ArgMatches) -> Option<Self> {
                // println!("from {} {:?}", name, matches.value_of(name));
                matches.value_of(name).map(|s| str_to_f64(s).unwrap() as Self)
            }
        }

        impl ClapMe for Vec<$t> {
            fn with_clap<TT>(info: ArgInfo, app: clap::App,
                             f: impl FnOnce(clap::App) -> TT) -> TT {
                let conflicts: Vec<_> = info.conflicted_flags.iter().map(AsRef::as_ref).collect();
                if info.name == "" {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .required(false)
                              .requires_all(info.required_flags)
                              .multiple(true)
                              .help(&info.help)
                              .validator(|s| str_to_f64(&s).map(|_| ()))))
                } else {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .long(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .required(false)
                              .requires_all(info.required_flags)
                              .conflicts_with_all(&conflicts)
                              .multiple(true)
                              .help(&info.help)
                              .validator(|s| str_to_f64(&s).map(|_| ()))))
                }
            }
            fn from_clap(name: &str, matches: &clap::ArgMatches) -> Option<Self> {
                Some(matches.values_of(name).unwrap_or(clap::Values::default())
                     .map(|s| str_to_f64(s).unwrap() as $t).collect())
            }
            fn requires_flags(_name: &str) -> Vec<String> {
                vec![]
            }
        }
    }
}
impl_rustyard!(f32, "FLOAT");
impl_rustyard!(f64, "FLOAT");

impl_fromstr!(std::net::IpAddr, "ADDR");
impl_fromstr!(std::net::Ipv4Addr, "ADDR");
impl_fromstr!(std::net::Ipv6Addr, "ADDR");
impl_fromstr!(std::net::SocketAddr, "ADDR:PORT");
impl_fromstr!(std::net::SocketAddrV4, "ADDR:PORT");
impl_fromstr!(std::net::SocketAddrV6, "ADDR:PORT");

macro_rules! impl_fromstr_or_via_f64 {
    ($t:ty, $tyname:expr) => {
        impl ClapMe for $t {
            fn with_clap<T>(info: ArgInfo, app: clap::App,
                            f: impl FnOnce(clap::App) -> T) -> T {
                let conflicts: Vec<_> = info.conflicted_flags.iter().map(AsRef::as_ref).collect();
                let ruo: Vec<_> = info.required_unless_one.iter().map(AsRef::as_ref).collect();
                let validator = |s: String| {
                    if let Err(e) = Self::from_str(&s) {
                        if let Ok(x) = str_to_f64(&s) {
                            if (x as $t) as f64 == x {
                                return Ok(());
                            }
                        }
                        return Err(e.to_string());
                    }
                    Ok(())
                };
                if info.name == "" {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .requires_all(info.required_flags)
                              .required(info.required)
                              .help(&info.help)
                              .validator(validator)))
                } else if ruo.len() > 0 {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .long(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .requires_all(info.required_flags)
                              .required(info.required)
                              .conflicts_with_all(&conflicts)
                              .required_unless_one(&ruo)
                              .help(&info.help)
                              .validator(validator)))
                } else {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .long(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .requires_all(info.required_flags)
                              .required(info.required)
                              .conflicts_with_all(&conflicts)
                              .help(&info.help)
                              .validator(validator)))
                }
            }
            fn from_clap(name: &str, matches: &clap::ArgMatches) -> Option<Self> {
                // println!("from {} {:?}", name, matches.value_of(name));
                matches.value_of(name).map(|s| {
                    if let Ok(v) = Self::from_str(s) {
                        return v;
                    }
                    str_to_f64(s).unwrap() as Self
                })
            }
        }

        impl ClapMe for Vec<$t> {
            fn with_clap<TT>(info: ArgInfo, app: clap::App,
                             f: impl FnOnce(clap::App) -> TT) -> TT {
                let conflicts: Vec<_> = info.conflicted_flags.iter().map(AsRef::as_ref).collect();
                if info.name == "" {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .required(false)
                              .requires_all(info.required_flags)
                              .multiple(true)
                              .help(&info.help)
                              .validator(|s| <$t>::from_str(&s).map(|_| ())
                                         .map_err(|_| "oops".to_owned()))))
                } else {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .long(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .required(false)
                              .requires_all(info.required_flags)
                              .conflicts_with_all(&conflicts)
                              .multiple(true)
                              .help(&info.help)
                              .validator(|s| <$t>::from_str(&s).map(|_| ())
                                         .map_err(|_| "oops".to_owned()))))
                }
            }
            fn from_clap(name: &str, matches: &clap::ArgMatches) -> Option<Self> {
                Some(matches.values_of(name).unwrap_or(clap::Values::default())
                     .map(|s| <$t>::from_str(s).unwrap()).collect())
            }
            fn requires_flags(_name: &str) -> Vec<String> {
                vec![]
            }
        }
    }
}

impl_fromstr_or_via_f64!(i16, "INT");
impl_fromstr_or_via_f64!(isize, "INT");
impl_fromstr_or_via_f64!(i32, "INT");
impl_fromstr_or_via_f64!(i64, "INT");
impl_fromstr_or_via_f64!(i128, "INT");
impl_fromstr_or_via_f64!(u16, "INT");
impl_fromstr_or_via_f64!(u32, "INT");
impl_fromstr_or_via_f64!(u64, "INT");
impl_fromstr_or_via_f64!(u128, "INT");
impl_fromstr_or_via_f64!(usize, "INT");

macro_rules! impl_from {
    ($t:ty, $tyname:expr) => {
        impl ClapMe for $t {
            fn with_clap<T>(info: ArgInfo, app: clap::App,
                            f: impl FnOnce(clap::App) -> T) -> T {
                let conflicts: Vec<_> = info.conflicted_flags.iter().map(AsRef::as_ref).collect();
                let ruo: Vec<_> = info.required_unless_one.iter().map(AsRef::as_ref).collect();
                // println!("\n\nmy name is {:?}", info.name);
                // println!("   requires_all {:?}", info.required_flags);
                if info.name == "" {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .requires_all(info.required_flags)
                              .required(info.required)
                              .help(&info.help)))
                } else if ruo.len() > 0 {
                    // println!("   {} conflicts_with_all {:?}", info.name, &conflicts);
                    // println!("   {} required_unless_one {:?}", info.name, &ruo);
                    f(app.arg(clap::Arg::with_name(info.name)
                              .long(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .requires_all(info.required_flags)
                              .required(info.required)
                              .conflicts_with_all(&conflicts)
                              .required_unless_one(&ruo)
                              .help(&info.help)))
                } else {
                    // println!("   {} conflicts_with_all {:?}", info.name, &conflicts);
                    f(app.arg(clap::Arg::with_name(info.name)
                              .long(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .requires_all(info.required_flags)
                              .required(info.required)
                              .conflicts_with_all(&conflicts)
                              .help(&info.help)))
                }
            }
            fn from_clap(name: &str, matches: &clap::ArgMatches) -> Option<Self> {
                matches.value_of(name).map(|s| Self::from(s))
            }
        }

        impl ClapMe for Vec<$t> {
            fn with_clap<TT>(info: ArgInfo, app: clap::App,
                             f: impl FnOnce(clap::App) -> TT) -> TT {
                if info.name == "" {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .required(false)
                              .requires_all(info.required_flags)
                              .multiple(true)
                              .help(&info.help)))
                } else {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .long(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .required(false)
                              .requires_all(info.required_flags)
                              .multiple(true)
                              .help(&info.help)))
                }
            }
            fn from_clap(name: &str, matches: &clap::ArgMatches) -> Option<Self> {
                Some(matches.values_of(name).unwrap_or(clap::Values::default())
                     .map(|s| <$t>::from(s)).collect())
            }
            fn requires_flags(_name: &str) -> Vec<String> {
                vec![]
            }
        }
    }
}

impl_from!(String, "STRING");

macro_rules! impl_from_osstr {
    ($t:ty, $tyname:expr) => {
        impl ClapMe for $t {
            fn with_clap<T>(info: ArgInfo, app: clap::App,
                            f: impl FnOnce(clap::App) -> T) -> T {
                let conflicts: Vec<_> = info.conflicted_flags.iter().map(AsRef::as_ref).collect();
                let ruo: Vec<_> = info.required_unless_one.iter().map(AsRef::as_ref).collect();
                if info.name == "" {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .requires_all(info.required_flags)
                              .required(info.required)
                              .help(&info.help)))
                } else if ruo.len() > 0 {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .long(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .requires_all(info.required_flags)
                              .required(info.required)
                              .conflicts_with_all(&conflicts)
                              .required_unless_one(&ruo)
                              .help(&info.help)))
                } else {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .long(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .requires_all(info.required_flags)
                              .required(info.required)
                              .conflicts_with_all(&conflicts)
                              .help(&info.help)))
                }
            }
            fn from_clap(name: &str, matches: &clap::ArgMatches) -> Option<Self> {
                matches.value_of_os(name).map(|s| Self::from(s))
            }
        }

        impl ClapMe for Vec<$t> {
            fn with_clap<TT>(info: ArgInfo, app: clap::App,
                             f: impl FnOnce(clap::App) -> TT) -> TT {
                if info.name == "" {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .required(false)
                              .requires_all(info.required_flags)
                              .multiple(true)
                              .help(&info.help)))
                } else {
                    f(app.arg(clap::Arg::with_name(info.name)
                              .long(info.name)
                              .takes_value(true)
                              .value_name($tyname)
                              .required(false)
                              .requires_all(info.required_flags)
                              .multiple(true)
                              .help(&info.help)))
                }
            }
            fn from_clap(name: &str, matches: &clap::ArgMatches) -> Option<Self> {
                Some(matches.values_of_os(name).unwrap_or(clap::OsValues::default())
                     .map(|s| <$t>::from(s)).collect())
            }
            fn requires_flags(_name: &str) -> Vec<String> {
                vec![]
            }
        }
    }
}

impl_from_osstr!(std::path::PathBuf, "PATH");
impl_from_osstr!(std::ffi::OsString, "STRING");

impl<T: ClapMe> ClapMe for Option<T> {
    fn with_clap<TT>(mut info: ArgInfo, app: clap::App,
                     f: impl FnOnce(clap::App) -> TT) -> TT {
        info.required = false;
        info.required_unless_one = Vec::new();
        T::with_clap(info, app, f)
    }
    fn from_clap(name: &str, matches: &clap::ArgMatches) -> Option<Self> {
        Some(T::from_clap(name, matches))
    }
    fn requires_flags(_name: &str) -> Vec<String> {
        vec![]
    }
}


impl<T> ClapMe for std::marker::PhantomData<T> {
    fn with_clap<TT>(_info: ArgInfo, app: clap::App,
                     f: impl FnOnce(clap::App) -> TT) -> TT {
        f(app)
    }
    fn from_clap(_name: &str, _matches: &clap::ArgMatches) -> Option<Self> {
        Some(std::marker::PhantomData)
    }
    fn requires_flags(_name: &str) -> Vec<String> {
        vec![]
    }
}