subcommand.py 634 Bytes
Newer Older
Baber's avatar
Baber committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import argparse
from abc import ABC, abstractmethod


class SubCommand(ABC):
    """Base class for all subcommands."""

    def __init__(self, *args, **kwargs):
        pass

    @classmethod
    def create(cls, subparsers: argparse._SubParsersAction):
        """Factory method to create and register a command instance."""
        return cls(subparsers)

    @abstractmethod
Baber's avatar
cleanup  
Baber committed
17
    def _add_args(self) -> None:
Baber's avatar
Baber committed
18
19
20
21
22
23
24
        """Add arguments specific to this subcommand."""
        pass

    @abstractmethod
    def execute(self, args: argparse.Namespace) -> None:
        """Execute the subcommand with the given arguments."""
        pass