Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #748: CmdParser.d

File CmdParser.d, 2.1 kB (added by darrylb, 8 months ago)
Line 
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.Arguments;
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 : Arguments
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                 define("h");
54                 define("log").parameters(1);
55                 define("port").parameters(1);
56                 define("size").parameters(1);
57                
58                 super.parse(args);
59                
60                 if ("h" in this)
61                     help = true;
62                 if ("log" in this)
63                     log.setLevel(Log.level(this["log"]));
64                 if ("port" in this)
65                     port = cast(ushort)atoi(this["port"]);
66                 if ("size" in this)
67                     size = atoi(args["size"]);
68         }
69 }