PageRenderTime 24ms CodeModel.GetById 16ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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