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
use super::GetWithDefault; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; use structopt::StructOpt; /// This struct provides the `--host` and `-H` cli option to get an IPv4 address /// /// No default is provided /// /// ```rust /// extern crate structopt_flags; /// #[macro_use] /// extern crate structopt; /// /// use std::net::Ipv4Addr; /// use structopt::StructOpt; /// use structopt_flags::GetWithDefault; // to access get_with_default /// /// #[derive(Debug, StructOpt)] /// #[structopt(name = "ipv4_opt", about = "An example using the HostV4Opt option")] /// struct Opt { /// #[structopt(flatten)] /// host_ip: structopt_flags::HostV4Opt, /// } /// /// fn main() { /// let opt = Opt::from_args(); /// let ipv4 = opt.host_ip.get_with_default(Ipv4Addr::new(127,0,0,1)); /// } /// ``` #[derive(StructOpt, Debug, Clone)] pub struct HostV4Opt { /// Set the host IP (Ipv4 only) #[structopt(name = "hostv4", long = "host", short = "-H", raw(global = "true"))] host_addr: Option<Ipv4Addr>, } impl GetWithDefault for HostV4Opt { type Item = Ipv4Addr; fn get_with_default<T: Into<Self::Item>>(&self, default: T) -> Self::Item { self.host_addr.unwrap_or_else(|| default.into()) } } /// This struct provides the `--host` and `-H` cli option to get an IPv4 address /// /// No default is provided and the parameter is mandatory /// This option is not global /// /// ```should_panic /// extern crate structopt_flags; /// #[macro_use] /// extern crate structopt; /// /// use std::net::Ipv4Addr; /// use structopt::StructOpt; /// /// #[derive(Debug, StructOpt)] /// #[structopt(name = "ipv4_param", about = "An example using the HostV4Param option")] /// struct Opt { /// #[structopt(flatten)] /// host_ip: structopt_flags::HostV4Param, /// } /// /// fn main() { /// let opt = Opt::from_args(); /// let ipv4 = opt.host_ip.host_addr; /// } /// ``` #[derive(StructOpt, Debug, Clone)] pub struct HostV4Param { /// Set the host IP (Ipv4 only) #[structopt(name = "hostv4", long = "host", short = "-H")] pub host_addr: Ipv4Addr, } /// This struct provides the `--host` and `-H` cli option to get an IPv6 address /// /// No default is provided /// /// ```rust /// extern crate structopt_flags; /// #[macro_use] /// extern crate structopt; /// /// use std::net::Ipv6Addr; /// use structopt::StructOpt; /// use structopt_flags::GetWithDefault; // to access get_with_default /// /// #[derive(Debug, StructOpt)] /// #[structopt(name = "ipv6_opt", about = "An example using the HostV6Opt option")] /// struct Opt { /// #[structopt(flatten)] /// host_ip: structopt_flags::HostV6Opt, /// } /// /// fn main() { /// let opt = Opt::from_args(); /// let ipv6 = opt.host_ip.get_with_default(Ipv6Addr::new(0,0,0,0,0,0,0,1)); /// } /// ``` #[derive(StructOpt, Debug, Clone)] pub struct HostV6Opt { /// Set the host IP (Ipv6 only) #[structopt(name = "hostv6", long = "host", short = "-H", raw(global = "true"))] host_addr: Option<Ipv6Addr>, } impl GetWithDefault for HostV6Opt { type Item = Ipv6Addr; fn get_with_default<T: Into<Self::Item>>(&self, default: T) -> Self::Item { self.host_addr.unwrap_or_else(|| default.into()) } } /// This struct provides the `--host` and `-H` cli option to get an IPv6 address /// /// No default is provided and the parameter is mandatory /// This option is not global /// /// ```should_panic /// extern crate structopt_flags; /// #[macro_use] /// extern crate structopt; /// /// use std::net::Ipv6Addr; /// use structopt::StructOpt; /// /// #[derive(Debug, StructOpt)] /// #[structopt(name = "ipv6_param", about = "An example using the HostV6Param option")] /// struct Opt { /// #[structopt(flatten)] /// host_ip: structopt_flags::HostV6Param, /// } /// /// fn main() { /// let opt = Opt::from_args(); /// let ipv6 = opt.host_ip.host_addr; /// } /// ``` #[derive(StructOpt, Debug, Clone)] pub struct HostV6Param { /// Set the host IP (Ipv6 only) #[structopt(name = "hostv6", long = "host", short = "-H")] pub host_addr: Ipv6Addr, } /// This struct provides the `--host` and `-H` cli option to get ageneric IP address /// /// No default is provided /// /// ```rust /// extern crate structopt_flags; /// #[macro_use] /// extern crate structopt; /// /// use std::net::{IpAddr,Ipv6Addr}; /// use structopt::StructOpt; /// use structopt_flags::GetWithDefault; // to access get_with_default /// /// #[derive(Debug, StructOpt)] /// #[structopt(name = "ip_opt", about = "An example using the HostOpt option")] /// struct Opt { /// #[structopt(flatten)] /// host_ip: structopt_flags::HostOpt, /// } /// /// fn main() { /// let opt = Opt::from_args(); /// let ip = opt.host_ip.get_with_default(IpAddr::V6(Ipv6Addr::new(0,0,0,0,0,0,0,1))); /// } /// ``` #[derive(StructOpt, Debug, Clone)] pub struct HostOpt { /// Set the host IP (both IpV4 and IpV6 are supported) #[structopt(name = "host", long = "host", short = "-H", raw(global = "true"))] host_addr: Option<IpAddr>, } impl GetWithDefault for HostOpt { type Item = IpAddr; fn get_with_default<T: Into<Self::Item>>(&self, default: T) -> Self::Item { self.host_addr.unwrap_or_else(|| default.into()) } } /// This struct provides the `--host` and `-H` cli option to get ageneric IP address /// /// No default is provided and the parameter is mandatory /// This option is not global /// /// ```should_panic /// extern crate structopt_flags; /// #[macro_use] /// extern crate structopt; /// /// use std::net::{IpAddr,Ipv6Addr}; /// use structopt::StructOpt; /// /// #[derive(Debug, StructOpt)] /// #[structopt(name = "ip_param", about = "An example using the HostParam option")] /// struct Opt { /// #[structopt(flatten)] /// host_ip: structopt_flags::HostParam, /// } /// /// fn main() { /// let opt = Opt::from_args(); /// let ip = opt.host_ip.host_addr; /// } /// ``` #[derive(StructOpt, Debug, Clone)] pub struct HostParam { /// Set the host IP (both IpV4 and IpV6 are supported) #[structopt(name = "host", long = "host", short = "-H")] pub host_addr: IpAddr, }