-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/gh47 custom argument parser #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,9 +9,9 @@ | |
| import rich | ||
| from rich.table import Table | ||
| try: | ||
| from base_plugin import BaseXTSPlugin, plugin_utils | ||
| from base_plugin import BaseXTSPlugin, plugin_utils, XTSArgumentParser | ||
|
||
| except: | ||
| from xts_core.plugins.base_plugin import BaseXTSPlugin, plugin_utils | ||
| from xts_core.plugins.base_plugin import BaseXTSPlugin, plugin_utils, XTSArgumentParser | ||
|
|
||
|
|
||
|
|
||
|
|
@@ -163,7 +163,7 @@ def _setup_allocator_args(self): | |
| # remove | ||
| # Since a lot of these parsers share arguments we can use the base parsers as parents | ||
| # to save on adding the same arguments multiple times. | ||
| remove_base = argparse.ArgumentParser('remove base', add_help=False,) | ||
| remove_base = XTSArgumentParser('remove base', add_help=False,) | ||
| remove_base.add_argument('name', help='Name of the server to remove') | ||
| remove_parser = allocator_subparsers.add_parser('remove', | ||
| help='Remove an allocator server', | ||
|
|
@@ -176,10 +176,10 @@ def _setup_allocator_args(self): | |
| add_parser.add_argument('url', help='URL for the allocator server') | ||
| # list | ||
| allocator_subparsers.add_parser('list', help='List all known allocators') | ||
| base_parser = argparse.ArgumentParser('base', add_help=False) | ||
| base_parser = XTSArgumentParser('base', add_help=False) | ||
| base_parser.add_argument('--server', required=True, help='Server URL') | ||
| # search | ||
| search_base = argparse.ArgumentParser('search_base', | ||
| search_base = XTSArgumentParser('search_base', | ||
| add_help=False, | ||
| parents=[base_parser]) | ||
| search_base.add_argument('--platform', help='Platform of DUT') | ||
|
|
@@ -189,7 +189,7 @@ def _setup_allocator_args(self): | |
| help='Search for slots on an allocator server', | ||
| parents=[search_base]) | ||
| # add-slot | ||
| add_base = argparse.ArgumentParser('add_base', | ||
| add_base = XTSArgumentParser('add_base', | ||
| add_help=False, | ||
| parents=[search_base]) | ||
| add_base.add_argument('--owner-email', help='Owner email (if allocated).', dest='owner_email') | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,42 @@ | ||||||
| #!/usr/bin/env python3 | ||||||
| #** ***************************************************************************** | ||||||
| # * | ||||||
| # * If not stated otherwise in this file or this component's LICENSE file the | ||||||
| # * following copyright and licenses apply: | ||||||
| # * | ||||||
| # * Copyright 2024 RDK Management | ||||||
| # * | ||||||
| # * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
| # * you may not use this file except in compliance with the License. | ||||||
| # * You may obtain a copy of the License at | ||||||
| # * | ||||||
| # * | ||||||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||||||
| # * | ||||||
| # * Unless required by applicable law or agreed to in writing, software | ||||||
| # * distributed under the License is distributed on an "AS IS" BASIS, | ||||||
| # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
| # * See the License for the specific language governing permissions and | ||||||
| # * limitations under the License. | ||||||
| # * | ||||||
| #* ****************************************************************************** | ||||||
|
|
||||||
| import argparse | ||||||
| import sys | ||||||
|
|
||||||
| from rich_argparse import RichHelpFormatter | ||||||
|
|
||||||
| class XTSArgumentParser(argparse.ArgumentParser): | ||||||
| """XTS Specific argument parser. | ||||||
| """ | ||||||
|
|
||||||
| def __init__(self,*args, **kwargs): | ||||||
|
||||||
| def __init__(self,*args, **kwargs): | |
| def __init__(self, *args, **kwargs): |
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The kwargs.pop('formatter_class', '') on line 34 removes the formatter_class if present, but uses an empty string as default. This should use None as the default value instead, as empty string is not a meaningful default for a class parameter: kwargs.pop('formatter_class', None)
| kwargs.pop('formatter_class','') | |
| kwargs.pop('formatter_class', None) |
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Using old-style string formatting (%). Consider using f-strings for consistency with modern Python: sys.stderr.write(f'error: {message}\\n')
| sys.stderr.write('error: %s\n' % message) | |
| sys.stderr.write(f'error: {message}\n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing
argparseimport. The base_plugin.py file still needs to import argparse since it's likely used elsewhere in the file (e.g., for type hints, argument groups, or other argparse functionality). Only the ArgumentParser class is being replaced.