blarg_builder 1.0.0

A type-safe, domain sensitive, argument/option paradigm command line parser.
Documentation
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
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
use crate::api::{CliArgument, CliOption, GenericCapturable, Scalar};
use crate::matcher::{ArgumentConfig, Bound, OptionConfig};
use crate::model::Nargs;
use crate::parser::{
    AnonymousCapturable, ArgumentCapture, ArgumentParameter, OptionCapture, OptionParameter,
    ParseError,
};
use crate::prelude::Choices;
use std::collections::HashMap;

pub(crate) struct AnonymousCapture<'a, T: 'a> {
    field: Box<dyn GenericCapturable<'a, T> + 'a>,
}

impl<'a, T> AnonymousCapture<'a, T> {
    pub(crate) fn bind(field: impl GenericCapturable<'a, T> + 'a) -> Self {
        Self {
            field: Box::new(field),
        }
    }
}

impl<'a, T> AnonymousCapturable for AnonymousCapture<'a, T> {
    fn matched(&mut self) {
        self.field.matched();
    }

    fn capture(&mut self, value: &str) -> Result<(), ParseError> {
        self.field.capture(value).map_err(ParseError::from)
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(super) enum ParameterClass {
    Opt,
    Arg,
}

pub(super) struct ParameterInner<'a, T> {
    class: ParameterClass,
    field: AnonymousCapture<'a, T>,
    nargs: Nargs,
    name: String,
    short: Option<char>,
    help: Option<String>,
    meta: Option<Vec<String>>,
    choices: HashMap<String, String>,
}

impl<'a, T> ParameterInner<'a, T> {
    pub(super) fn class(&self) -> ParameterClass {
        self.class
    }
}

impl<'a, T> std::fmt::Debug for ParameterInner<'a, T> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let class = match &self.class {
            ParameterClass::Opt => "Opt",
            ParameterClass::Arg => "Arg",
        };
        let name = match &self.class {
            ParameterClass::Opt => format!("--{n}", n = self.name),
            ParameterClass::Arg => format!("{n}", n = self.name),
        };
        let short = match &self.class {
            ParameterClass::Opt => match &self.short {
                Some(s) => format!(" -{s},"),
                None => "".to_string(),
            },
            ParameterClass::Arg => "".to_string(),
        };
        let help = if let Some(d) = &self.help {
            format!(", {d}")
        } else {
            "".to_string()
        };

        write!(
            f,
            "{class}[{t}, {nargs}, {name},{short} {help}]",
            t = std::any::type_name::<T>(),
            nargs = self.nargs,
        )
    }
}

impl<'a, T> From<&ParameterInner<'a, T>> for OptionConfig {
    fn from(value: &ParameterInner<'a, T>) -> Self {
        OptionConfig::new(
            value.name.clone(),
            value.short.clone(),
            Bound::from(value.nargs),
        )
    }
}

impl<'a, T> From<ParameterInner<'a, T>> for OptionCapture<'a> {
    fn from(value: ParameterInner<'a, T>) -> Self {
        let config = OptionConfig::from(&value);
        let ParameterInner { field, .. } = value;
        (config, Box::new(field))
    }
}

impl<'a, T> From<&ParameterInner<'a, T>> for OptionParameter {
    fn from(value: &ParameterInner<'a, T>) -> Self {
        OptionParameter::new(
            value.name.clone(),
            value.short.clone(),
            value.nargs,
            value.help.clone(),
            value.meta.clone(),
            value.choices.clone(),
        )
    }
}

impl<'a, T> From<&ParameterInner<'a, T>> for ArgumentConfig {
    fn from(value: &ParameterInner<'a, T>) -> Self {
        ArgumentConfig::new(value.name.clone(), Bound::from(value.nargs))
    }
}

impl<'a, T> From<ParameterInner<'a, T>> for ArgumentCapture<'a> {
    fn from(value: ParameterInner<'a, T>) -> Self {
        let config = ArgumentConfig::from(&value);
        let ParameterInner { field, .. } = value;
        (config, Box::new(field))
    }
}

