comparison tango/tango/net/cluster/tina/CmdParser.d @ 132:1700239cab2e trunk

[svn r136] MAJOR UNSTABLE UPDATE!!! Initial commit after moving to Tango instead of Phobos. Lots of bugfixes... This build is not suitable for most things.
author lindquist
date Fri, 11 Jan 2008 17:57:40 +0100
parents
children
comparison
equal deleted inserted replaced
131:5825d48b27d1 132:1700239cab2e
1 /*******************************************************************************
2
3 copyright: Copyright (c) 2004 Kris Bell. All rights reserved
4
5 license: BSD style: $(LICENSE)
6
7 version: July 2004: Initial release
8
9 author: Kris
10
11 *******************************************************************************/
12
13 module tango.net.cluster.tina.CmdParser;
14
15 private import tango.util.ArgParser;
16
17 private import tango.text.convert.Integer;
18
19 private import tango.util.log.Log,
20 tango.util.log.Configurator;
21
22 /******************************************************************************
23
24 Extends the ArgParser to support/extract common arguments
25
26 ******************************************************************************/
27
28 class CmdParser : ArgParser
29 {
30 Logger log;
31 ushort port;
32 uint size;
33 bool help;
34
35 /**********************************************************************
36
37 **********************************************************************/
38
39 this (char[] name)
40 {
41 log = Log.getLogger (name);
42
43 // default logging is info, not trace
44 log.setLevel (log.Level.Info);
45 }
46
47 /**********************************************************************
48
49 **********************************************************************/
50
51 void parse (char[][] args)
52 {
53 static char[] strip (char[] value)
54 {
55 if (value.length && (value[0] is '=' || value [0] is ':'))
56 value = value[1..$];
57 return value;
58 }
59
60 static int toInt (char[] value)
61 {
62 return atoi (strip(value));
63 }
64
65 bind ("-", "h", {help = true;});
66
67 bind ("-", "log", delegate (char[] value)
68 {log.setLevel(Log.level(strip(value)));});
69
70 bind ("-", "port", delegate (char[] value)
71 {port = cast(ushort) toInt (value);});
72
73 bind ("-", "size", delegate (char[] value)
74 {size = toInt (value);});
75
76 super.parse (args);
77 }
78 }