@@ -16,39 +16,77 @@ from codebasin.walkers.platform_mapper import PlatformMapper
16
16
version = "1.2.0"
17
17
18
18
19
+ def _help_string (* lines : str , is_long = False , is_last = False ):
20
+ """
21
+ Parameters
22
+ ----------
23
+ *lines: str
24
+ Each line in the help string.
25
+
26
+ is_long: bool
27
+ A flag indicating whether the option is long enough to generate an
28
+ initial newline by default.
29
+
30
+ is_last: bool
31
+ A flag indicating whether the option is the last in the list.
32
+
33
+ Returns
34
+ -------
35
+ An argparse help string formatted as a paragraph.
36
+ """
37
+ result = ""
38
+
39
+ # A long option like --exclude will force a newline.
40
+ if not is_long :
41
+ result = "\n "
42
+
43
+ # argparse.HelpFormatter indents by 24 characters.
44
+ # We cannot override this directly, but can delete them with backspaces.
45
+ lines = ["\b " * 20 + x for x in lines ]
46
+
47
+ # The additional space is required for argparse to respect newlines.
48
+ result += "\n " .join (lines )
49
+
50
+ if not is_last :
51
+ result += "\n "
52
+
53
+ return result
54
+
55
+
19
56
def main ():
20
57
# Read command-line arguments
21
58
parser = argparse .ArgumentParser (
22
59
description = "Code Base Investigator " + str (version ),
60
+ formatter_class = argparse .RawTextHelpFormatter ,
23
61
add_help = False ,
24
62
)
25
63
parser .add_argument (
26
64
"-h" ,
27
65
"--help" ,
28
66
action = "help" ,
29
- help = "Display help message and exit." ,
67
+ help = _help_string ( "Display help message and exit." ) ,
30
68
)
31
69
parser .add_argument (
32
70
"--version" ,
33
71
action = "version" ,
34
72
version = f"Code Base Investigator { version } " ,
35
- help = "Display version information and exit." ,
73
+ help = _help_string ( "Display version information and exit." ) ,
36
74
)
37
75
parser .add_argument (
38
76
"-v" ,
39
77
"--verbose" ,
40
78
dest = "verbose" ,
41
79
action = "count" ,
42
80
default = 0 ,
43
- help = "Increase verbosity level." ,
81
+ help = _help_string ( "Increase verbosity level." ) ,
44
82
)
45
83
parser .add_argument (
46
84
"-q" ,
47
85
"--quiet" ,
48
86
dest = "quiet" ,
49
87
action = "count" ,
50
88
default = 0 ,
51
- help = "Decrease verbosity level." ,
89
+ help = _help_string ( "Decrease verbosity level." ) ,
52
90
)
53
91
parser .add_argument (
54
92
"-R" ,
@@ -58,9 +96,12 @@ def main():
58
96
action = "append" ,
59
97
default = [],
60
98
choices = ["all" , "summary" , "clustering" ],
61
- help = "Generate a report of the specified type. "
62
- + "May be specified multiple times. "
63
- + "If not specified, all reports will be generated." ,
99
+ help = _help_string (
100
+ "Generate a report of the specified type." ,
101
+ "May be specified multiple times." ,
102
+ "If not specified, all reports will be generated." ,
103
+ is_long = True ,
104
+ ),
64
105
)
65
106
parser .add_argument (
66
107
"-x" ,
@@ -69,8 +110,11 @@ def main():
69
110
metavar = "<pattern>" ,
70
111
action = "append" ,
71
112
default = [],
72
- help = "Exclude files matching this pattern from the code base. "
73
- + "May be specified multiple times." ,
113
+ help = _help_string (
114
+ "Exclude files matching this pattern from the code base." ,
115
+ "May be specified multiple times." ,
116
+ is_long = True ,
117
+ ),
74
118
)
75
119
parser .add_argument (
76
120
"-p" ,
@@ -79,15 +123,23 @@ def main():
79
123
metavar = "<platform>" ,
80
124
action = "append" ,
81
125
default = [],
82
- help = "Include the specified platform in the analysis. "
83
- + "May be specified multiple times. "
84
- + "If not specified, all platforms will be included." ,
126
+ help = _help_string (
127
+ "Include the specified platform in the analysis." ,
128
+ "May be specified multiple times." ,
129
+ "If not specified, all platforms will be included." ,
130
+ is_long = True ,
131
+ is_last = True ,
132
+ ),
85
133
)
134
+
86
135
parser .add_argument (
87
136
"analysis_file" ,
88
137
metavar = "<analysis-file>" ,
89
- help = "TOML file describing the analysis to be performed, "
90
- + "including the codebase and platform descriptions." ,
138
+ help = _help_string (
139
+ "TOML file describing the analysis to be performed, "
140
+ + "including the codebase and platform descriptions." ,
141
+ is_last = True ,
142
+ ),
91
143
)
92
144
93
145
args = parser .parse_args ()
0 commit comments