Coverage for birdplan/plugins/cmdline/cmdline_plugin.py: 79%

19 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-23 03:27 +0000

1# 

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

3# 

4# Copyright (c) 2019-2024, 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 

21 

22import argparse 

23from typing import Any, Optional 

24 

25from ...plugin import Plugin 

26 

27__all__ = ["BirdPlanCmdlinePluginBase"] 

28 

29 

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

31 """BirdPlan commandline plugin base class.""" 

32 

33 _subparser: Optional[argparse.ArgumentParser] 

34 _subparsers: Optional[argparse.ArgumentParser] 

35 

36 def __init__(self) -> None: 

37 """Initialize object.""" 

38 

39 super().__init__() 

40 

41 # Initialize our internals 

42 self._subparser = None 

43 

44 def get_subparser(self, args: Any) -> argparse.ArgumentParser: # pylint: disable=unused-argument 

45 """ 

46 Return the plugin subparser. 

47 

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

49 

50 Parameters 

51 ---------- 

52 args : Any 

53 Method argument(s). Unused. 

54 

55 Returns 

56 ------- 

57 argparse.ArgumentParser subparser. 

58 

59 """ 

60 

61 if not self._subparser: 

62 raise RuntimeError 

63 return self._subparser 

64 

65 def get_subparsers(self, args: Any) -> argparse.ArgumentParser: # pylint: disable=unused-argument 

66 """ 

67 Return the plugin subparsers. 

68 

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

70 

71 Parameters 

72 ---------- 

73 args : Any 

74 Method argument(s). Unused. 

75 

76 Returns 

77 ------- 

78 argparse.ArgumentParser subparsers. 

79 

80 """ 

81 

82 if not self._subparsers: 

83 raise RuntimeError 

84 return self._subparsers