PageRenderTime 17ms CodeModel.GetById 14ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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