1 | import argparse |
||
2 | import sys |
||
3 | |||
4 | from coalib.misc import Constants |
||
5 | |||
6 | |||
7 | def default_arg_parser(formatter_class=None): |
||
8 | """ |
||
9 | This function creates an ArgParser to parse command line arguments. |
||
10 | |||
11 | :param formatter_class: Formatting the arg_parser output into a specific |
||
12 | form. For example: In the manpage format. |
||
13 | """ |
||
14 | formatter_class = formatter_class or argparse.RawDescriptionHelpFormatter |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() |
|||
15 | |||
16 | entry_point = sys.argv[0] |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
17 | for entry in ['coala-ci', 'coala-dbus', 'coala-format', 'coala-json', |
||
18 | 'coala-delete-orig']: |
||
19 | if entry_point.endswith(entry): |
||
20 | parser_type = entry |
||
21 | break |
||
22 | else: |
||
23 | parser_type = 'coala' |
||
24 | |||
25 | arg_parser = argparse.ArgumentParser( |
||
26 | formatter_class=formatter_class, |
||
27 | prog="coala", |
||
28 | description="coala is a simple COde AnaLysis Application. Its goal " |
||
29 | "is to make static code analysis easy and convenient " |
||
30 | "for all languages. coala uses bears, which are analysis " |
||
31 | "routines that can be combined arbitrarily.") |
||
32 | |||
33 | arg_parser.add_argument('TARGETS', |
||
34 | nargs='*', |
||
35 | help="Sections to be executed exclusively.") |
||
36 | arg_parser.add_argument('-c', |
||
37 | '--config', |
||
38 | nargs=1, |
||
39 | metavar='FILE', |
||
40 | help='Configuration file to be used, defaults to ' |
||
41 | + repr(Constants.default_coafile)) |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
42 | FIND_CONFIG_HELP = ('Attempt to find config file by checking parent ' |
||
43 | 'directories of the current working directory. It is ' |
||
44 | 'assumed that the config file is named ' |
||
45 | + repr(Constants.default_coafile) + '. This arg is ' |
||
46 | 'ignored if --config is also given') |
||
47 | arg_parser.add_argument('-F', |
||
48 | '--find-config', |
||
49 | nargs='?', |
||
50 | const=True, |
||
51 | metavar='BOOL', |
||
52 | help=FIND_CONFIG_HELP) |
||
53 | arg_parser.add_argument('-I', |
||
54 | '--no-config', |
||
55 | nargs='?', |
||
56 | const=True, |
||
57 | metavar='BOOL', |
||
58 | help="Run without using any config file") |
||
59 | arg_parser.add_argument('-f', |
||
60 | '--files', |
||
61 | nargs='+', |
||
62 | metavar='FILE', |
||
63 | help='Files that should be checked') |
||
64 | arg_parser.add_argument('-i', |
||
65 | '--ignore', |
||
66 | nargs='+', |
||
67 | metavar='FILE', |
||
68 | help='Files that should be ignored') |
||
69 | arg_parser.add_argument('--limit-files', |
||
70 | nargs='+', |
||
71 | metavar='FILE', |
||
72 | help='Files that will be analyzed will be ' |
||
73 | 'restricted to those in the globs listed ' |
||
74 | 'in this argument as well the files setting') |
||
75 | arg_parser.add_argument('-b', |
||
76 | '--bears', |
||
77 | nargs='+', |
||
78 | metavar='NAME', |
||
79 | help='Names of bears to use') |
||
80 | BEAR_DIRS_HELP = 'Additional directories where bears may lie' |
||
81 | arg_parser.add_argument('-d', |
||
82 | '--bear-dirs', |
||
83 | nargs='+', |
||
84 | metavar='DIR', |
||
85 | help=BEAR_DIRS_HELP) |
||
86 | LOG_LEVEL_HELP = ("Enum('ERROR','INFO','WARNING','DEBUG') to set level of " |
||
87 | "log output") |
||
88 | arg_parser.add_argument('-L', |
||
89 | '--log-level', |
||
90 | nargs=1, |
||
91 | choices=['ERROR', 'INFO', 'WARNING', 'DEBUG'], |
||
92 | metavar='ENUM', |
||
93 | help=LOG_LEVEL_HELP) |
||
94 | MIN_SEVERITY_HELP = ("Enum('INFO', 'NORMAL', 'MAJOR') to set the minimal " |
||
95 | "result severity.") |
||
96 | arg_parser.add_argument('-m', |
||
97 | '--min-severity', |
||
98 | nargs=1, |
||
99 | choices=('INFO', 'NORMAL', 'MAJOR'), |
||
100 | metavar='ENUM', |
||
101 | help=MIN_SEVERITY_HELP) |
||
102 | SETTINGS_HELP = 'Arbitrary settings in the form of section.key=value' |
||
103 | arg_parser.add_argument('-S', |
||
104 | '--settings', |
||
105 | nargs='+', |
||
106 | metavar='SETTING', |
||
107 | help=SETTINGS_HELP) |
||
108 | if parser_type == 'coala-json': |
||
109 | arg_parser.add_argument('--text-logs', |
||
110 | nargs='?', |
||
111 | const=True, |
||
112 | metavar='BOOL', |
||
113 | help='Don\'t display logs as json, display ' |
||
114 | 'them as we normally do in the console.') |
||
115 | arg_parser.add_argument('-o', |
||
116 | '--output', |
||
117 | nargs='?', |
||
118 | const=True, |
||
119 | metavar='BOOL', |
||
120 | help='Write the logs as json to a file ' |
||
121 | 'where filename is specified as argument.') |
||
122 | if parser_type == 'coala': |
||
123 | SHOW_BEARS_HELP = ("Display bears and its metadata with the sections " |
||
124 | "that they belong to") |
||
125 | arg_parser.add_argument('-B', |
||
126 | '--show-bears', |
||
127 | nargs='?', |
||
128 | const=True, |
||
129 | metavar='BOOL', |
||
130 | help=SHOW_BEARS_HELP) |
||
131 | arg_parser.add_argument('-A', |
||
132 | '--show-all-bears', |
||
133 | nargs='?', |
||
134 | const=True, |
||
135 | metavar='BOOL', |
||
136 | help="Display all bears.") |
||
137 | SAVE_HELP = ('Filename of file to be saved to, if provided with no ' |
||
138 | 'arguments, settings will be stored back to the file given ' |
||
139 | 'by -c') |
||
140 | arg_parser.add_argument('-s', |
||
141 | '--save', |
||
142 | nargs='?', |
||
143 | const=True, |
||
144 | metavar='FILE', |
||
145 | help=SAVE_HELP) |
||
146 | TAG_HELP = ('Tag results with a specific name. You can access the results' |
||
147 | ' later with that tag.') |
||
148 | arg_parser.add_argument('-t', |
||
149 | '--tag', |
||
150 | nargs='?', |
||
151 | const=True, |
||
152 | metavar='STRING', |
||
153 | help=TAG_HELP) |
||
154 | |||
155 | DELETE_TAG_HELP = 'Delete pre-tagged results with tag name.' |
||
156 | arg_parser.add_argument('-g', |
||
157 | '--dtag', |
||
158 | nargs='?', |
||
159 | const=True, |
||
160 | metavar='STRING', |
||
161 | help=DELETE_TAG_HELP) |
||
162 | |||
163 | arg_parser.add_argument("-j", |
||
164 | "--jobs", |
||
165 | type=int, |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
166 | help="Number of jobs to use in parallel.") |
||
167 | |||
168 | arg_parser.add_argument('-v', |
||
169 | '--version', |
||
170 | action='version', |
||
171 | version=Constants.VERSION) |
||
172 | |||
173 | arg_parser.add_argument('-n', |
||
174 | '--no-orig', |
||
175 | nargs='?', |
||
176 | const=True, |
||
177 | help="Deactivate creation of .orig files," |
||
178 | ".orig backup files before applying patches") |
||
179 | arg_parser.add_argument('-r', |
||
180 | '--relpath', |
||
181 | nargs='?', |
||
182 | const=True, |
||
183 | help="return relative paths for files") |
||
184 | |||
185 | return arg_parser |
||
186 |