PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/lib/cli/internal/clarg_boolean.e

http://github.com/tybor/Liberty
Specman e | 188 lines | 144 code | 21 blank | 23 comment | 12 complexity | e5ed64108dc30380ba1aada4752ffb2b MD5 | raw file
  1-- This file is part of a Liberty Eiffel library.
  2-- See the full copyright at the end.
  3--
  4class CLARG_BOOLEAN
  5
  6inherit
  7   COMMAND_LINE_TYPED_ARGUMENT[BOOLEAN]
  8      redefine
  9         out_in_tagged_out_memory
 10      end
 11
 12insert
 13   ARGUMENTS
 14      redefine
 15         out_in_tagged_out_memory
 16      end
 17   CLARG_OPTIONS
 18      redefine
 19         out_in_tagged_out_memory
 20      end
 21
 22create {COMMAND_LINE_ARGUMENT_FACTORY}
 23   make
 24
 25feature {ANY}
 26   item: BOOLEAN
 27
 28   usage: FIXED_STRING
 29
 30   is_mandatory: BOOLEAN False
 31   can_be_mandatory: BOOLEAN False
 32   is_optional: BOOLEAN True
 33   can_be_optional: BOOLEAN True
 34   is_positional: BOOLEAN False
 35   is_repeatable: BOOLEAN False
 36
 37   is_set: BOOLEAN
 38      do
 39         Result := item
 40      end
 41
 42   force_index (a_index: INTEGER)
 43      do
 44         check False end
 45      end
 46
 47   out_in_tagged_out_memory
 48      do
 49         if long /= Void then
 50            tagged_out_memory.append(once "--")
 51            tagged_out_memory.append(long)
 52         else
 53            tagged_out_memory.append(once "-")
 54            tagged_out_memory.append(short)
 55         end
 56      end
 57
 58feature {COMMAND_LINE_ARGUMENTS, COMMAND_LINE_ARGUMENT}
 59   prepare_parse
 60      do
 61         item := False
 62      end
 63
 64   parse_command_line (context: COMMAND_LINE_CONTEXT): COMMAND_LINE_CONTEXT
 65      local
 66         arg: STRING
 67      do
 68         Result := context
 69         if context.is_short then
 70            if is_short(argument(context.index), context.short_option_index) then
 71               item := True
 72               Result.set_index(context.index)
 73               Result.set_short(context.short_index, context.short_option_index + 1)
 74            elseif argument_count >= context.short_index and then is_long(argument(context.short_index)) then
 75               item := True
 76               Result.set_index(context.short_index + 1)
 77            end
 78         elseif argument_count >= context.index then
 79            arg := argument(context.index)
 80            if is_short(arg, 1) then
 81               item := True
 82               Result.set_index(context.index)
 83               Result.set_short(context.index + 1, context.short_option_index + 1)
 84            elseif is_long(arg) then
 85               item := True
 86               Result.set_index(context.index + 1)
 87            end
 88         end
 89      end
 90
 91   is_set_at (context: COMMAND_LINE_CONTEXT): BOOLEAN
 92      do
 93         Result := item
 94      end
 95
 96   undo_parse (context: COMMAND_LINE_CONTEXT)
 97      do
 98         item := False
 99      end
100
101   usage_summary (stream: OUTPUT_STREAM)
102      do
103         if short /= Void then
104            if long /= Void then
105               stream.put_character('(')
106               put_short(stream)
107               stream.put_character('|')
108               put_long(stream)
109               stream.put_character(')')
110            else
111               put_short(stream)
112            end
113         elseif long /= Void then
114            put_long(stream)
115         end
116         detailed := False
117      end
118
119   usage_details (stream: OUTPUT_STREAM)
120      do
121         if not detailed then
122            usage_summary(stream)
123            stream.put_character(':')
124            stream.put_character(' ')
125            if usage /= Void then
126               stream.put_line(usage)
127            else
128               stream.put_line(once "Set the flag.")
129            end
130            detailed := True
131         end
132      end
133
134   set_mandatory (parent_option: like Current; enable: BOOLEAN)
135      do
136         check False end
137      end
138
139feature {}
140   make (a_short, a_long, a_usage: ABSTRACT_STRING)
141      require
142         a_short /= Void implies a_short.count = 1
143         a_short /= Void or else a_long /= Void
144      do
145         if a_short /= Void then
146            short := a_short.intern
147         end
148         if a_long /= Void then
149            long := a_long.intern
150         end
151         if a_usage /= Void then
152            usage := a_usage.intern
153         end
154      ensure
155         a_short /= Void implies short.is_equal(a_short)
156         a_long /= Void implies long.is_equal(a_long)
157         a_usage /= Void implies usage.is_equal(a_usage)
158      end
159
160   parent: like Current
161
162   detailed: BOOLEAN
163
164invariant
165   parent = Void
166   is_optional
167
168end -- class CLARG_BOOLEAN
169--
170-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
171--
172-- Permission is hereby granted, free of charge, to any person obtaining a copy
173-- of this software and associated documentation files (the "Software"), to deal
174-- in the Software without restriction, including without limitation the rights
175-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
176-- copies of the Software, and to permit persons to whom the Software is
177-- furnished to do so, subject to the following conditions:
178--
179-- The above copyright notice and this permission notice shall be included in
180-- all copies or substantial portions of the Software.
181--
182-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
183-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
184-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
185-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
186-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
187-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
188-- THE SOFTWARE.