impl<'a, T> From<&ParameterInner<'a, T>> for ArgumentParameter {
    fn from(value: &ParameterInner<'a, T>) -> Self {
        ArgumentParameter::new(
            value.name.clone(),
            value.nargs,
            value.help.clone(),
            value.meta.clone(),
            value.choices.clone(),
        )
    }
}

/// The condition argument with which to branch the parser.
/// Used with [`CommandLineParser::branch`](./struct.CommandLineParser.html#method.branch).
///
/// There is an implicit (non-compile time) requirement for the type `T` of a `Condition`:
/// > The implementations of `std::fmt::Display` and `std::str::FromStr` must form an inverse relationship.
///
/// This sounds scary and onerous, but most types will naturally adhere to this requirement.
/// Consider rusts implementation for `bool`, where this is requirement holds:
/// ```
/// # use std::str::FromStr;
/// assert_eq!(bool::from_str("true").unwrap().to_string(), "true");
/// assert_eq!(bool::from_str("false").unwrap().to_string(), "false");
/// ```
///
/// However, not all types will necessarily adhere to this requirement.
/// Observe the following example enum:
/// ```
/// # use std::str::FromStr;
/// // Implement FromStr to be case-insensitive.
/// // Implement Display.
/// enum FooBar {
///     Foo,
///     Bar,
/// }
/// # impl FromStr for FooBar {
/// #    type Err = String;
/// #    fn from_str(value: &str) -> Result<Self, Self::Err> {
/// #        match value.to_lowercase().as_str() {
/// #            "foo" => Ok(FooBar::Foo),
/// #            "bar" => Ok(FooBar::Bar),
/// #            _ => Err(format!("unknown: {}", value)),
/// #        }
/// #    }
/// # }
/// # impl std::fmt::Display for FooBar {
/// #   fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
/// #       match self {
/// #           FooBar::Foo => write!(f, "Foo"),
/// #           FooBar::Bar => write!(f, "Bar"),
/// #       }
/// #   }
/// # }
/// assert_eq!(FooBar::from_str("Foo").unwrap().to_string(), "Foo");
/// // Display does not invert FromStr!
/// assert_ne!(FooBar::from_str("foo").unwrap().to_string(), "foo");
/// ```
pub struct Condition<'a, T>(Parameter<'a, T>);

impl<'a, T: std::str::FromStr + std::fmt::Display> Condition<'a, T> {
    /// Create a condition parameter.
    ///
    /// ### Example
    /// ```
    /// # use blarg_builder as blarg;
    /// use blarg::{Condition, Scalar};
    /// use std::str::FromStr;
    ///
    /// // Be sure to implement `std::fmt::Display` and `std::str::FromStr` with an inverse relationship.
    /// enum FooBar {
    ///     Foo,
    ///     Bar,
    /// }
    /// # impl std::fmt::Display for FooBar {
    /// #     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    /// #         match self {
    /// #              FooBar::Foo => write!(f, "foo"),
    /// #             FooBar::Bar => write!(f, "bar"),
    /// #         }
    /// #     }
    /// # }
    /// # impl FromStr for FooBar {
    /// #     type Err = String;
    /// #
    /// #     fn from_str(value: &str) -> Result<Self, Self::Err> {
    /// #         match value.to_lowercase().as_str() {
    /// #             "foo" => Ok(FooBar::Foo),
    /// #             "bar" => Ok(FooBar::Bar),
    /// #             _ => Err(format!("unknown: {}", value)),
    /// #         }
    /// #     }
    /// # }
    ///
    /// let mut foo_bar: FooBar = FooBar::Foo;
    /// Condition::new(Scalar::new(&mut foo_bar), "foo_bar");
    /// // .. parse()
    /// match foo_bar {
    ///     FooBar::Foo => println!("Do foo'y things."),
    ///     FooBar::Bar => println!("Do bar'y things."),
    /// };
    /// ```
    pub fn new(value: Scalar<'a, T>, name: &'static str) -> Self {
        Condition(Parameter::argument(value, name))
    }

