/src/lib/cli/internal/clarg_customs.e

http://github.com/tybor/Liberty · Specman e · 100 lines · 68 code · 9 blank · 23 comment · 2 complexity · ec113c22cc17105c197f863ed1a33f2f 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_CUSTOMS[D_]
  5. inherit
  6. CLARG_WITH_ARGS[D_]
  7. rename
  8. optional as clarg_optional
  9. positional as clarg_positional
  10. decode as decode_
  11. end
  12. create {COMMAND_LINE_ARGUMENT_FACTORY}
  13. optional, positional
  14. feature {CLARG_PARSER}
  15. is_valid_data (arg: STRING): BOOLEAN
  16. local
  17. default_value: D_
  18. do
  19. if validate /= Void then
  20. Result := validate.item([arg])
  21. elseif default_value = Void then -- because of SmartEiffel's strict equality checks
  22. Result := decode.item([arg]) /= default_value
  23. else
  24. Result := True
  25. end
  26. end
  27. feature {}
  28. decode_ (arg: STRING): D_
  29. do
  30. Result := decode.item([arg])
  31. end
  32. feature {}
  33. optional (a_short, a_long, a_name, a_usage: ABSTRACT_STRING; a_validate: like validate; a_decode: like decode)
  34. require
  35. a_short /= Void implies a_short.count = 1
  36. a_short /= Void or else a_long /= Void
  37. a_name /= Void
  38. a_decode /= Void
  39. do
  40. clarg_optional(a_short, a_long, a_name, a_usage)
  41. validate := a_validate
  42. decode := a_decode
  43. ensure
  44. is_optional
  45. a_short /= Void implies short.is_equal(a_short)
  46. a_long /= Void implies long.is_equal(a_long)
  47. name.is_equal(a_name)
  48. a_usage /= Void implies usage.is_equal(a_usage)
  49. validate = a_validate
  50. decode = a_decode
  51. end
  52. positional (a_name, a_usage: ABSTRACT_STRING; a_validate: like validate; a_decode: like decode)
  53. require
  54. a_name /= Void
  55. a_decode /= Void
  56. do
  57. clarg_positional(a_name, a_usage)
  58. validate := a_validate
  59. decode := a_decode
  60. ensure
  61. is_positional
  62. name.is_equal(a_name)
  63. a_usage /= Void implies usage.is_equal(a_usage)
  64. validate = a_validate
  65. decode = a_decode
  66. end
  67. validate: PREDICATE[TUPLE[STRING]]
  68. decode: FUNCTION[TUPLE[STRING], D_]
  69. invariant
  70. decode /= Void
  71. end -- CLARG_CUSTOMS
  72. --
  73. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  74. --
  75. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  76. -- of this software and associated documentation files (the "Software"), to deal
  77. -- in the Software without restriction, including without limitation the rights
  78. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  79. -- copies of the Software, and to permit persons to whom the Software is
  80. -- furnished to do so, subject to the following conditions:
  81. --
  82. -- The above copyright notice and this permission notice shall be included in
  83. -- all copies or substantial portions of the Software.
  84. --
  85. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  86. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  87. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  88. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  89. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  90. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  91. -- THE SOFTWARE.