PageRenderTime 17ms CodeModel.GetById 14ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/src/lib/cli/internal/clarg_remaining.e

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