/src/lib/cli/command_line_argument.e

http://github.com/tybor/Liberty · Specman e · 131 lines · 76 code · 14 blank · 41 comment · 0 complexity · 4808daf4d657e9caa1d2b9a548d1303d 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 COMMAND_LINE_ARGUMENT
  5. --
  6. -- Represents a (semantically unique) command-line argument (option or positional alike).
  7. -- The semantics of a command-line argument depends on how it is created, and includes:
  8. -- * arguments conjunction (a "set" of arguments)
  9. -- * arguments disjunction (a mutually exclusive set of arguments)
  10. -- * options (which may be mandatory)
  11. -- * positional arguments (which may be fixed at a given index)
  12. --
  13. -- "Simple" options and positional arguments may be set zero times (if not `is_mandatory'), once, or more
  14. -- (if `is_repeatable'), depending on the argument configuration.
  15. --
  16. feature {ANY}
  17. infix "or", infix "or else" (other: COMMAND_LINE_ARGUMENT): COMMAND_LINE_ARGUMENT
  18. -- Arguments disjunction. Useful to implement mutually exclusive sets of arguments.
  19. require
  20. other /= Void
  21. do
  22. create {CLARG_OR} Result.make(Current, other)
  23. ensure
  24. Result /= Void
  25. end
  26. infix "and", infix "and then" (other: COMMAND_LINE_ARGUMENT): COMMAND_LINE_ARGUMENT
  27. -- Arguments conjunction. All the arguments are checked, in any order.
  28. require
  29. other /= Void
  30. do
  31. create {CLARG_AND} Result.make(Current, other)
  32. ensure
  33. Result /= Void
  34. end
  35. prefix "not": COMMAND_LINE_ARGUMENT
  36. -- (tentative; don't use it, the semantics is not well defined)
  37. do
  38. create {CLARG_NOT} Result.make(Current)
  39. ensure
  40. Result /= Void
  41. end
  42. feature {ANY}
  43. is_set: BOOLEAN
  44. -- True if the option is present and correct.
  45. deferred
  46. end
  47. is_mandatory: BOOLEAN
  48. -- True if the argument must be present.
  49. deferred
  50. end
  51. is_repeatable: BOOLEAN
  52. -- True if the argument is repeatable; False if unique.
  53. deferred
  54. end
  55. feature {COMMAND_LINE_ARGUMENTS, COMMAND_LINE_ARGUMENT}
  56. prepare_parse
  57. deferred
  58. ensure
  59. not is_set
  60. end
  61. parse_command_line (context: COMMAND_LINE_CONTEXT): COMMAND_LINE_CONTEXT
  62. require
  63. context.is_parsed
  64. deferred
  65. end
  66. undo_parse (context: COMMAND_LINE_CONTEXT)
  67. require
  68. is_set_at(context)
  69. deferred
  70. ensure
  71. not is_set_at(context)
  72. ;(not is_repeatable) implies not is_set
  73. end
  74. is_set_at (context: COMMAND_LINE_CONTEXT): BOOLEAN
  75. -- True if the option is present and correct at the given context.
  76. require
  77. context.is_parsed
  78. deferred
  79. ensure
  80. Result implies is_set
  81. ;(not is_repeatable) implies (Result = is_set)
  82. end
  83. usage_summary (stream: OUTPUT_STREAM)
  84. deferred
  85. ensure
  86. not detailed
  87. end
  88. usage_details (stream: OUTPUT_STREAM)
  89. deferred
  90. ensure
  91. detailed
  92. end
  93. feature {}
  94. detailed: BOOLEAN
  95. deferred
  96. end
  97. end -- class COMMAND_LINE_ARGUMENT
  98. --
  99. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  100. --
  101. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  102. -- of this software and associated documentation files (the "Software"), to deal
  103. -- in the Software without restriction, including without limitation the rights
  104. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  105. -- copies of the Software, and to permit persons to whom the Software is
  106. -- furnished to do so, subject to the following conditions:
  107. --
  108. -- The above copyright notice and this permission notice shall be included in
  109. -- all copies or substantial portions of the Software.
  110. --
  111. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  112. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  113. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  114. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  115. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  116. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  117. -- THE SOFTWARE.