    /// Document the help message for this sub-command condition.
    /// If repeated, only the final message will apply to the sub-command condition.
    ///
    /// A help message describes the condition in full sentence/paragraph format.
    /// We recommend allowing `blarg` to format this field (ex: it is not recommended to use line breaks `'\n'`).
    ///
    /// See also:
    /// * [`Condition::meta`]
    /// * [`Condition::choice`]
    ///
    /// ### Example
    /// ```
    /// # use blarg_builder as blarg;
    /// use blarg::{Condition, Scalar};
    ///
    /// let mut case: u32 = 0;
    /// Condition::new(Scalar::new(&mut case), "case")
    ///     .help("--this will get discarded--")
    ///     .help("Choose the 'case' to execute.  Description may include multiple sentences.");
    /// ```
    pub fn help(self, description: impl Into<String>) -> Self {
        let inner = self.0;
        Self(inner.help(description))
    }

    /// Document the meta message(s) for this sub-command condition.
    /// If repeated, only the final message will apply to the sub-command condition.
    ///
    /// Meta message(s) describe short format extra details about the condition.
    /// We recommend non-sentence information for this field.
    ///
    /// See also:
    /// * [`Condition::help`]
    /// * [`Condition::choice`]
    ///
    /// ### Example
    /// ```
    /// # use blarg_builder as blarg;
    /// use blarg::{Condition, Scalar};
    ///
    /// let mut case: u32 = 0;
    /// Condition::new(Scalar::new(&mut case), "case")
    ///     .meta(vec!["--this will get discarded--"])
    ///     .meta(vec!["final extra", "details"]);
    /// ```
    pub fn meta(self, description: Vec<impl Into<String>>) -> Self {
        let inner = self.0;
        Self(inner.meta(description))
    }

    pub(super) fn consume(self) -> Parameter<'a, T> {
        self.0
    }
}

impl<'a, T: std::str::FromStr + std::fmt::Display> Choices<T> for Condition<'a, T> {
    /// Document a choice's help message for the sub-command condition.
    /// If repeated for the same `variant` of `T`, only the final message will apply to the sub-command condition.
    /// Repeat using different variants to document multiple choices.
    /// Needn't be exhaustive.
    ///
    /// A choice help message describes the variant in full sentence/paragraph format.
    /// We recommend allowing `blarg` to format this field (ex: it is not recommended to use line breaks `'\n'`).
    ///
    /// Notice, the documented or un-documented choices *do not* affect the actual command parser semantics.
    /// To actually limit the command parser semantics, be sure to use an enum.
    ///
    /// See also:
    /// * [`Condition::help`]
    /// * [`Condition::meta`]
    ///
    /// ### Example
    /// ```
    /// # use blarg_builder as blarg;
    /// use blarg::{prelude::*, Condition, Scalar};
    /// use std::str::FromStr;
    ///
    /// // Be sure to implement `std::fmt::Display` and `std::str::FromStr`.
    /// enum FooBar {
    ///     Foo,
    ///     Bar,
    /// }
    /// # impl std::fmt::Display for FooBar {
    /// #     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    /// #         match self {
    /// #              FooBar::Foo => write!(f, "foo"),
    /// #             FooBar::Bar => write!(f, "bar"),
    /// #         }
    /// #     }
    /// # }
    /// # impl FromStr for FooBar {
    /// #     type Err = String;
    /// #
    /// #     fn from_str(value: &str) -> Result<Self, Self::Err> {
    /// #         match value.to_lowercase().as_str() {
    /// #             "foo" => Ok(FooBar::Foo),
    /// #             "bar" => Ok(FooBar::Bar),
    /// #             _ => Err(format!("unknown: {}", value)),
    /// #         }
    /// #     }
    /// # }
    ///
    /// let mut foo_bar: FooBar = FooBar::Foo;
    /// Condition::new(Scalar::new(&mut foo_bar), "foo_bar")
    ///     .choice(FooBar::Foo, "--this will get discarded--")
    ///     .choice(FooBar::Foo, "Do foo'y things.")
    ///     .choice(FooBar::Bar, "Do bar'y things.  Description may include multiple sentences.");
    /// ```
    fn choice(self, variant: T, description: impl Into<String>) -> Self {
        let inner = self.0;
        Self(inner.choice(variant, description))
    }
}

