[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__()
|
||||
|
||||
새 이슈에서 참조
사용자 차단