| | 307 | //enum Action { Store, StoreConst, Append, AppendConst, Count, SetTrue, SetFalse, Callback, CallbackFancy, Help } |
|---|
| | 308 | void issue_default(Options results) { |
|---|
| | 309 | // Only set the default if the option doesn't already have a value. |
|---|
| | 310 | char[][]* val = this.name in results.opts; |
|---|
| | 311 | switch (this.action) { |
|---|
| | 312 | case Action.Store, Action.Append: |
|---|
| | 313 | if (val !is null) return; |
|---|
| | 314 | if (this.type == ArgType.String) { |
|---|
| | 315 | results.opts[name] = [default_string]; |
|---|
| | 316 | } else { |
|---|
| | 317 | results.opts[name] = [.toString(default_value)]; |
|---|
| | 318 | } |
|---|
| | 319 | break; |
|---|
| | 320 | case Action.StoreConst, Action.AppendConst: |
|---|
| | 321 | if (val !is null) return; |
|---|
| | 322 | results.opts[name] = [default_string]; |
|---|
| | 323 | break; |
|---|
| | 324 | case Action.SetTrue, Action.SetFalse: |
|---|
| | 325 | if (val !is null) return; |
|---|
| | 326 | if (default_flag) { |
|---|
| | 327 | results.opts[name] = ["1"]; |
|---|
| | 328 | } else { |
|---|
| | 329 | results.opts[name] = ["0"]; |
|---|
| | 330 | } |
|---|
| | 331 | break; |
|---|
| | 332 | default: |
|---|
| | 333 | return; |
|---|
| | 334 | } |
|---|
| | 335 | } |
|---|
| | 412 | return this; |
|---|
| | 413 | } |
|---|
| | 414 | Option def(char[] val) { |
|---|
| | 415 | if ( |
|---|
| | 416 | (this.type != ArgType.String || (this.action != Action.Store && this.action != Action.Append)) && |
|---|
| | 417 | this.action != Action.StoreConst && this.action != Action.AppendConst |
|---|
| | 418 | ) |
|---|
| | 419 | throw new OptionError("Cannot specify string default for non-string option '"~this.name~"'"); |
|---|
| | 420 | this.has_default = true; |
|---|
| | 421 | this.default_string = val; |
|---|
| | 422 | return this; |
|---|
| | 423 | } |
|---|
| | 424 | Option def(int val) { |
|---|
| | 425 | if (this.type != ArgType.Integer || (this.action != Action.Store && this.action != Action.Append)) |
|---|
| | 426 | throw new OptionError("Cannot specify integer default for non-integer option '"~this.name~"'"); |
|---|
| | 427 | this.has_default = true; |
|---|
| | 428 | this.default_value = val; |
|---|
| | 429 | return this; |
|---|
| | 430 | } |
|---|
| | 431 | Option def(bool val) { |
|---|
| | 432 | if (this.action != Action.SetTrue && this.action != Action.SetFalse) |
|---|
| | 433 | throw new OptionError("Cannot specify boolean default for non-flag option '"~this.name~"'"); |
|---|
| | 434 | this.has_default = true; |
|---|
| | 435 | this.default_flag = val; |
|---|