/src/tools/main/liberty_main.e
Specman e | 139 lines | 103 code | 19 blank | 17 comment | 3 complexity | d0dbce6e4f848544b238ea13717adcd6 MD5 | raw file
1-- This file is part of Liberty Eiffel. 2-- 3-- Liberty Eiffel is free software: you can redistribute it and/or modify 4-- it under the terms of the GNU General Public License as published by 5-- the Free Software Foundation, version 3 of the License. 6-- 7-- Liberty Eiffel is distributed in the hope that it will be useful, 8-- but WITHOUT ANY WARRANTY; without even the implied warranty of 9-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10-- GNU General Public License for more details. 11-- 12-- You should have received a copy of the GNU General Public License 13-- along with Liberty Eiffel. If not, see <http://www.gnu.org/licenses/>. 14-- 15deferred class LIBERTY_MAIN 16 -- 17 -- Provides a common structure for Liberty tools. 18 -- 19 20insert 21 ARGUMENTS 22 LOGGING 23 24feature {} 25 make is 26 local 27 root: LIBERTY_ACTUAL_TYPE 28 root_feature_name: LIBERTY_FEATURE_NAME 29 etc: LIBERTY_ETC 30 log_location: like default_log_location 31 do 32 log_location := default_log_location 33 if not arguments.parse_command_line then 34 arguments.usage(std_error) 35 die_with_code(1) 36 end 37 38 etc.configure_for(arg_loadpath.item, create {LIBERTY_ETC_VISITOR_IMPL}.make("libertyi")) 39 40 set_log(log_location) 41 etc.log_clusters 42 43 create universe.make 44 create root_feature_name.make(arg_root_feature_name.item) 45 46 root := universe.get_type(Void, errors.unknown_position, arg_root_type.item, create {FAST_ARRAY[LIBERTY_ACTUAL_TYPE]}.with_capacity(0)) 47 48 run(root, root_feature_name) 49 end 50 51 arg_loadpath, arg_root_type, arg_root_feature_name: COMMAND_LINE_TYPED_ARGUMENT[FIXED_STRING] 52 opt_variables: COMMAND_LINE_TYPED_ARGUMENT[TRAVERSABLE[FIXED_STRING]] 53 opt_log_level: COMMAND_LINE_TYPED_ARGUMENT[LIBERTY_MAIN_LOG_LEVEL] 54 opt_check_level: COMMAND_LINE_TYPED_ARGUMENT[LIBERTY_MAIN_CHECK_LEVEL] 55 opt_debug: COMMAND_LINE_TYPED_ARGUMENT[BOOLEAN] 56 57 arguments: COMMAND_LINE_ARGUMENTS is 58 local 59 factory: COMMAND_LINE_ARGUMENT_FACTORY 60 log_level_factory: COMMAND_LINE_ARGUMENT_CUSTOM_FACTORY[LIBERTY_MAIN_LOG_LEVEL] 61 check_level_factory: COMMAND_LINE_ARGUMENT_CUSTOM_FACTORY[LIBERTY_MAIN_CHECK_LEVEL] 62 log_level: LIBERTY_MAIN_LOG_LEVEL 63 check_level: LIBERTY_MAIN_CHECK_LEVEL 64 once 65 arg_loadpath := factory.positional_string("loadpath", "The path to the root loadpath.se") 66 arg_root_type := factory.positional_string("root type", "The name of the root type") 67 arg_root_feature_name := factory.positional_string("root feature name", "The name of the creation feature in the root type") 68 opt_variables := factory.option_strings("v", "variable", "variable", "[ 69 var=value -- Set the variable 'var' to 'value'. 70 Useful for plugin paths. For example: 71 -v sys=`se -environment | grep '^SE_SYS=' | cut -c8-` 72 ]") 73 opt_log_level := log_level_factory.option_custom("l", "log", "log level", "The log level: trace, info, warning, error", 74 agent log_level.valid_arg, 75 agent log_level.set) 76 opt_check_level := check_level_factory.option_custom("c", "check", "check level", "The contract checking level: all, invariant, ensure, require, none", 77 agent check_level.valid_arg, 78 agent check_level.set) 79 opt_debug := factory.option_boolean("d", "debug", "Enable debug sections") 80 81 create Result.make(arg_loadpath and arg_root_type and arg_root_feature_name 82 and opt_variables and opt_log_level and opt_check_level and opt_debug 83 and factory.remaining_parameters) 84 end 85 86 usage is 87 do 88 arguments.usage(std_error) 89 die_with_code(1) 90 end 91 92 run (root: LIBERTY_ACTUAL_TYPE; root_feature_name: LIBERTY_FEATURE_NAME) is 93 require 94 root /= Void 95 root_feature_name /= Void 96 deferred 97 end 98 99 set_log (logpath: STRING) is 100 local 101 log_conf: LOG_CONFIGURATION 102 tfr: TEXT_FILE_READ 103 do 104 env.substitute(logpath) 105 create tfr.connect_to(logpath) 106 if not tfr.is_connected then 107 std_error.put_line("Unknown log configuration file: " + logpath) 108 die_with_code(1) 109 end 110 log_conf.load(tfr, agent on_error, agent resolve_path) 111 tfr.disconnect 112 end 113 114 on_error (message: STRING) is 115 do 116 std_error.put_line(message) 117 die_with_code(1) 118 end 119 120 levels: LOG_LEVELS 121 env: LIBERTY_ENVIRONMENT 122 123 default_log_location: STRING is 124 deferred 125 ensure 126 Result /= Void 127 end 128 129 errors: LIBERTY_ERRORS 130 universe: LIBERTY_UNIVERSE 131 132 resolve_path (a_path: STRING): STRING is 133 do 134 Result := once "" 135 Result.copy(a_path) 136 env.substitute(Result) 137 end 138 139end -- class LIBERTY_MAIN