Coverage for birdplan/plugins/cmdline/ospf/__init__.py: 86%

21 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 options for OSPF.""" 

20 

21import argparse 

22from typing import Any, Dict 

23 

24from ....exceptions import BirdPlanErrorUsage 

25from ..cmdline_plugin import BirdPlanCmdlinePluginBase 

26 

27__all__ = ["BirdPlanCmdlineOSPF"] 

28 

29 

30class BirdPlanCmdlineOSPF(BirdPlanCmdlinePluginBase): 

31 """BirdPlan "ospf" command.""" 

32 

33 def __init__(self) -> None: 

34 """Initialize object.""" 

35 

36 super().__init__() 

37 

38 # Plugin setup 

39 self.plugin_description = "birdplan ospf" 

40 self.plugin_order = 10 

41 

42 def register_parsers(self, args: Dict[str, Any]) -> None: 

43 """ 

44 Register commandline parsers. 

45 

46 Parameters 

47 ---------- 

48 args : Dict[str, Any] 

49 Method argument(s). 

50 

51 """ 

52 

53 root_parser = args["root_parser"] 

54 

55 # CMD: ospf 

56 subparser = root_parser.add_parser("ospf", help="OSPF commands") 

57 

58 subparser.add_argument( 

59 "--action", 

60 action="store_const", 

61 const="ospf", 

62 default="ospf", 

63 help=argparse.SUPPRESS, 

64 ) 

65 

66 # Set our internal subparser properties 

67 self._subparser = subparser 

68 self._subparsers = subparser.add_subparsers() 

69 

70 def cmd_ospf(self, args: Any) -> Any: # pylint: disable=unused-argument 

71 """ 

72 Commandline handler for "ospf" action. 

73 

74 Parameters 

75 ---------- 

76 args : Dict[str, Any] 

77 Method argument(s). 

78 

79 """ 

80 

81 if not self._subparser: 

82 raise RuntimeError() 

83 

84 raise BirdPlanErrorUsage("No options specified to 'ospf' action", self._subparser)