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

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