/src/lib/cli/internal/clarg_or.e
Specman e | 137 lines | 97 code | 17 blank | 23 comment | 5 complexity | 5c242e240d846226ffe59edb5f1aede4 MD5 | raw file
1-- This file is part of a Liberty Eiffel library. 2-- See the full copyright at the end. 3-- 4class CLARG_OR 5 6inherit 7 COMMAND_LINE_ARGUMENT 8 redefine 9 infix "or", infix "or else" 10 end 11 12create {COMMAND_LINE_ARGUMENT} 13 make 14 15feature {ANY} 16 is_repeatable: BOOLEAN False 17 18 infix "or", infix "or else" (other: COMMAND_LINE_ARGUMENT): COMMAND_LINE_ARGUMENT 19 do 20 args.add_last(other) 21 Result := Current 22 end 23 24 is_set: BOOLEAN 25 26 is_mandatory: BOOLEAN 27 do 28 Result := args.for_all(agent {COMMAND_LINE_ARGUMENT}.is_mandatory) 29 end 30 31 is_set_at (context: COMMAND_LINE_CONTEXT): BOOLEAN 32 do 33 Result := args.exists(agent {COMMAND_LINE_ARGUMENT}.is_set_at(context)) 34 end 35 36feature {COMMAND_LINE_ARGUMENTS, COMMAND_LINE_ARGUMENT} 37 prepare_parse 38 do 39 is_set := False 40 args.for_each(agent {COMMAND_LINE_ARGUMENT}.prepare_parse) 41 end 42 43 parse_command_line (context: COMMAND_LINE_CONTEXT): COMMAND_LINE_CONTEXT 44 local 45 i: INTEGER 46 do 47 from 48 Result := args.first.parse_command_line(context) 49 if Result.is_parsed then 50 is_set := args.first.is_set 51 else 52 undo_parse(Result) 53 end 54 i := args.lower + 1 55 until 56 is_set or else i > args.upper 57 loop 58 Result := args.item(i).parse_command_line(context) 59 if Result.is_parsed then 60 is_set := args.item(i).is_set 61 else 62 undo_parse(Result) 63 end 64 i := i + 1 65 end 66 end 67 68 usage_summary (stream: OUTPUT_STREAM) 69 local 70 i: INTEGER 71 do 72 stream.put_character('[') 73 from 74 i := args.lower 75 until 76 i > args.upper 77 loop 78 if i > args.lower then 79 stream.put_character('|') 80 end 81 args.item(i).usage_summary(stream) 82 i := i + 1 83 end 84 stream.put_character(']') 85 detailed := False 86 end 87 88 usage_details (stream: OUTPUT_STREAM) 89 do 90 if not detailed then 91 args.for_each(agent {COMMAND_LINE_ARGUMENT}.usage_details(stream)) 92 detailed := True 93 end 94 end 95 96 undo_parse (context: COMMAND_LINE_CONTEXT) 97 do 98 args.for_each(agent {COMMAND_LINE_ARGUMENT}.undo_parse(context)) 99 end 100 101feature {} 102 args: FAST_ARRAY[COMMAND_LINE_ARGUMENT] 103 104 make (a_left, a_right: COMMAND_LINE_ARGUMENT) 105 require 106 a_left /= Void 107 a_right /= Void 108 do 109 args := {FAST_ARRAY[COMMAND_LINE_ARGUMENT] << a_left, a_right >> } 110 end 111 112 detailed: BOOLEAN 113 114invariant 115 args.count >= 2 116 117end -- class CLARG_OR 118-- 119-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file. 120-- 121-- Permission is hereby granted, free of charge, to any person obtaining a copy 122-- of this software and associated documentation files (the "Software"), to deal 123-- in the Software without restriction, including without limitation the rights 124-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 125-- copies of the Software, and to permit persons to whom the Software is 126-- furnished to do so, subject to the following conditions: 127-- 128-- The above copyright notice and this permission notice shall be included in 129-- all copies or substantial portions of the Software. 130-- 131-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 132-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 133-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 134-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 135-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 136-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 137-- THE SOFTWARE.