1414from vcspull .__about__ import __version__
1515from vcspull .log import setup_logger
1616
17+ from ._formatter import VcspullHelpFormatter
1718from ._import import (
1819 create_import_subparser ,
1920 import_from_filesystem ,
2425
2526log = logging .getLogger (__name__ )
2627
27- SYNC_DESCRIPTION = textwrap .dedent (
28+
29+ def build_description (
30+ intro : str ,
31+ example_blocks : t .Sequence [tuple [str | None , t .Sequence [str ]]],
32+ ) -> str :
33+ """Assemble help text with optional example sections."""
34+ sections : list [str ] = []
35+ intro_text = textwrap .dedent (intro ).strip ()
36+ if intro_text :
37+ sections .append (intro_text )
38+
39+ for heading , commands in example_blocks :
40+ if not commands :
41+ continue
42+ title = "examples:" if heading is None else f"{ heading } examples:"
43+ lines = [title ]
44+ lines .extend (f" { command } " for command in commands )
45+ sections .append ("\n " .join (lines ))
46+
47+ return "\n \n " .join (sections )
48+
49+
50+ CLI_DESCRIPTION = build_description (
51+ """
52+ Manage multiple VCS repositories from a single configuration file.
53+ """ ,
54+ (
55+ (
56+ "sync" ,
57+ [
58+ 'vcspull sync "*"' ,
59+ 'vcspull sync "django-*"' ,
60+ 'vcspull sync "django-*" flask' ,
61+ 'vcspull sync -c ./myrepos.yaml "*"' ,
62+ "vcspull sync -c ./myrepos.yaml myproject" ,
63+ ],
64+ ),
65+ (
66+ "import" ,
67+ [
68+ "vcspull import mylib https://github.com/example/mylib.git" ,
69+ (
70+ "vcspull import -c ./myrepos.yaml mylib "
71+ "git@github.com:example/mylib.git"
72+ ),
73+ "vcspull import --scan ~/code" ,
74+ (
75+ "vcspull import --scan ~/code --recursive "
76+ "--workspace-root ~/code --yes"
77+ ),
78+ ],
79+ ),
80+ (
81+ "fmt" ,
82+ [
83+ "vcspull fmt" ,
84+ "vcspull fmt -c ./myrepos.yaml" ,
85+ "vcspull fmt --write" ,
86+ "vcspull fmt --all" ,
87+ ],
88+ ),
89+ ),
90+ )
91+
92+ SYNC_DESCRIPTION = build_description (
2893 """
2994 sync vcs repos
95+ """ ,
96+ (
97+ (
98+ None ,
99+ [
100+ 'vcspull sync "*"' ,
101+ 'vcspull sync "django-*"' ,
102+ 'vcspull sync "django-*" flask' ,
103+ 'vcspull sync -c ./myrepos.yaml "*"' ,
104+ "vcspull sync -c ./myrepos.yaml myproject" ,
105+ ],
106+ ),
107+ ),
108+ )
30109
31- examples:
32- vcspull sync "*"
33- vcspull sync "django-*"
34- vcspull sync "django-*" flask
35- vcspull sync -c ./myrepos.yaml "*"
36- vcspull sync -c ./myrepos.yaml myproject
37- """ ,
38- ).strip ()
110+ IMPORT_DESCRIPTION = build_description (
111+ """
112+ Import a repository to the vcspull configuration file.
113+
114+ Provide NAME and URL to add a single repository, or use --scan to
115+ discover existing git repositories within a directory.
116+ """ ,
117+ (
118+ (
119+ None ,
120+ [
121+ "vcspull import mylib https://github.com/example/mylib.git" ,
122+ (
123+ "vcspull import -c ./myrepos.yaml mylib "
124+ "git@github.com:example/mylib.git"
125+ ),
126+ "vcspull import --scan ~/code" ,
127+ (
128+ "vcspull import --scan ~/code --recursive "
129+ "--workspace-root ~/code --yes"
130+ ),
131+ ],
132+ ),
133+ ),
134+ )
135+
136+ FMT_DESCRIPTION = build_description (
137+ """
138+ Format vcspull configuration files for consistency.
139+
140+ Normalizes repository entries, sorts sections, and can write changes
141+ back to disk or format all discovered configuration files.
142+ """ ,
143+ (
144+ (
145+ None ,
146+ [
147+ "vcspull fmt" ,
148+ "vcspull fmt -c ./myrepos.yaml" ,
149+ "vcspull fmt --write" ,
150+ "vcspull fmt --all" ,
151+ ],
152+ ),
153+ ),
154+ )
39155
40156
41157@overload
@@ -54,8 +170,8 @@ def create_parser(
54170 """Create CLI argument parser for vcspull."""
55171 parser = argparse .ArgumentParser (
56172 prog = "vcspull" ,
57- formatter_class = argparse . RawDescriptionHelpFormatter ,
58- description = SYNC_DESCRIPTION ,
173+ formatter_class = VcspullHelpFormatter ,
174+ description = CLI_DESCRIPTION ,
59175 )
60176 parser .add_argument (
61177 "--version" ,
@@ -75,28 +191,24 @@ def create_parser(
75191 sync_parser = subparsers .add_parser (
76192 "sync" ,
77193 help = "synchronize repos" ,
78- formatter_class = argparse . RawDescriptionHelpFormatter ,
194+ formatter_class = VcspullHelpFormatter ,
79195 description = SYNC_DESCRIPTION ,
80196 )
81197 create_sync_subparser (sync_parser )
82198
83199 import_parser = subparsers .add_parser (
84200 "import" ,
85201 help = "import repository or scan filesystem for repositories" ,
86- formatter_class = argparse .RawDescriptionHelpFormatter ,
87- description = "Import a repository to the vcspull configuration file. "
88- "Can import a single repository by name and URL, or scan a directory "
89- "to discover and import multiple repositories." ,
202+ formatter_class = VcspullHelpFormatter ,
203+ description = IMPORT_DESCRIPTION ,
90204 )
91205 create_import_subparser (import_parser )
92206
93207 fmt_parser = subparsers .add_parser (
94208 "fmt" ,
95209 help = "format vcspull configuration files" ,
96- formatter_class = argparse .RawDescriptionHelpFormatter ,
97- description = "Format vcspull configuration files for consistency. "
98- "Normalizes compact format to verbose format, standardizes on 'repo' key, "
99- "and sorts directories and repositories alphabetically." ,
210+ formatter_class = VcspullHelpFormatter ,
211+ description = FMT_DESCRIPTION ,
100212 )
101213 create_fmt_subparser (fmt_parser )
102214
0 commit comments