1 module eph.args.arg;
2 
3 import eph.args.param: Parameter;
4 
5 /**
6  * CLI Argument / Flag
7  *
8  * Represents a unique cli flag that can have a short and/or long form.
9  */
10 public class Argument {
11 
12   private char sFlag;
13 
14   private string lFlag;
15 
16   private string desc;
17 
18   private bool isRequired;
19 
20   private bool hasParam;
21 
22   private bool isParamRequired;
23 
24   private uint hits;
25 
26   private string[] vals;
27 
28   public Argument shortFlag(char c) {
29     sFlag = c;
30     return this;
31   }
32 
33   public char shortFlag() const {
34     return sFlag;
35   }
36 
37   public bool hasShortFlag() const {
38     return sFlag == 0;
39   }
40 
41   public Argument longFlag(string l) {
42     lFlag = l;
43     return this;
44   }
45 
46   public string longFlag() const {
47     return lFlag;
48   }
49 
50   public bool hasLongFrom() const {
51     return lFlag != "";
52   }
53 
54   public Argument require() {
55     isRequired = true;
56     return this;
57   }
58 
59   public bool required() const {
60     return isRequired;
61   }
62 
63   public Argument requireParam() {
64     hasParam = true;
65     isParamRequired = true;
66     return this;
67   }
68 
69   public bool paramRequired() const {
70     return isParamRequired;
71   }
72 
73   public Argument optionalParam() {
74     hasParam = true;
75     isParamRequired = false;
76     return this;
77   }
78 
79   public bool hasOptionalParam() const {
80     return hasParam && !this.isParamRequired;
81   }
82 
83   public bool parameterized() const {
84     return hasParam;
85   }
86 
87   public Argument description(string d) {
88     desc = d;
89     return this;
90   }
91 
92   public string description() const {
93     return desc;
94   }
95 
96   public bool hasDescription() const {
97     return desc != "";
98   }
99 
100   public string[] values() {
101     return vals;
102   }
103 
104   public uint uses() const {
105     return hits;
106   }
107 
108   public bool set() const {
109     return hits > 0;
110   }
111 
112   package void value(string val) {
113     vals ~= val;
114   }
115 
116   package void use() {
117     hits++;
118   }
119 }