| 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 |
Real-world example showing more complicated case. |
|---|
| 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 |
void main(char[][] args) { |
|---|
| 32 |
try { |
|---|
| 33 |
auto desc = new RegularOptions("Allowed options"); |
|---|
| 34 |
desc.options() |
|---|
| 35 |
// First parameter describes option name/alias name |
|---|
| 36 |
// The second is parameter to option |
|---|
| 37 |
// The third is description |
|---|
| 38 |
("help,h", "print usage message") |
|---|
| 39 |
("output,o", define!(char[]), "pathname for output") |
|---|
| 40 |
("macrofile,m", define!(char[]), "full pathname of macro.h") |
|---|
| 41 |
("two,t", boolSwitch, "preprocess both header and body") |
|---|
| 42 |
("body,b", boolSwitch, "preprocess body in the header context") |
|---|
| 43 |
("libmakfile,l", define!(char[]), "write include makefile for library") |
|---|
| 44 |
("mainpackage,p", define!(char[]), "output dependency information") |
|---|
| 45 |
("depends,d", define!(char[]).defaultValue("deps_file"), "write dependencies to <pathname>") |
|---|
| 46 |
("sources,s", define!(char[]).defaultValue("src_file"), "write source package list to <pathname>") |
|---|
| 47 |
("root,r", define!(char[]).defaultValue("."), "treat <dirname> as project root directory") |
|---|
| 48 |
; |
|---|
| 49 |
|
|---|
| 50 |
auto po = (new ProgramOptions).next( |
|---|
| 51 |
(new CommandLineStorage(args)) |
|---|
| 52 |
.options(desc) |
|---|
| 53 |
); |
|---|
| 54 |
|
|---|
| 55 |
po.connect; |
|---|
| 56 |
|
|---|
| 57 |
if ("help" in po) { |
|---|
| 58 |
writefln(po); |
|---|
| 59 |
return 0; |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
conflictingOptions(po, "output", "two"); |
|---|
| 63 |
conflictingOptions(po, "output", "body"); |
|---|
| 64 |
conflictingOptions(po, "output", "mainpackage"); |
|---|
| 65 |
conflictingOptions(po, "two", "mainpackage"); |
|---|
| 66 |
conflictingOptions(po, "body", "mainpackage"); |
|---|
| 67 |
|
|---|
| 68 |
conflictingOptions(po, "two", "body"); |
|---|
| 69 |
conflictingOptions(po, "libmakfile", "mainpackage"); |
|---|
| 70 |
conflictingOptions(po, "libmakfile", "mainpackage"); |
|---|
| 71 |
|
|---|
| 72 |
dependantOptions(po, "depends", "mainpackage"); |
|---|
| 73 |
dependantOptions(po, "sources", "mainpackage"); |
|---|
| 74 |
dependantOptions(po, "root", "mainpackage"); |
|---|
| 75 |
|
|---|
| 76 |
writefln ("two = ", po["two"].as!(bool)()); |
|---|
| 77 |
|
|---|
| 78 |
po.disconnect; |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
catch(ProgramOptionsException e) { |
|---|
| 82 |
writefln(e); |
|---|
| 83 |
} |
|---|
| 84 |
} |
|---|