PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/src/lib/cli/command_line_argument_factory.e

http://github.com/tybor/Liberty
Specman e | 179 lines | 132 code | 19 blank | 28 comment | 8 complexity | 98abda22f7c69492582c6b2044032515 MD5 | raw file
  1-- This file is part of a Liberty Eiffel library.
  2-- See the full copyright at the end.
  3--
  4expanded class COMMAND_LINE_ARGUMENT_FACTORY
  5--
  6-- The command-line arguments factory.
  7--
  8
  9feature {ANY} -- Options
 10   option_string (short, long, name, usage: ABSTRACT_STRING): COMMAND_LINE_TYPED_ARGUMENT[FIXED_STRING]
 11      require
 12         short /= Void implies short_pattern.match(short.out)
 13         long /= Void implies long_pattern.match(long.out)
 14         short /= Void or else long /= Void
 15         name /= Void
 16      do
 17         create {CLARG_STRING} Result.optional(short, long, name, usage)
 18      end
 19
 20   option_strings (short, long, name, usage: ABSTRACT_STRING): COMMAND_LINE_TYPED_ARGUMENT[TRAVERSABLE[FIXED_STRING]]
 21      require
 22         short /= Void implies short_pattern.match(short.out)
 23         long /= Void implies long_pattern.match(long.out)
 24         short /= Void or else long /= Void
 25         name /= Void
 26      do
 27         create {CLARG_STRINGS} Result.optional(short, long, name, usage)
 28      end
 29
 30   option_file (short, long, name, usage: ABSTRACT_STRING): COMMAND_LINE_TYPED_ARGUMENT[REGULAR_FILE]
 31      require
 32         short /= Void implies short_pattern.match(short.out)
 33         long /= Void implies long_pattern.match(long.out)
 34         short /= Void or else long /= Void
 35         name /= Void
 36      do
 37         create {CLARG_FILE} Result.optional(short, long, name, usage)
 38      end
 39
 40   option_directory (short, long, name, usage: ABSTRACT_STRING): COMMAND_LINE_TYPED_ARGUMENT[DIRECTORY]
 41      require
 42         short /= Void implies short_pattern.match(short.out)
 43         long /= Void implies long_pattern.match(long.out)
 44         short /= Void or else long /= Void
 45         name /= Void
 46      do
 47         create {CLARG_DIRECTORY} Result.optional(short, long, name, usage)
 48      end
 49
 50   option_integer (short, long, name, usage: ABSTRACT_STRING): COMMAND_LINE_TYPED_ARGUMENT[INTEGER]
 51      require
 52         short /= Void implies short_pattern.match(short.out)
 53         long /= Void implies long_pattern.match(long.out)
 54         short /= Void or else long /= Void
 55         name /= Void
 56      do
 57         create {CLARG_INTEGER} Result.optional(short, long, name, usage)
 58      end
 59
 60   option_integers (short, long, name, usage: ABSTRACT_STRING): COMMAND_LINE_TYPED_ARGUMENT[TRAVERSABLE[INTEGER]]
 61      require
 62         short /= Void implies short_pattern.match(short.out)
 63         long /= Void implies long_pattern.match(long.out)
 64         short /= Void or else long /= Void
 65         name /= Void
 66      do
 67         create {CLARG_INTEGERS} Result.optional(short, long, name, usage)
 68      end
 69
 70   option_boolean (short, long, usage: ABSTRACT_STRING): COMMAND_LINE_TYPED_ARGUMENT[BOOLEAN]
 71      require
 72         short /= Void implies short_pattern.match(short.out)
 73         long /= Void implies long_pattern.match(long.out)
 74         short /= Void or else long /= Void
 75      do
 76         create {CLARG_BOOLEAN} Result.make(short, long, usage)
 77      end
 78
 79   option_counter (short, long, usage: ABSTRACT_STRING): COMMAND_LINE_TYPED_ARGUMENT[INTEGER]
 80      require
 81         short /= Void implies short_pattern.match(short.out)
 82         long /= Void implies long_pattern.match(long.out)
 83         short /= Void or else long /= Void
 84      do
 85         create {CLARG_COUNTER} Result.make(short, long, usage)
 86      end
 87
 88feature {ANY} -- Positional
 89   positional_string (name, usage: ABSTRACT_STRING): COMMAND_LINE_TYPED_ARGUMENT[FIXED_STRING]
 90      require
 91         name /= Void
 92      do
 93         create {CLARG_STRING} Result.positional(name, usage)
 94      end
 95
 96   positional_strings (name, usage: ABSTRACT_STRING): COMMAND_LINE_TYPED_ARGUMENT[TRAVERSABLE[FIXED_STRING]]
 97      require
 98         name /= Void
 99      do
100         create {CLARG_STRINGS} Result.positional(name, usage)
101      end
102
103   positional_file (name, usage: ABSTRACT_STRING): COMMAND_LINE_TYPED_ARGUMENT[REGULAR_FILE]
104      require
105         name /= Void
106      do
107         create {CLARG_FILE} Result.positional(name, usage)
108      end
109
110   positional_directory (name, usage: ABSTRACT_STRING): COMMAND_LINE_TYPED_ARGUMENT[DIRECTORY]
111      require
112         name /= Void
113      do
114         create {CLARG_DIRECTORY} Result.positional(name, usage)
115      end
116
117   positional_integer (name, usage: ABSTRACT_STRING): COMMAND_LINE_TYPED_ARGUMENT[INTEGER]
118      require
119         name /= Void
120      do
121         create {CLARG_INTEGER} Result.positional(name, usage)
122      end
123
124   positional_integers (name, usage: ABSTRACT_STRING): COMMAND_LINE_TYPED_ARGUMENT[TRAVERSABLE[INTEGER]]
125      require
126         name /= Void
127      do
128         create {CLARG_INTEGERS} Result.positional(name, usage)
129      end
130
131feature {ANY}
132   no_parameters: COMMAND_LINE_ARGUMENT
133         -- useful to allow an empty command line.
134      once
135         create {CLARG_NOP} Result.make
136      end
137
138   remaining_parameters: COMMAND_LINE_TYPED_ARGUMENT[TRAVERSABLE[FIXED_STRING]]
139         -- allows parameters to be set after a special "--" option
140      once
141         create {CLARG_REMAINING} Result.make
142      end
143
144feature {ANY} -- Option names validity
145   short_pattern: REGULAR_EXPRESSION
146      local
147         re: REGULAR_EXPRESSION_BUILDER
148      once
149         Result := re.convert_posix_pattern("^[A-Za-z0-9]$")
150      end
151
152   long_pattern: REGULAR_EXPRESSION
153      local
154         re: REGULAR_EXPRESSION_BUILDER
155      once
156         Result := re.convert_posix_pattern("^[A-Za-z0-9]([A-Za-z0-9_-]*[A-Za-z0-9])?$")
157      end
158
159end -- class COMMAND_LINE_ARGUMENT_FACTORY
160--
161-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
162--
163-- Permission is hereby granted, free of charge, to any person obtaining a copy
164-- of this software and associated documentation files (the "Software"), to deal
165-- in the Software without restriction, including without limitation the rights
166-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
167-- copies of the Software, and to permit persons to whom the Software is
168-- furnished to do so, subject to the following conditions:
169--
170-- The above copyright notice and this permission notice shall be included in
171-- all copies or substantial portions of the Software.
172--
173-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
174-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
175-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
176-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
177-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
178-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
179-- THE SOFTWARE.