| 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 |
Example shows how to show defined options for user. |
|---|
| 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(char[][] args) { |
|---|
| 32 |
try { |
|---|
| 33 |
auto desc = new RegularOptions("Allowed options"); |
|---|
| 34 |
desc.options() |
|---|
| 35 |
("help", "produce help message") |
|---|
| 36 |
("optimization", define!(int).defaultValue(10), "optimization level") |
|---|
| 37 |
("include-path,I", define!(char[][]), "include path") |
|---|
| 38 |
("input-file", define!(char[][]), "input file") |
|---|
| 39 |
; |
|---|
| 40 |
|
|---|
| 41 |
auto spec = new CommandLineOptions; |
|---|
| 42 |
spec.options() |
|---|
| 43 |
("input-file=*", new PositionalOption) |
|---|
| 44 |
("selfdir", new SelfDir) |
|---|
| 45 |
("selfname", new SelfName) |
|---|
| 46 |
; |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
auto po = (new ProgramOptions).next( |
|---|
| 51 |
(new CommandLineStorage(args)) |
|---|
| 52 |
.options(desc, spec) |
|---|
| 53 |
.caption("Usage: OptionsDescription [options]") |
|---|
| 54 |
); |
|---|
| 55 |
|
|---|
| 56 |
po.connect; |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
if ("help" in po) { |
|---|
| 60 |
writefln(po); |
|---|
| 61 |
|
|---|
| 62 |
writefln("Program directory : ", po["selfdir"].as!(char[])); |
|---|
| 63 |
writefln("Program name : ", po["selfname"].as!(char[])); |
|---|
| 64 |
return 0; |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
if ("include-path" in po) { |
|---|
| 68 |
writefln("Include paths are: ", po["include-path"].as!(char[][])); |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
if ("input-file" in po) { |
|---|
| 72 |
writefln("Input files are: ", po["input-file"].as!(char[][])); |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
writefln("Optimization level is ", po["optimization"].as!(int)); |
|---|
| 76 |
|
|---|
| 77 |
po.disconnect; |
|---|
| 78 |
} |
|---|
| 79 |
catch(ProgramOptionsException e) { |
|---|
| 80 |
writefln(e); |
|---|
| 81 |
return 1; |
|---|
| 82 |
} |
|---|
| 83 |
return 0; |
|---|
| 84 |
} |
|---|