/src/lib/cli/internal/clarg_options.e

http://github.com/tybor/Liberty · Specman e · 111 lines · 78 code · 10 blank · 23 comment · 4 complexity · 46282d6d07308cc0dd3b68ebca87d2f8 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. deferred class CLARG_OPTIONS
  5. feature {ANY}
  6. short: FIXED_STRING
  7. long: FIXED_STRING
  8. feature {} -- patterns
  9. short_pattern: REGULAR_EXPRESSION
  10. local
  11. re: REGULAR_EXPRESSION_BUILDER
  12. once
  13. Result := re.convert_python_pattern("^(?:-|/)(?P<options>[A-Za-z0-9]+)$")
  14. end
  15. long_pattern: REGULAR_EXPRESSION
  16. local
  17. re: REGULAR_EXPRESSION_BUILDER
  18. once
  19. Result := re.convert_python_pattern("^(?:--)(?P<name>[A-Za-z0-9]([A-Za-z0-9_-]*[A-Za-z0-9])?)$")
  20. end
  21. long_equal_pattern: REGULAR_EXPRESSION
  22. local
  23. re: REGULAR_EXPRESSION_BUILDER
  24. once
  25. Result := re.convert_python_pattern("^(?:--)(?P<name>[A-Za-z0-9]([A-Za-z0-9_-]*[A-Za-z0-9])?)=(?P<value>.+)$")
  26. end
  27. feature {} -- queries
  28. is_short (arg: STRING; a_index: INTEGER): BOOLEAN
  29. require
  30. short /= Void
  31. local
  32. options: STRING
  33. do
  34. if short_pattern.match(arg) and then short_pattern.named_group_matched(once "options") then
  35. options := short_pattern.named_group_value(arg, once "options")
  36. if options.valid_index(a_index) then
  37. Result := options.item(a_index) = short.first
  38. end
  39. end
  40. end
  41. is_long (arg: STRING): BOOLEAN
  42. require
  43. long /= Void
  44. local
  45. name_: FIXED_STRING
  46. do
  47. if long_pattern.match(arg) and then long_pattern.named_group_matched(once "name") then
  48. name_ := long_pattern.named_group_value(arg, once "name").intern
  49. Result := name_ = long
  50. end
  51. end
  52. is_long_equal (arg: STRING): BOOLEAN
  53. require
  54. long /= Void
  55. local
  56. name_: FIXED_STRING
  57. do
  58. if long_equal_pattern.match(arg) and then long_equal_pattern.named_group_matched(once "name") then
  59. name_ := long_equal_pattern.named_group_value(arg, once "name").intern
  60. Result := name_ = long
  61. end
  62. ensure
  63. Result implies long_equal_pattern.named_group_matched(once "value")
  64. end
  65. feature {} -- usage output helpers
  66. put_short (stream: OUTPUT_STREAM)
  67. require
  68. short /= Void
  69. do
  70. stream.put_character('-')
  71. stream.put_character(short.first)
  72. end
  73. put_long (stream: OUTPUT_STREAM)
  74. require
  75. long /= Void
  76. do
  77. stream.put_character('-')
  78. stream.put_character('-')
  79. stream.put_string(long)
  80. end
  81. end -- class CLARG_OPTIONS
  82. --
  83. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  84. --
  85. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  86. -- of this software and associated documentation files (the "Software"), to deal
  87. -- in the Software without restriction, including without limitation the rights
  88. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  89. -- copies of the Software, and to permit persons to whom the Software is
  90. -- furnished to do so, subject to the following conditions:
  91. --
  92. -- The above copyright notice and this permission notice shall be included in
  93. -- all copies or substantial portions of the Software.
  94. --
  95. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  96. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  97. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  98. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  99. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  100. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  101. -- THE SOFTWARE.