1 /**
2 License:
3 	Boost Software License - Version 1.0 - August 17th, 2003
4 
5 	Permission is hereby granted, free of charge, to any person or organization
6 	obtaining a copy of the software and accompanying documentation covered by
7 	this license (the "Software") to use, reproduce, display, distribute,
8 	execute, and transmit the Software, and to prepare derivative works of the
9 	Software, and to permit third-parties to whom the Software is furnished to
10 	do so, all subject to the following:
11 	
12 	The copyright notices in the Software and this entire statement, including
13 	the above license grant, this restriction and the following disclaimer,
14 	must be included in all copies of the Software, in whole or in part, and
15 	all derivative works of the Software, unless such copies or derivative
16 	works are solely in the form of machine-executable object code generated by
17 	a source language processor.
18 	
19 	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 	FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22 	SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23 	FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24 	ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 	DEALINGS IN THE SOFTWARE.
26 
27 Authors:
28 	aermicioi
29 **/
30 module aermicioi.aedi_property_reader.helper.help_decorating_information_provider;
31 
32 import std.range;
33 
34 /**
35 Interface for objects that write help messages into a sink
36 **/
37 interface HelpInformationProvider {
38 
39 	/**
40 	Write a help message into sink.
41 	
42 	Params: 
43 		sink = the sink where to write the help message
44 	**/
45     void message(scope void delegate(in char[] ch) sink) const;
46 }
47 
48 /**
49 Implementation of HelpInformationProvider that provides help information for command line arguments.
50 **/
51 class ArgumentInformationProvider : HelpInformationProvider {
52     private {
53         
54         string argument_;
55         string separator_ = "\t";
56         string help_;
57     }
58     
59     public {
60         @property {
61 
62 			/**
63 			Set argument
64 			
65 			Params: 
66 				argument = the argument for which help usage is printed
67 			
68 			Returns:
69 				typeof(this)
70 			**/
71         	ArgumentInformationProvider argument(string argument) @safe nothrow {
72         		this.argument_ = argument;
73         	
74         		return this;
75         	}
76         	
77 			/**
78 			Get argument
79 			
80 			Returns:
81 				string
82 			**/
83         	string argument() @safe nothrow const {
84         		return this.argument_;
85         	}
86         	
87 			/**
88 			Set separator
89 			
90 			Params: 
91 				separator = separator string used to separate argument from equal and from message
92 			
93 			Returns:
94 				typeof(this)
95 			**/
96         	ArgumentInformationProvider separator(string separator) @safe nothrow {
97         		this.separator_ = separator;
98         	
99         		return this;
100         	}
101         	
102 			/**
103 			Get separator
104 			
105 			Returns:
106 				string
107 			**/
108         	string separator() @safe nothrow const {
109         		return this.separator_;
110         	}
111         	
112 			/**
113 			Set help
114 			
115 			Params: 
116 				help = help message for argument
117 			
118 			Returns:
119 				typeof(this)
120 			**/
121         	ArgumentInformationProvider help(string help) @safe nothrow {
122         		this.help_ = help;
123         	
124         		return this;
125         	}
126         	
127 			/**
128 			Get help
129 			
130 			Returns:
131 				string
132 			**/
133         	string help() @safe nothrow const {
134         		return this.help_;
135         	}
136         }
137         
138 		/**
139 		Write a help message into sink.
140 		
141 		Params: 
142 			sink = the sink where to write the help message
143 		**/
144         void message(scope void delegate(in char[] ch) sink) const 	{
145             import std.utf;
146     		foreach (ch; chain(this.argument, this.separator, this.help).byChar) {
147     		    char[1] buff;
148     		    buff[0] = ch;
149     		    sink(buff[]);
150     		}
151     	}
152     }
153 }