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
// Copyright 2018 Lyndon Brown
//
// This file is part of the `gong` command-line argument processing library.
//
// Licensed under the MIT license or the Apache license (version 2.0), at your option. You may not
// copy, modify, or distribute this file except in compliance with said license. You can find copies
// of these licenses either in the LICENSE-MIT and LICENSE-APACHE files, or alternatively at
// <http://opensource.org/licenses/MIT> and <http://www.apache.org/licenses/LICENSE-2.0>
// respectively.

/// Construct an [`OptionSetEx`](options/struct.OptionSetEx.html)
///
/// Takes:
///
/// 1. A `Vec` of long options
/// 2. A `Vec` of short options
/// 3. Mode
/// 4. Abbreviation support state
///
/// The last two can be left off if both defaults.
///
/// Example:
///
/// ```rust
/// # #[macro_use]
/// # extern crate gong;
/// # fn main() {
/// // Without modes, empty option lists
/// let _ = gong_option_set!(vec![], vec![]);
/// // With modes, empty option lists
/// let _ = gong_option_set!(vec![], vec![], gong::options::OptionsMode::Standard, true);
/// # }
/// ```
#[macro_export]
macro_rules! gong_option_set {
    ( $long:expr, $short:expr, $mode:expr, $abbr:expr ) => {
        $crate::options::OptionSetEx {
            long: $long, short: $short, mode: $mode, allow_abbreviations: $abbr
        }
    };
    ( $long:expr, $short:expr ) => {
        $crate::options::OptionSetEx {
            long: $long, short: $short, mode: $crate::options::OptionsMode::Standard,
            allow_abbreviations: true
        }
    };
    () => { gong_option_set!(vec![], vec![]) };
}

/// Construct an [`OptionSet`](options/struct.OptionSet.html)
///
/// Takes:
///
/// 1. An array of long options
/// 2. An array of short options
/// 3. Mode
/// 4. Abbreviation support state
///
/// The last two can be left off if both defaults.
///
/// Example:
///
/// ```rust
/// # #[macro_use]
/// # extern crate gong;
/// # fn main() {
/// // Without modes, empty option lists
/// let _ = gong_option_set_fixed!([], []);
/// // With modes, empty option lists
/// let _ = gong_option_set_fixed!([], [], gong::options::OptionsMode::Standard, true);
/// # }
/// ```
#[macro_export]
macro_rules! gong_option_set_fixed {
    ( $long:tt, $short:tt, $mode:expr, $abbr:expr ) => {
        $crate::options::OptionSet {
            long: &$long, short: &$short, mode: $mode, allow_abbreviations: $abbr
        }
    };
    ( $long:tt, $short:tt ) => {
        $crate::options::OptionSet {
            long: &$long, short: &$short, mode: $crate::options::OptionsMode::Standard,
            allow_abbreviations: true
        }
    };
    () => { gong_option_set_fixed!([], []) };
}

/// Construct a [`LongOption`](options/struct.LongOption.html)
///
/// Takes:
///
/// 1. Option name
/// 2. Boolean indicating whether or not it takes a data arg (optional, defaults to false)
#[macro_export]
macro_rules! gong_longopt {
    ( $name:expr, $data:expr ) => {
        $crate::options::LongOption { name: $name, expects_data: $data }
    };
    ( $name:expr ) => { $crate::options::LongOption { name: $name, expects_data: false } };
}

/// Construct a [`ShortOption`](options/struct.ShortOption.html)
///
/// Takes:
///
/// 1. Option char
/// 2. Boolean indicating whether or not it takes a data arg (optional, defaults to false)
#[macro_export]
macro_rules! gong_shortopt {
    ( $ch:expr, $data:expr ) => { $crate::options::ShortOption { ch: $ch, expects_data: $data } };
    ( $ch:expr ) => { $crate::options::ShortOption { ch: $ch, expects_data: false } };
}