Coverage for src/birdplan/plugins/cmdline/cmdline_plugin.py: 75%

16 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-25 07:38 +0000

1# 

2# SPDX-License-Identifier: GPL-3.0-or-later 

3# 

4# Copyright (c) 2019-2025, AllWorldIT 

5# 

6# This program is free software: you can redistribute it and/or modify 

7# it under the terms of the GNU General Public License as published by 

8# the Free Software Foundation, either version 3 of the License, or 

9# (at your option) any later version. 

10# 

11# This program is distributed in the hope that it will be useful, 

12# but WITHOUT ANY WARRANTY; without even the implied warranty of 

13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

14# GNU General Public License for more details. 

15# 

16# You should have received a copy of the GNU General Public License 

17# along with this program. If not, see <http://www.gnu.org/licenses/>. 

18 

19"""BirdPlan commandline plugin base class.""" 

20 

21import argparse 

22from typing import Any 

23 

24from ...plugin import Plugin 

25 

26__all__ = ["BirdPlanCmdlinePluginBase"] 

27 

28 

29class BirdPlanCmdlinePluginBase(Plugin): # pylint: disable=too-few-public-methods 

30 """BirdPlan commandline plugin base class.""" 

31 

32 _subparser: argparse.ArgumentParser | None 

33 _subparsers: argparse.ArgumentParser | None 

34 

35 def __init__(self) -> None: 

36 """Initialize object.""" 

37 

38 super().__init__() 

39 

40 # Initialize our internals 

41 self._subparser = None 

42 

43 def get_subparser(self, args: dict[str, Any]) -> argparse.ArgumentParser: # noqa: ARG002 

44 """ 

45 Return the plugin subparser. 

46 

47 The subparser is this commandline options parser for this command. 

48 

49 Parameters 

50 ---------- 

51 args : Any 

52 Method argument(s). Unused. 

53 

54 Returns 

55 ------- 

56 argparse.ArgumentParser subparser. 

57 

58 """ 

59 

60 if not self._subparser: 

61 raise RuntimeError 

62 return self._subparser 

63 

64 def get_subparsers(self, args: dict[str, Any]) -> argparse.ArgumentParser: # noqa: ARG002 

65 """ 

66 Return the plugin subparsers. 

67 

68 Subparsers are created under the commandline option to implement command hierarchies. 

69 

70 Parameters 

71 ---------- 

72 args : Any 

73 Method argument(s). Unused. 

74 

75 Returns 

76 ------- 

77 argparse.ArgumentParser subparsers. 

78 

79 """ 

80 

81 if not self._subparsers: 

82 raise RuntimeError 

83 return self._subparsers