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