[SWDEV-513958] Fix error message due to argparse behavior (#108)
When argparse parses multiple invalid arguments, the error message displays only the last argument and this leads to confusion. To avoid the scenario, added valid command check before argparse and in case of invalid first command, added new exception. Signed-off-by: Bindhiya Kanangot Balakrishnan <Bindhiya.KanangotBalakrishnan@amd.com>
このコミットが含まれているのは:
1 親
dc7a5bb925
コミット
3681f900ee
2ファイル変更
+25
-1
検索条件に一致するファイルはありません
+10
-1
@@ -103,9 +103,18 @@ if __name__ == "__main__":
|
||||
except NameError:
|
||||
logging.debug("argcomplete module not found. Autocomplete will not work.")
|
||||
|
||||
valid_commands = ['version', 'list', 'static', 'firmware', 'bad-pages',
|
||||
'metric', 'process', 'profile', 'event', 'topology', 'set',
|
||||
'reset', 'monitor', 'xgmi', 'partition', '--help']
|
||||
|
||||
sys.argv = [arg.lower() if arg.startswith('--') or not arg.startswith('-')
|
||||
else arg for arg in sys.argv]
|
||||
args = amd_smi_parser.parse_args(args=None if sys.argv[1:] else ['--help'])
|
||||
if len(sys.argv) == 1:
|
||||
args = amd_smi_parser.parse_args(args=['--help'])
|
||||
elif sys.argv[1] in valid_commands:
|
||||
args = amd_smi_parser.parse_args(args=None)
|
||||
else:
|
||||
raise amdsmi_cli_exceptions.AmdSmiInvalidSubcommandException(sys.argv[1],amd_smi_commands.logger.destination)
|
||||
|
||||
# Handle command modifiers before subcommand execution
|
||||
if args.json:
|
||||
|
||||
@@ -241,6 +241,21 @@ class AmdSmiRequiredCommandException(AmdSmiException):
|
||||
self.stdout_message = f"{common_message} Error code: {self.value}"
|
||||
|
||||
|
||||
class AmdSmiInvalidSubcommandException(AmdSmiException):
|
||||
def __init__(self, command, outputformat: str):
|
||||
super().__init__()
|
||||
self.value = -10
|
||||
self.command = command
|
||||
self.output_format = outputformat
|
||||
|
||||
common_message = f"AMD-SMI Command '{self.command}' is invalid. Must receive valid AMD-SMI Command first. Run '--help' for more info."
|
||||
|
||||
self.json_message["error"] = common_message
|
||||
self.json_message["code"] = self.value
|
||||
self.csv_message = f"error,code\n{common_message}, {self.value}"
|
||||
self.stdout_message = f"{common_message} Error code: {self.value}"
|
||||
|
||||
|
||||
class AmdSmiUnknownErrorException(AmdSmiException):
|
||||
def __init__(self, command, outputformat: str):
|
||||
super().__init__()
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする