Skip to content

Commit 376a505

Browse files
authored
🔀 Merge pull request #46 from davep/quiet
Add a --quiet switch
2 parents fd177d4 + 0cd30d3 commit 376a505

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# ng2web ChangeLog
22

3+
## Unreleased
4+
5+
**Released: WiP**
6+
7+
- Added the `--quiet` switch.
8+
39
## v1.3.0
410

511
**Released: 2025-12-03**

docs/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ in the guide as the file `index.html`.
7575
Use this switch to optionally specify the output directory for the generated
7676
HTML. By default all HTML files will be generated in the current directory.
7777

78+
### `--quiet`
79+
80+
Silence the conversion progress output.
81+
7882
### `--templates`
7983

8084
Use this switch to optionally specify a location to look for templates that

src/ng2web/ng2web.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ def get_args() -> argparse.Namespace:
9999
default=".",
100100
)
101101

102+
# Add a quiet flag
103+
parser.add_argument(
104+
"-q",
105+
"--quiet",
106+
action="store_true",
107+
help="Write less progress output while working",
108+
)
109+
102110
# Add an optional source of template files.
103111
parser.add_argument(
104112
"-t",
@@ -139,15 +147,19 @@ def about(guide: NortonGuide, output_directory: Path) -> Path:
139147

140148

141149
##############################################################################
142-
def write_about(guide: NortonGuide, output_directory: Path, env: Environment) -> None:
150+
def write_about(
151+
guide: NortonGuide, output_directory: Path, env: Environment, quietly: bool
152+
) -> None:
143153
"""Write the about page for the guide.
144154
145155
Args:
146156
guide: The guide to generate the about name for.
147157
output_directory: The output directory.
148158
env: The template environment.
159+
quietly: Don't log the output.
149160
"""
150-
log(f"Writing about into {about(guide, output_directory)}")
161+
if not quietly:
162+
log(f"Writing about into {about(guide, output_directory)}")
151163
with about(guide, output_directory).open("w") as target:
152164
target.write(env.get_template("about.html").render())
153165

@@ -167,15 +179,19 @@ def css(guide: NortonGuide, output_directory: Path) -> Path:
167179

168180

169181
##############################################################################
170-
def write_css(guide: NortonGuide, output_directory: Path, env: Environment) -> None:
182+
def write_css(
183+
guide: NortonGuide, output_directory: Path, env: Environment, quietly: bool
184+
) -> None:
171185
"""Write the stylesheet for the guide.
172186
173187
Args:
174188
guide: The guide to generate the stylesheet for.
175189
output_directory: The output directory.
176190
env: The template environment.
191+
quietly: Don't log the output.
177192
"""
178-
log(f"Writing stylesheet into {css(guide, output_directory)}")
193+
if not quietly:
194+
log(f"Writing stylesheet into {css(guide, output_directory)}")
179195
with css(guide, output_directory).open("w") as target:
180196
target.write(
181197
env.get_template("base.css").render(
@@ -232,6 +248,7 @@ def write_entry(
232248
output_directory: Path,
233249
make_index: bool,
234250
env: Environment,
251+
quietly: bool,
235252
) -> None:
236253
"""Write the an entry from the guide.
237254
@@ -241,10 +258,12 @@ def write_entry(
241258
output_directory: The output directory.
242259
make_index: Make first entry be `index.html`?
243260
env: The template environment.
261+
quietly: Write without logging?
244262
"""
245-
log(
246-
f"Writing {entry.__class__.__name__.lower()} entry to {entry_file(guide, output_directory, entry, make_index)}"
247-
)
263+
if not quietly:
264+
log(
265+
f"Writing {entry.__class__.__name__.lower()} entry to {entry_file(guide, output_directory, entry, make_index)}"
266+
)
248267
with entry_file(guide, output_directory, entry, make_index).open("w") as target:
249268
target.write(
250269
env.get_template(f"{entry.__class__.__name__.lower()}.html").render(
@@ -418,9 +437,10 @@ def to_html(args: argparse.Namespace) -> None:
418437

419438
with NortonGuide(convert_from) as guide:
420439
# Log some basics.
421-
log(f"Guide: {guide.path}")
422-
log(f"Output directory: {output_directory}")
423-
log(f"Output prefix: {prefix('', guide)}")
440+
if not args.quiet:
441+
log(f"Guide: {guide.path}")
442+
log(f"Output directory: {output_directory}")
443+
log(f"Output prefix: {prefix('', guide)}")
424444

425445
# Bootstrap the template stuff.
426446
env = Environment(
@@ -446,14 +466,14 @@ def to_html(args: argparse.Namespace) -> None:
446466
}
447467

448468
# Write the stylesheet.
449-
write_css(guide, output_directory, env)
469+
write_css(guide, output_directory, env, args.quiet)
450470

451471
# Write the about page.
452-
write_about(guide, output_directory, env)
472+
write_about(guide, output_directory, env, args.quiet)
453473

454474
# Now, for every entry in the guide...
455475
for entry in guide:
456-
write_entry(entry, guide, output_directory, args.index, env)
476+
write_entry(entry, guide, output_directory, args.index, env, args.quiet)
457477

458478

459479
##############################################################################

0 commit comments

Comments
 (0)