Use subparsers in the notifications command
- Dominant language
- Python
- Stars
- 9
- Forks
- 31
- Avg merge
- 3d 19h
- Merged PRs (30d)
- 16
Description
We currently use the `--actions` parameter to define what to do, but this has increased over time and since `--actions` is a required parameter, we turned it into subcommands but without much organization. We should split it into subparsers and delegate each action to a defined function.
Example code for subparsers:
```python
from django.core.management.base import BaseCommand
from kernelCI_app.helpers.logger import out
class Command(BaseCommand):
help = "Test command for subparsers"
def add_arguments(self, parser):
subparsers = parser.add_subparsers(
title="action",
help="Available actions",
)
parser_function = subparsers.add_parser(
'function',
help='Execute _function'
)
parser_function.set_defaults(func=self._function)
second_function = subparsers.add_parser(
'second_action',
help='Execute _second_action'
)
second_function.set_defaults(func=self._second_action)
second_function.add_argument(
'--option',
type=str,
help='An example option for the second action',
)
def handle(
self,
*args,
**options,
):
out("Handle executed")
func = options["func"]
func(*args, **options)
def _function(self, *args, **options):
print(" ~ 🔍 _function (39) - options: %s" % options)
print("Function executed")
def _second_action(self, *args, option, **options):
print(" ~ 🔍 _second_action (44) - option: %s" % option)
print(" ~ 🔍 _second_action (42) - options: %s" % options)
print("Second action executed")
```
Contributor guide
Research direction
Start by locating the notifications management command and reading how the required --actions parameter currently dispatches work. Identify each existing action and its options, then verify that the command uses organized subparsers with a defined function for every action and that each action still receives its required arguments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100