/// An argument/option for the command parser.
/// Used with [`CommandLineParser::add`](./struct.CommandLineParser.html#method.add) and [`SubCommand::add`](./struct.SubCommand.html#method.add).
pub struct Parameter<'a, T>(ParameterInner<'a, T>);

impl<'a, T> Parameter<'a, T> {
    /// Create an option parameter.
    ///
    /// ### Example
    /// ```
    /// # use blarg_builder as blarg;
    /// use blarg::{Parameter, Switch};
    ///
    /// let mut verbose: bool = false;
    /// Parameter::option(Switch::new(&mut verbose, true), "verbose", Some('v'));
    /// ```
    pub fn option(
        field: impl GenericCapturable<'a, T> + CliOption + 'a,
        name: impl Into<String>,
        short: Option<char>,
    ) -> Self {
        let nargs = field.nargs();
        Self(ParameterInner {
            class: ParameterClass::Opt,
            field: AnonymousCapture::bind(field),
            nargs,
            name: name.into(),
            short,
            help: None,
            meta: None,
            choices: HashMap::default(),
        })
    }

    /// Create an argument parameter.
    ///
    /// ### Example
    /// ```
    /// # use blarg_builder as blarg;
    /// use blarg::{Parameter, Scalar};
    ///
    /// let mut verbose: bool = false;
    /// Parameter::argument(Scalar::new(&mut verbose), "verbose");
    /// ```
    pub fn argument(
        field: impl GenericCapturable<'a, T> + CliArgument + 'a,
        name: impl Into<String>,
    ) -> Self {
        let nargs = field.nargs();
        Self(ParameterInner {
            class: ParameterClass::Arg,
            field: AnonymousCapture::bind(field),
            nargs,
            name: name.into(),
            short: None,
            help: None,
            meta: None,
            choices: HashMap::default(),
        })
    }

    /// Document the help message for this parameter.
    /// If repeated, only the final message will apply to the parameter.
    ///
    /// A help message describes the parameter in full sentence/paragraph format.
    /// We recommend allowing `blarg` to format this field (ex: it is not recommended to use line breaks `'\n'`).
    ///
    /// See also:
    /// * [`Parameter::meta`]
    /// * [`Parameter::choice`]
    ///
    /// ### Example
    /// ```
    /// # use blarg_builder as blarg;
    /// use blarg::{Parameter, Scalar};
    ///
    /// let mut verbose: bool = false;
    /// Parameter::argument(Scalar::new(&mut verbose), "verbose")
    ///     .help("--this will get discarded--")
    ///     .help("Make the program output verbose.  Description may include multiple sentences.");
    /// ```
    pub fn help(self, description: impl Into<String>) -> Self {
        let mut inner = self.0;
        inner.help = Some(description.into());
        Self(inner)
    }

