Coverage for python/lsst/source/injection/bin/source_injection_help_formatter.py: 44%

14 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-02 03:11 -0700

1# This file is part of source_injection. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

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

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

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

12# (at your option) any later version. 

13# 

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

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

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

17# GNU General Public License for more details. 

18# 

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

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

21 

22from __future__ import annotations 

23 

24__all__ = ["SourceInjectionHelpFormatter"] 

25 

26from argparse import ArgumentDefaultsHelpFormatter, RawDescriptionHelpFormatter 

27 

28 

29class SourceInjectionHelpFormatter(ArgumentDefaultsHelpFormatter, RawDescriptionHelpFormatter): 

30 """Custom help formatter class to override standard formatting output.""" 

31 

32 def __init__(self, prog): 

33 super().__init__(prog, width=79, max_help_position=6) 

34 

35 def _format_action_invocation(self, action): 

36 """Modify help message format to remove duplicate metavar entries.""" 

37 if not action.option_strings or action.nargs == 0: 

38 return super()._format_action_invocation(action) 

39 default = self._get_default_metavar_for_optional(action) 

40 args_string = self._format_args(action, default) 

41 return ", ".join(action.option_strings) + " " + args_string 

42 

43 def _split_lines(self, text, width): 

44 """Split text into lines; add a line break after each option block.""" 

45 return super()._split_lines(text, width) + [""]