|
6 | 6 | from .utils import reset_terminal_colors |
7 | 7 |
|
8 | 8 |
|
| 9 | +class CustomHelpFormatter(argparse.HelpFormatter): |
| 10 | + def __init__(self, prog): |
| 11 | + super().__init__(prog, max_help_position=40, width=80) |
| 12 | + |
| 13 | + def _format_action_invocation(self, action): |
| 14 | + if not action.option_strings or action.nargs == 0: |
| 15 | + return super()._format_action_invocation(action) |
| 16 | + default = self._get_default_metavar_for_optional(action) |
| 17 | + args_string = self._format_args(action, default) |
| 18 | + return ", ".join(action.option_strings) + " " + args_string |
| 19 | + |
| 20 | + |
9 | 21 | def get_cli_args(): |
| 22 | + fmt = lambda prog: CustomHelpFormatter(prog) |
10 | 23 | parser = argparse.ArgumentParser( |
11 | | - prog="CodeManager - CLI", |
12 | | - description="Organizes all coding projects on the device", |
| 24 | + prog="codemg", |
| 25 | + description="CodeManager - CLI: Organizes all coding projects on the device", |
| 26 | + formatter_class=fmt, |
13 | 27 | ) |
14 | 28 |
|
15 | 29 | parser.add_argument( |
16 | | - "--list-templates", action="store_true", help="List all templates" |
| 30 | + "-lt", |
| 31 | + "--list-templates", |
| 32 | + action="store_true", |
| 33 | + help="list all templates", |
17 | 34 | ) |
18 | 35 |
|
19 | 36 | subparsers = parser.add_subparsers(dest="command") |
20 | | - project_creator = subparsers.add_parser("create") |
| 37 | + project_creator = subparsers.add_parser( |
| 38 | + "create", |
| 39 | + help="create a new project", |
| 40 | + formatter_class=fmt, |
| 41 | + ) |
| 42 | + project_adder = subparsers.add_parser( |
| 43 | + "add", |
| 44 | + help="add an existing project", |
| 45 | + formatter_class=fmt, |
| 46 | + ) |
21 | 47 |
|
| 48 | + # Project Creator arguments |
22 | 49 | project_creator.add_argument( |
23 | 50 | "project_template", |
24 | 51 | metavar="template", |
25 | | - help="Template to create the project", |
26 | 52 | choices=get_args(TEMPLATE), |
| 53 | + help="template to create the project", |
27 | 54 | ) |
28 | 55 | project_creator.add_argument( |
29 | | - "directory", help="Destination directory to create the project" |
| 56 | + "directory", |
| 57 | + help="destination directory to create the project", |
30 | 58 | ) |
31 | 59 |
|
32 | 60 | project_creator.add_argument( |
33 | 61 | "--git", |
34 | | - help="Initializes git version control system in the project", |
| 62 | + help="initializes git version control system in the project", |
35 | 63 | action="store_true", |
36 | 64 | ) |
37 | | - |
38 | 65 | project_creator.add_argument( |
39 | 66 | "-rc", |
40 | | - help="Reuses current vscode instance", |
| 67 | + help="reuses current vscode instance", |
41 | 68 | action="store_true", |
42 | 69 | ) |
43 | | - |
44 | 70 | project_creator.add_argument( |
45 | 71 | "-nc", |
46 | | - help="Creates project without opening the project in vscode", |
| 72 | + help="creates project without opening the project in vscode", |
47 | 73 | action="store_true", |
48 | 74 | ) |
49 | | - |
50 | 75 | project_creator.add_argument( |
51 | 76 | "--jpm", |
52 | | - metavar="JS package manager", |
53 | | - help="Package manager for JavaScript", |
54 | | - type=str, |
55 | 77 | default="npm", |
56 | 78 | choices=JS_PACKAGE_MANAGERS, |
| 79 | + metavar="<package-manager>", |
| 80 | + help="package manager for JavaScript", |
| 81 | + ) |
| 82 | + |
| 83 | + # Project Adder arguments |
| 84 | + project_adder.add_argument( |
| 85 | + "directory", |
| 86 | + help="project directory to add", |
| 87 | + ) |
| 88 | + project_adder.add_argument( |
| 89 | + "-t", |
| 90 | + "--template", |
| 91 | + default="normal", |
| 92 | + metavar="<template>", |
| 93 | + choices=get_args(TEMPLATE), |
| 94 | + help="specifies the project template", |
57 | 95 | ) |
58 | 96 |
|
59 | 97 | args = parser.parse_args() |
|
0 commit comments