@@ -16,6 +16,39 @@ 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
+ # The additional space is required for argparse to respect newlines.
44
+ result += "\n " .join (lines )
45
+
46
+ if not is_last :
47
+ result += "\n "
48
+
49
+ return result
50
+
51
+
19
52
def main ():
20
53
# Read command-line arguments
21
54
parser = argparse .ArgumentParser (
@@ -27,29 +60,29 @@ def main():
27
60
"-h" ,
28
61
"--help" ,
29
62
action = "help" ,
30
- help = " \n Display help message and exit.\n " ,
63
+ help = _help_string ( "Display help message and exit." ) ,
31
64
)
32
65
parser .add_argument (
33
66
"--version" ,
34
67
action = "version" ,
35
68
version = f"Code Base Investigator { version } " ,
36
- help = " \n Display version information and exit.\n " ,
69
+ help = _help_string ( "Display version information and exit." ) ,
37
70
)
38
71
parser .add_argument (
39
72
"-v" ,
40
73
"--verbose" ,
41
74
dest = "verbose" ,
42
75
action = "count" ,
43
76
default = 0 ,
44
- help = " \n Increase verbosity level.\n " ,
77
+ help = _help_string ( "Increase verbosity level." ) ,
45
78
)
46
79
parser .add_argument (
47
80
"-q" ,
48
81
"--quiet" ,
49
82
dest = "quiet" ,
50
83
action = "count" ,
51
84
default = 0 ,
52
- help = " \n Decrease verbosity level.\n " ,
85
+ help = _help_string ( "Decrease verbosity level." ) ,
53
86
)
54
87
parser .add_argument (
55
88
"-R" ,
@@ -59,9 +92,12 @@ def main():
59
92
action = "append" ,
60
93
default = [],
61
94
choices = ["all" , "summary" , "clustering" ],
62
- help = "Generate a report of the specified type.\n "
63
- + "May be specified multiple times.\n "
64
- + "If not specified, all reports will be generated.\n " ,
95
+ help = _help_string (
96
+ "Generate a report of the specified type." ,
97
+ "May be specified multiple times." ,
98
+ "If not specified, all reports will be generated." ,
99
+ is_long = True ,
100
+ ),
65
101
)
66
102
parser .add_argument (
67
103
"-x" ,
@@ -70,8 +106,11 @@ def main():
70
106
metavar = "<pattern>" ,
71
107
action = "append" ,
72
108
default = [],
73
- help = "Exclude files matching this pattern from the code base.\n "
74
- + "May be specified multiple times.\n " ,
109
+ help = _help_string (
110
+ "Exclude files matching this pattern from the code base." ,
111
+ "May be specified multiple times." ,
112
+ is_long = True ,
113
+ ),
75
114
)
76
115
parser .add_argument (
77
116
"-p" ,
@@ -80,15 +119,23 @@ def main():
80
119
metavar = "<platform>" ,
81
120
action = "append" ,
82
121
default = [],
83
- help = "Include the specified platform in the analysis.\n "
84
- + "May be specified multiple times.\n "
85
- + "If not specified, all platforms will be included.\n " ,
122
+ help = _help_string (
123
+ "Include the specified platform in the analysis." ,
124
+ "May be specified multiple times." ,
125
+ "If not specified, all platforms will be included." ,
126
+ is_long = True ,
127
+ is_last = True ,
128
+ ),
86
129
)
130
+
87
131
parser .add_argument (
88
132
"analysis_file" ,
89
133
metavar = "<analysis-file>" ,
90
- help = "\n TOML file describing the analysis to be performed, "
91
- + "including the codebase and platform descriptions." ,
134
+ help = _help_string (
135
+ "TOML file describing the analysis to be performed, "
136
+ + "including the codebase and platform descriptions." ,
137
+ is_last = True ,
138
+ ),
92
139
)
93
140
94
141
args = parser .parse_args ()
0 commit comments