| 1 |
/******************************************************************************* |
|---|
| 2 |
|
|---|
| 3 |
License: Boost Software License, v. 1.0 |
|---|
| 4 |
Academic Free License, v. 3.0 |
|---|
| 5 |
BSD License |
|---|
| 6 |
|
|---|
| 7 |
Authors: Marcin Kuszczak, www.zapytajmnie.com (author's christian site) |
|---|
| 8 |
This software is inspired and partially based on Boost C++ |
|---|
| 9 |
library named 'program_options' and created by Vladimir Prus. |
|---|
| 10 |
|
|---|
| 11 |
Version: 0.9.1 |
|---|
| 12 |
Date: 30-Apr-2008 |
|---|
| 13 |
|
|---|
| 14 |
History: 0.9.0 (08-Oct-2007) - initial public version |
|---|
| 15 |
|
|---|
| 16 |
Description: |
|---|
| 17 |
This example program shows simplest usage of library. |
|---|
| 18 |
|
|---|
| 19 |
******************************************************************************/ |
|---|
| 20 |
|
|---|
| 21 |
import std.stdio; |
|---|
| 22 |
|
|---|
| 23 |
import doost.util.config.ProgramOptions; |
|---|
| 24 |
import doost.util.config.CommandLineStorage; |
|---|
| 25 |
|
|---|
| 26 |
//------------------------------------------------------------------------------ |
|---|
| 27 |
|
|---|
| 28 |
/******************************************************************************* |
|---|
| 29 |
Program entry point |
|---|
| 30 |
******************************************************************************/ |
|---|
| 31 |
int main(string[] args) { |
|---|
| 32 |
try { |
|---|
| 33 |
|
|---|
| 34 |
auto desc = new RegularOptions("Allowed options"); |
|---|
| 35 |
desc.options() |
|---|
| 36 |
("help", "produce help message") |
|---|
| 37 |
("compression", define!(int)(), "set compression level") |
|---|
| 38 |
; |
|---|
| 39 |
|
|---|
| 40 |
auto po = (new ProgramOptions).next( |
|---|
| 41 |
(new CommandLineStorage(args)) |
|---|
| 42 |
.options(desc) |
|---|
| 43 |
); |
|---|
| 44 |
|
|---|
| 45 |
po.connect; |
|---|
| 46 |
|
|---|
| 47 |
if ("help" in po) { |
|---|
| 48 |
writefln(desc.describe(new CommandLineFormatter)); |
|---|
| 49 |
return 1; |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
if ("compression" in po) { |
|---|
| 53 |
writefln("Compression level was set to ", po["compression"]); |
|---|
| 54 |
} else { |
|---|
| 55 |
writefln("Compression level was not set."); |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
po.disconnect; |
|---|
| 59 |
} |
|---|
| 60 |
catch(ProgramOptionsException e) { |
|---|
| 61 |
writefln("Exception: ", e); |
|---|
| 62 |
return 1; |
|---|
| 63 |
} |
|---|
| 64 |
return 0; |
|---|
| 65 |
} |
|---|