Skip to content

Commit 6f49a5d

Browse files
authored
Change command line to not require -path argument (#593)
* JIRA WDT-388 Change command line to not require -path argument * JIRA WDT-388 Remove unused variable
1 parent 16dc4bf commit 6f49a5d

File tree

6 files changed

+54
-22
lines changed

6 files changed

+54
-22
lines changed

core/src/main/python/model_help.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
__logger = PlatformLogger('wlsdeploy.modelhelp')
2525

2626
__required_arguments = [
27-
CommandLineArgUtil.ORACLE_HOME_SWITCH,
28-
CommandLineArgUtil.PATH_SWITCH
27+
CommandLineArgUtil.ORACLE_HOME_SWITCH
2928
]
3029

3130
__optional_arguments = [
@@ -50,7 +49,7 @@ def __process_args(args):
5049
_method_name = '__process_args'
5150

5251
cla_util = CommandLineArgUtil(_program_name, __required_arguments, __optional_arguments)
53-
required_arg_map, optional_arg_map = cla_util.process_args(args)
52+
required_arg_map, optional_arg_map = cla_util.process_args(args, trailing_arg_count=1)
5453

5554
cla_helper.verify_required_args_present(_program_name, __required_arguments, required_arg_map)
5655

@@ -125,7 +124,7 @@ def main(args):
125124
sys.exit(exit_code)
126125

127126
try:
128-
model_path = model_context.get_path()
127+
model_path = model_context.get_trailing_argument(0)
129128
exit_code = print_help(model_path, model_context)
130129
except CLAException, ve:
131130
__logger.severe('WLSDPLY-10112', _program_name, ve.getLocalizedMessage(), error=ve,

core/src/main/python/wlsdeploy/util/cla_utils.py

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class CommandLineArgUtil(object):
4545
MODEL_FILE_SWITCH = '-model_file'
4646
OPSS_WALLET_SWITCH = '-opss_wallet'
4747
OPSS_WALLET_PASSPHRASE = '-opss_wallet_passphrase'
48-
PATH_SWITCH = '-path'
4948
PREVIOUS_MODEL_FILE_SWITCH = '-prev_model_file'
5049
VARIABLE_FILE_SWITCH = '-variable_file'
5150
RCU_DB_SWITCH = '-rcu_db'
@@ -64,6 +63,8 @@ class CommandLineArgUtil(object):
6463
RUN_RCU_SWITCH = '-run_rcu'
6564
TARGET_VERSION_SWITCH = '-target_version'
6665
TARGET_MODE_SWITCH = '-target_mode'
66+
# phony arg used as a key to store the trailing (non-switched) arguments
67+
TRAILING_ARGS_SWITCH = '-trailing_arguments'
6768
ATTRIBUTES_ONLY_SWITCH = '-attributes_only'
6869
FOLDERS_ONLY_SWITCH = '-folders_only'
6970
RECURSIVE_SWITCH = '-recursive'
@@ -131,12 +132,13 @@ def set_allow_multiple_models(self, allow_multiple_models):
131132
"""
132133
self._allow_multiple_models = allow_multiple_models
133134

134-
def process_args(self, args, tool_type=TOOL_TYPE_DEFAULT):
135+
def process_args(self, args, tool_type=TOOL_TYPE_DEFAULT, trailing_arg_count=0):
135136
"""
136137
This method parses the command-line arguments and returns dictionaries of the required and optional args.
137138
138139
:param args: sys.argv
139140
:param tool_type: optional, type of tool for special argument processing
141+
:param trailing_arg_count: optional, the number of trailing (no switch) arguments
140142
:return: the required and optional argument dictionaries
141143
:raises CLAException: if argument processing encounters a usage or validation exception
142144
"""
@@ -156,6 +158,9 @@ def process_args(self, args, tool_type=TOOL_TYPE_DEFAULT):
156158
ex.setExitCode(self.HELP_EXIT_CODE)
157159
raise ex
158160

161+
args = self._check_trailing_arguments(args, trailing_arg_count)
162+
args_len = len(args)
163+
159164
idx = 1
160165
while idx < args_len:
161166
key = args[idx]
@@ -280,9 +285,6 @@ def process_args(self, args, tool_type=TOOL_TYPE_DEFAULT):
280285
value, idx = self._get_arg_value(args, idx, key)
281286
full_path = self._validate_domain_resource_file_arg(value)
282287
self._add_arg(key, full_path, True)
283-
elif self.is_path_key(key):
284-
value, idx = self._get_arg_value(args, idx, key)
285-
self._add_arg(key, value)
286288
elif self.is_boolean_switch(key):
287289
self._add_arg(key, True)
288290
else:
@@ -314,6 +316,38 @@ def _get_arg_value(self, args, index, key):
314316
raise ex
315317
return args[index], index
316318

319+
def _check_trailing_arguments(self, args, trailing_arg_count):
320+
"""
321+
Remove any trailing (no switch) arguments from the argument list and add them to the required result.
322+
example:
323+
command.sh -oracle_home /oracle file1 file2
324+
file1 and file2 are trailing arguments
325+
326+
:param args: the arguments to be examined
327+
:param trailing_arg_count: the number of trailing arguments that are expected
328+
:return: the argument list, with the trailing arguments removed
329+
:raises CLAException: if there are not enough arguments present
330+
"""
331+
method_name = '_check_trailing_arguments'
332+
args_len = len(args)
333+
334+
# verify there are enough arguments for any trailing (no switch) args
335+
if args_len < trailing_arg_count + 1:
336+
ex = exception_helper.create_cla_exception('WLSDPLY-01639', trailing_arg_count)
337+
ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
338+
self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
339+
raise ex
340+
341+
# set required_result['TRAILING_ARGS'] to list of trailing args (such as ['file1', 'file2'])
342+
trailing_args = []
343+
for index in range(args_len - trailing_arg_count, args_len):
344+
arg = args[index]
345+
trailing_args.append(arg)
346+
self._required_result[self.TRAILING_ARGS_SWITCH] = trailing_args
347+
348+
# remove trailing args from the list and return revised list
349+
return args[0:(args_len - trailing_arg_count)]
350+
317351
def get_help_key(self):
318352
return self.HELP_SWITCH
319353

@@ -930,9 +964,6 @@ def _validate_domain_resource_file_arg(self, value):
930964
raise ex
931965
return variables.getAbsolutePath()
932966

933-
def is_path_key(self, key):
934-
return self.PATH_SWITCH == key
935-
936967
def is_boolean_switch(self, key):
937968
return key in self.BOOLEAN_SWITCHES
938969

core/src/main/python/wlsdeploy/util/model_context.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(self, program_name, arg_map):
7575
self._validation_method = None
7676
self._rollback_if_restart_required = None
7777
self._domain_resource_file = None
78-
self._path = None
78+
self._trailing_args = []
7979

8080
if CommandLineArgUtil.ORACLE_HOME_SWITCH in arg_map:
8181
self._oracle_home = arg_map[CommandLineArgUtil.ORACLE_HOME_SWITCH]
@@ -178,8 +178,8 @@ def __init__(self, program_name, arg_map):
178178
if CommandLineArgUtil.DOMAIN_RESOURCE_FILE_SWITCH in arg_map:
179179
self._domain_resource_file = arg_map[CommandLineArgUtil.DOMAIN_RESOURCE_FILE_SWITCH]
180180

181-
if CommandLineArgUtil.PATH_SWITCH in arg_map:
182-
self._path = arg_map[CommandLineArgUtil.PATH_SWITCH]
181+
if CommandLineArgUtil.TRAILING_ARGS_SWITCH in arg_map:
182+
self._trailing_args = arg_map[CommandLineArgUtil.TRAILING_ARGS_SWITCH]
183183

184184
if CommandLineArgUtil.TARGET_MODE_SWITCH in arg_map:
185185
wlst_mode_string = arg_map[CommandLineArgUtil.TARGET_MODE_SWITCH]
@@ -467,12 +467,13 @@ def get_target_wlst_mode(self):
467467
"""
468468
return self._wlst_mode
469469

470-
def get_path(self):
470+
def get_trailing_argument(self, index):
471471
"""
472-
Get the model path (modelHelp).
473-
:return: the model path
472+
Get the trailing argument at index.
473+
:param index: the index of the trailing argument
474+
:return: the trailing argument
474475
"""
475-
return self._path
476+
return self._trailing_args[index]
476477

477478
def is_wlst_online(self):
478479
"""

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ WLSDPLY-01635=Specified Model Variable Injector File {0} is not a valid file : {
269269
WLSDPLY-01636=Specified Model Variable Keywords File {0} is not a valid file : {1}
270270
WLSDPLY-01637=Specified domain resource file {0} is not a valid file: {1}
271271
WLSDPLY-01638=The argument {0} must be followed by a value
272+
WLSDPLY-01639=At least {0} arguments are required
272273

273274
# wlsdeploy/util/cla_helper.py
274275
WLSDPLY-01650=Saving the model to file {0}
@@ -1047,7 +1048,7 @@ WLSDPLY-10105=Path: {0}
10471048
WLSDPLY-10106=Section: {0}
10481049
WLSDPLY-10107=Valid Folders:
10491050
WLSDPLY-10108={0} does not adhere to [<model_section>[:]][/<section_folder>]... pattern \
1050-
for the -path option. For example: domainInfo, resources:, topology:/Server, \
1051+
for the path argument. For example: domainInfo, resources:, topology:/Server, \
10511052
topology:/Server/ServerStart, /Server/ServerStart
10521053
WLSDPLY-10109={0} is not a recognized top level section name. The recognized top level section names are {1}
10531054
WLSDPLY-10110=Model section {0} has no folder {1} beneath it. Valid folders are: {2}

installer/src/main/bin/modelHelp.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ ECHO Usage: %SCRIPT_NAME%
7070
ECHO [-help]
7171
ECHO -oracle_home ^<oracle_home^>
7272
ECHO [-attributes_only ^| -folders_only ^| -recursive]
73-
ECHO -path ^<model_path^>
73+
ECHO ^<model_path^>
7474
ECHO.
7575
ECHO where:
7676
ECHO oracle_home - an existing Oracle Home directory

installer/src/main/bin/modelHelp.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ usage() {
3535
echo "Usage: $1 [-help]"
3636
echo " -oracle_home <oracle_home>"
3737
echo " [-attributes_only | -folders_only | -recursive]"
38-
echo " -path <model_path>"
38+
echo " <model_path>"
3939
echo ""
4040
echo " where:
4141
echo " oracle_home - an existing Oracle Home directory"

0 commit comments

Comments
 (0)