/src/lib/cli/internal/clarg_custom.e

http://github.com/tybor/Liberty · Specman e · 112 lines · 78 code · 11 blank · 23 comment · 2 complexity · 2aaad4840319d4a684a5b43a7018fa56 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_CUSTOM[D_]
  5. inherit
  6. CLARG_WITH_ARG[D_]
  7. rename
  8. optional as clarg_optional
  9. positional as clarg_positional
  10. end
  11. create {COMMAND_LINE_ARGUMENT_FACTORY}
  12. optional, positional
  13. feature {ANY}
  14. item: D_
  15. is_set: BOOLEAN
  16. feature {CLARG_PARSER}
  17. is_valid_data (arg: STRING): BOOLEAN
  18. local
  19. default_value: D_
  20. do
  21. if validate /= Void then
  22. Result := validate.item([arg])
  23. elseif default_value = Void then -- because of SmartEiffel's strict equality checks
  24. Result := decode.item([arg]) /= default_value
  25. else
  26. Result := True
  27. end
  28. end
  29. feature {}
  30. set_data (context: COMMAND_LINE_CONTEXT; arg: STRING)
  31. do
  32. item := decode.item([arg])
  33. is_set := True
  34. end
  35. unset
  36. local
  37. default_value: D_
  38. do
  39. item := default_value
  40. is_set := False
  41. end
  42. feature {}
  43. optional (a_short, a_long, a_name, a_usage: ABSTRACT_STRING; a_validate: like validate; a_decode: like decode)
  44. require
  45. a_short /= Void implies a_short.count = 1
  46. a_short /= Void or else a_long /= Void
  47. a_name /= Void
  48. a_decode /= Void
  49. do
  50. clarg_optional(a_short, a_long, a_name, a_usage)
  51. validate := a_validate
  52. decode := a_decode
  53. ensure
  54. is_optional
  55. a_short /= Void implies short.is_equal(a_short)
  56. a_long /= Void implies long.is_equal(a_long)
  57. name.is_equal(a_name)
  58. a_usage /= Void implies usage.is_equal(a_usage)
  59. validate = a_validate
  60. decode = a_decode
  61. end
  62. positional (a_name, a_usage: ABSTRACT_STRING; a_validate: like validate; a_decode: like decode)
  63. require
  64. a_name /= Void
  65. a_decode /= Void
  66. do
  67. clarg_positional(a_name, a_usage)
  68. validate := a_validate
  69. decode := a_decode
  70. ensure
  71. is_positional
  72. name.is_equal(a_name)
  73. a_usage /= Void implies usage.is_equal(a_usage)
  74. validate = a_validate
  75. decode = a_decode
  76. end
  77. validate: PREDICATE[TUPLE[STRING]]
  78. decode: FUNCTION[TUPLE[STRING], D_]
  79. invariant
  80. decode /= Void
  81. end -- CLARG_CUSTOM
  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.