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- CLI_DESCRIPTION = textwrap .dedent (
28+ ExampleBlocks = t .Sequence [tuple [str | None , list [str ]]]
29+
30+
31+ def build_description (intro : str , example_blocks : ExampleBlocks ) -> str :
32+ """Assemble help text with optional example sections."""
33+ sections : list [str ] = []
34+ intro_text = textwrap .dedent (intro ).strip ()
35+ if intro_text :
36+ sections .append (intro_text )
37+
38+ for heading , commands in example_blocks :
39+ if not commands :
40+ continue
41+ title = "examples:" if heading is None else f"{ heading } examples:"
42+ lines = [title ]
43+ lines .extend (f" { command } " for command in commands )
44+ sections .append ("\n " .join (lines ))
45+
46+ return "\n \n " .join (sections )
47+
48+
49+ CLI_DESCRIPTION = build_description (
2850 """
2951 Manage multiple VCS repositories from a single configuration file.
52+ """ ,
53+ (
54+ (
55+ "sync" ,
56+ [
57+ 'vcspull sync "*"' ,
58+ 'vcspull sync "django-*"' ,
59+ 'vcspull sync "django-*" flask' ,
60+ 'vcspull sync -c ./myrepos.yaml "*"' ,
61+ 'vcspull sync -c ./myrepos.yaml myproject' ,
62+ ],
63+ ),
64+ (
65+ "import" ,
66+ [
67+ "vcspull import mylib https://github.com/example/mylib.git" ,
68+ "vcspull import -c ./myrepos.yaml mylib git@github.com:example/mylib.git" ,
69+ "vcspull import --scan ~/code" ,
70+ (
71+ "vcspull import --scan ~/code --recursive "
72+ "--workspace-root ~/code --yes"
73+ ),
74+ ],
75+ ),
76+ (
77+ "fmt" ,
78+ [
79+ "vcspull fmt" ,
80+ "vcspull fmt -c ./myrepos.yaml" ,
81+ "vcspull fmt --write" ,
82+ "vcspull fmt --all" ,
83+ ],
84+ ),
85+ ),
86+ )
3087
31- sync 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- import examples:
39- vcspull import mylib https://github.com/example/mylib.git
40- vcspull import -c ./myrepos.yaml mylib git@github.com:example/mylib.git
41- vcspull import --scan ~/code
42- vcspull import --scan ~/code --recursive --workspace-root ~/code --yes
43-
44- fmt examples:
45- vcspull fmt
46- vcspull fmt -c ./myrepos.yaml
47- vcspull fmt --write
48- vcspull fmt --all
49- """ ,
50- ).strip ()
51-
52- SYNC_DESCRIPTION = textwrap .dedent (
88+ SYNC_DESCRIPTION = build_description (
5389 """
5490 sync vcs repos
91+ """ ,
92+ (
93+ (
94+ None ,
95+ [
96+ 'vcspull sync "*"' ,
97+ 'vcspull sync "django-*"' ,
98+ 'vcspull sync "django-*" flask' ,
99+ 'vcspull sync -c ./myrepos.yaml "*"' ,
100+ 'vcspull sync -c ./myrepos.yaml myproject' ,
101+ ],
102+ ),
103+ ),
104+ )
55105
56- examples:
57- vcspull sync "*"
58- vcspull sync "django-*"
59- vcspull sync "django-*" flask
60- vcspull sync -c ./myrepos.yaml "*"
61- vcspull sync -c ./myrepos.yaml myproject
62- """ ,
63- ).strip ()
64-
65- IMPORT_DESCRIPTION = textwrap .dedent (
106+ IMPORT_DESCRIPTION = build_description (
66107 """
67108 Import repositories into a vcspull configuration file.
68109
69110 Provide NAME and URL to add a single repository, or use --scan to
70111 discover existing git repositories within a directory.
112+ """ ,
113+ (
114+ (
115+ None ,
116+ [
117+ "vcspull import mylib https://github.com/example/mylib.git" ,
118+ "vcspull import -c ./myrepos.yaml mylib git@github.com:example/mylib.git" ,
119+ "vcspull import --scan ~/code" ,
120+ (
121+ "vcspull import --scan ~/code --recursive "
122+ "--workspace-root ~/code --yes"
123+ ),
124+ ],
125+ ),
126+ ),
127+ )
71128
72- examples:
73- vcspull import mylib https://github.com/example/mylib.git
74- vcspull import -c ./myrepos.yaml mylib git@github.com:example/mylib.git
75- vcspull import --scan ~/code
76- vcspull import --scan ~/code --recursive --workspace-root ~/code --yes
77- """ ,
78- ).strip ()
79-
80- FMT_DESCRIPTION = textwrap .dedent (
129+ FMT_DESCRIPTION = build_description (
81130 """
82131 Format vcspull configuration files for consistency.
83132
84133 Normalizes repository entries, sorts sections, and can write changes
85134 back to disk or format all discovered configuration files.
86-
87- examples:
88- vcspull fmt
89- vcspull fmt -c ./myrepos.yaml
90- vcspull fmt --write
91- vcspull fmt --all
92- """ ,
93- ).strip ()
135+ """ ,
136+ (
137+ (
138+ None ,
139+ [
140+ "vcspull fmt" ,
141+ "vcspull fmt -c ./myrepos.yaml" ,
142+ "vcspull fmt --write" ,
143+ "vcspull fmt --all" ,
144+ ],
145+ ),
146+ ),
147+ )
94148
95149
96150@overload
@@ -109,7 +163,7 @@ def create_parser(
109163 """Create CLI argument parser for vcspull."""
110164 parser = argparse .ArgumentParser (
111165 prog = "vcspull" ,
112- formatter_class = argparse . RawDescriptionHelpFormatter ,
166+ formatter_class = VcspullHelpFormatter ,
113167 description = CLI_DESCRIPTION ,
114168 )
115169 parser .add_argument (
@@ -130,23 +184,23 @@ def create_parser(
130184 sync_parser = subparsers .add_parser (
131185 "sync" ,
132186 help = "synchronize repos" ,
133- formatter_class = argparse . RawDescriptionHelpFormatter ,
187+ formatter_class = VcspullHelpFormatter ,
134188 description = SYNC_DESCRIPTION ,
135189 )
136190 create_sync_subparser (sync_parser )
137191
138192 import_parser = subparsers .add_parser (
139193 "import" ,
140194 help = "import repository or scan filesystem for repositories" ,
141- formatter_class = argparse . RawDescriptionHelpFormatter ,
195+ formatter_class = VcspullHelpFormatter ,
142196 description = IMPORT_DESCRIPTION ,
143197 )
144198 create_import_subparser (import_parser )
145199
146200 fmt_parser = subparsers .add_parser (
147201 "fmt" ,
148202 help = "format vcspull configuration files" ,
149- formatter_class = argparse . RawDescriptionHelpFormatter ,
203+ formatter_class = VcspullHelpFormatter ,
150204 description = FMT_DESCRIPTION ,
151205 )
152206 create_fmt_subparser (fmt_parser )
0 commit comments