The "Args and Flags" sections of the help string.
(info, spec, metadata)
| 189 | |
| 190 | |
| 191 | def _ArgsAndFlagsSections(info, spec, metadata): |
| 192 | """The "Args and Flags" sections of the help string.""" |
| 193 | args_with_no_defaults = spec.args[:len(spec.args) - len(spec.defaults)] |
| 194 | args_with_defaults = spec.args[len(spec.args) - len(spec.defaults):] |
| 195 | |
| 196 | # Check if positional args are allowed. If not, require flag syntax for args. |
| 197 | accepts_positional_args = metadata.get(decorators.ACCEPTS_POSITIONAL_ARGS) |
| 198 | |
| 199 | args_and_flags_sections = [] |
| 200 | notes_sections = [] |
| 201 | |
| 202 | docstring_info = info['docstring_info'] |
| 203 | |
| 204 | arg_items = [ |
| 205 | _CreateArgItem(arg, docstring_info, spec) |
| 206 | for arg in args_with_no_defaults |
| 207 | ] |
| 208 | |
| 209 | if spec.varargs: |
| 210 | arg_items.append( |
| 211 | _CreateArgItem(spec.varargs, docstring_info, spec) |
| 212 | ) |
| 213 | |
| 214 | if arg_items: |
| 215 | title = 'POSITIONAL ARGUMENTS' if accepts_positional_args else 'ARGUMENTS' |
| 216 | arguments_section = (title, '\n'.join(arg_items).rstrip('\n')) |
| 217 | args_and_flags_sections.append(arguments_section) |
| 218 | if args_with_no_defaults and accepts_positional_args: |
| 219 | notes_sections.append( |
| 220 | ('NOTES', 'You can also use flags syntax for POSITIONAL ARGUMENTS') |
| 221 | ) |
| 222 | |
| 223 | unique_short_args = _GetShortFlags(args_with_defaults) |
| 224 | positional_flag_items = [ |
| 225 | _CreateFlagItem( |
| 226 | flag, docstring_info, spec, required=False, |
| 227 | short_arg=flag[0] in unique_short_args |
| 228 | ) |
| 229 | for flag in args_with_defaults |
| 230 | ] |
| 231 | |
| 232 | unique_short_kwonly_flags = _GetShortFlags(spec.kwonlyargs) |
| 233 | kwonly_flag_items = [ |
| 234 | _CreateKeywordOnlyFlagItem( |
| 235 | flag, docstring_info, spec, |
| 236 | short_arg=flag[0] in unique_short_kwonly_flags |
| 237 | ) |
| 238 | for flag in spec.kwonlyargs |
| 239 | ] |
| 240 | flag_items = positional_flag_items + kwonly_flag_items |
| 241 | |
| 242 | if spec.varkw: |
| 243 | # Include kwargs documented via :key param: |
| 244 | documented_kwargs = [] |
| 245 | |
| 246 | # add short flags if possible |
| 247 | flags = docstring_info.args or [] |
| 248 | flag_names = [f.name for f in flags] |
no test coverage detected