    /// Document the meta message(s) for this parameter.
    /// If repeated, only the final message will apply to the parameter.
    ///
    /// Meta message(s) describe short format extra details about the parameter.
    /// We recommend non-sentence information for this field.
    ///
    /// See also:
    /// * [`Parameter::help`]
    /// * [`Parameter::choice`]
    ///
    /// ### Example
    /// ```
    /// # use blarg_builder as blarg;
    /// use blarg::{Parameter, Scalar};
    ///
    /// let mut verbose: bool = false;
    /// Parameter::argument(Scalar::new(&mut verbose), "verbose")
    ///     .meta(vec!["--this will be discarded--"])
    ///     .meta(vec!["final extra", "details"]);
    /// ```
    pub fn meta(self, descriptions: Vec<impl Into<String>>) -> Self {
        let mut inner = self.0;
        inner.meta = Some(descriptions.into_iter().map(|s| s.into()).collect());
        Self(inner)
    }

    pub(super) fn name(&self) -> String {
        self.0.name.clone()
    }

    pub(super) fn consume(self) -> ParameterInner<'a, T> {
        self.0
    }
}

impl<'a, T: std::fmt::Display> Choices<T> for Parameter<'a, T> {
    /// Document a choice's help message for this parameter.
    /// If repeated for the same `variant` of `T`, only the final message will apply to the parameter.
    /// Repeat using different variants to document multiple choices.
    /// Needn't be exhaustive.
    ///
    /// A choice help message describes the variant in full sentence/paragraph format.
    /// We recommend allowing `blarg` to format this field (ex: it is not recommended to use line breaks `'\n'`).
    ///
    /// Notice, the documented or un-documented choices *do not* affect the actual command parser semantics.
    /// To actually limit the command parser semantics, be sure to use an enum.
    ///
    /// See also:
    /// * [`Parameter::help`]
    /// * [`Parameter::meta`]
    ///
    /// ### Example
    /// ```
    /// # use blarg_builder as blarg;
    /// use blarg::{prelude::*, Parameter, Scalar};
    /// use std::str::FromStr;
    ///
    /// let mut door: u32 = 0;
    /// Parameter::argument(Scalar::new(&mut door), "door")
    ///     .choice(1, "--this will get discarded--")
    ///     .choice(1, "Enter door #1.")
    ///     .choice(2, "Enter door #2.  Description may include multiple sentences.");
    /// ```
    fn choice(self, variant: T, description: impl Into<String>) -> Self {
        let mut inner = self.0;
        inner
            .choices
            .insert(variant.to_string(), description.into());
        Self(inner)
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::api::{Parameter, Switch};

    #[test]
    fn option() {
        let mut flag: bool = false;
        let option = Parameter::option(Switch::new(&mut flag, true), "flag", None).consume();

        assert_eq!(option.class, ParameterClass::Opt);
        assert_eq!(option.name, "flag");
        assert_eq!(option.short, None);
        assert_eq!(option.help, None);
        assert_eq!(option.meta, None);
        assert_eq!(option.choices, HashMap::default());
    }

    #[test]
    fn option_short() {
        let mut flag: bool = false;
        let option = Parameter::option(Switch::new(&mut flag, true), "flag", Some('f')).consume();

        assert_eq!(option.class, ParameterClass::Opt);
        assert_eq!(option.name, "flag");
        assert_eq!(option.short, Some('f'));
        assert_eq!(option.help, None);
        assert_eq!(option.meta, None);
        assert_eq!(option.choices, HashMap::default());
    }

    #[test]
    fn option_help() {
        let mut flag: bool = false;
        let option = Parameter::option(Switch::new(&mut flag, true), "flag", None)
            .help("help message")
            .consume();

        assert_eq!(option.class, ParameterClass::Opt);
        assert_eq!(option.name, "flag".to_string());
        assert_eq!(option.short, None);
        assert_eq!(option.help, Some("help message".to_string()));
        assert_eq!(option.meta, None);
        assert_eq!(option.choices, HashMap::default());
    }

    #[test]
    fn option_meta() {
        let mut flag: bool = false;
        let option = Parameter::option(Switch::new(&mut flag, true), "flag", None)
            .meta(vec!["meta message"])
            .consume();

        assert_eq!(option.class, ParameterClass::Opt);
        assert_eq!(option.name, "flag".to_string());
        assert_eq!(option.short, None);
        assert_eq!(option.help, None);
        assert_eq!(option.meta, Some(vec!["meta message".to_string()]));
        assert_eq!(option.choices, HashMap::default());
    }

    #[test]
    fn option_choice() {
        let mut flag: bool = false;
        let option = Parameter::option(Switch::new(&mut flag, true), "flag", None)
            .choice(true, "b")
            .choice(false, "d")
            .choice(true, "e")
            .consume();

        assert_eq!(option.class, ParameterClass::Opt);
        assert_eq!(option.name, "flag".to_string());
        assert_eq!(option.short, None);
        assert_eq!(option.help, None);
        assert_eq!(option.meta, None);
        assert_eq!(
            option.choices,
            HashMap::from([
                ("true".to_string(), "e".to_string()),
                ("false".to_string(), "d".to_string())
            ])
        );
    }

    #[test]
    fn argument() {
        let mut item: bool = false;
        let argument = Parameter::argument(Scalar::new(&mut item), "item").consume();

        assert_eq!(argument.class, ParameterClass::Arg);
        assert_eq!(argument.name, "item".to_string());
        assert_eq!(argument.short, None);
        assert_eq!(argument.help, None);
        assert_eq!(argument.meta, None);
        assert_eq!(argument.choices, HashMap::default());
    }

    #[test]
    fn argument_help() {
        let mut item: bool = false;
        let argument = Parameter::argument(Scalar::new(&mut item), "item")
            .help("help message")
            .consume();

        assert_eq!(argument.class, ParameterClass::Arg);
        assert_eq!(argument.name, "item".to_string());
        assert_eq!(argument.short, None);
        assert_eq!(argument.help, Some("help message".to_string()));
        assert_eq!(argument.meta, None);
        assert_eq!(argument.choices, HashMap::default());
    }

    #[test]
    fn argument_meta() {
        let mut item: bool = false;
        let argument = Parameter::argument(Scalar::new(&mut item), "item")
            .meta(vec!["meta message"])
            .consume();

        assert_eq!(argument.class, ParameterClass::Arg);
        assert_eq!(argument.name, "item".to_string());
        assert_eq!(argument.short, None);
        assert_eq!(argument.help, None);
        assert_eq!(argument.meta, Some(vec!["meta message".to_string()]));
        assert_eq!(argument.choices, HashMap::default());
    }

    #[test]
    fn argument_choice() {
        let mut item: bool = false;
        let argument = Parameter::argument(Scalar::new(&mut item), "item")
            .choice(true, "b")
            .choice(false, "d")
            .choice(true, "e")
            .help("help")
            .meta(vec!["meta"])
            .consume();

        assert_eq!(argument.class, ParameterClass::Arg);
        assert_eq!(argument.name, "item".to_string());
        assert_eq!(argument.short, None);
        assert_eq!(argument.help, Some("help".to_string()));
        assert_eq!(argument.meta, Some(vec!["meta".to_string()]));
        assert_eq!(
            argument.choices,
            HashMap::from([
                ("true".to_string(), "e".to_string()),
                ("false".to_string(), "d".to_string())
            ])
        );
    }

    #[test]
    fn condition() {
        let mut item: bool = false;
        let condition = Condition::new(Scalar::new(&mut item), "item")
            .choice(true, "b")
            .choice(false, "d")
            .choice(true, "e")
            .help("help")
            .meta(vec!["meta"])
            .consume();
        let argument = condition.consume();

        assert_eq!(argument.class, ParameterClass::Arg);
        assert_eq!(argument.name, "item".to_string());
        assert_eq!(argument.short, None);
        assert_eq!(argument.help, Some("help".to_string()));
        assert_eq!(argument.meta, Some(vec!["meta".to_string()]));
        assert_eq!(
            argument.choices,
            HashMap::from([
                ("true".to_string(), "e".to_string()),
                ("false".to_string(), "d".to_string())
            ])
        );
    }
}