Skip to content

Commit 3ce5ad1

Browse files
sveneberthclaude
andauthored
feat: Add progress logging and summary to script pull (#216)
Show per-file status ([new], [ok], [diff], [forced]) while pulling and print a summary (new/updated/skipped/unchanged) at the end. --- Requires #215 to be merged --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 40da685 commit 3ce5ad1

1 file changed

Lines changed: 37 additions & 8 deletions

File tree

src/viur_cli/scriptor/cli.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,35 @@ async def main():
144144
tree = await modules.get_module("script")
145145
working_dir = scriptor_config.get("working_dir")
146146

147+
stats = {"new": 0, "updated": 0, "skipped": 0, "unchanged": 0, "dirs": 0}
148+
147149
async def process_entry(entry: dict, is_node: bool):
148150
_path = os.path.join(working_dir, entry["path"].lstrip("/"))
149151

150152
if is_node:
151153
if not os.path.exists(_path):
154+
click.echo(click.style(f" mkdir {entry['path']}", fg="blue"))
152155
os.makedirs(_path)
156+
stats["dirs"] += 1
153157
else:
158+
click.echo(f" check {entry['path']}", nl=False)
159+
154160
def create_file():
155161
with open(_path, "a+") as f:
156162
f.write(entry["script"])
157163

158-
click.echo(f"Pull {_path}")
159-
160164
if os.path.exists(_path):
161165
if force:
166+
with open(_path, "r") as f:
167+
changed = f.read().splitlines() != entry["script"].splitlines()
162168
os.remove(_path)
163169
create_file()
170+
if changed:
171+
click.echo(click.style(" [updated]", fg="yellow"))
172+
stats["updated"] += 1
173+
else:
174+
click.echo(click.style(" [ok]", fg="green"))
175+
stats["unchanged"] += 1
164176
else:
165177
with open(_path, "r") as f:
166178
local_content = f.read()
@@ -173,23 +185,33 @@ def create_file():
173185
lineterm="",
174186
))
175187
if diff:
188+
click.echo(click.style(" [diff]", fg="yellow"))
176189
for line in diff:
177190
if line.startswith("+++") or line.startswith("---"):
178-
click.echo(click.style(line, bold=True), nl=True)
191+
click.echo(click.style(line, bold=True))
179192
elif line.startswith("@@"):
180-
click.echo(click.style(line, fg="cyan"), nl=True)
193+
click.echo(click.style(line, fg="cyan"))
181194
elif line.startswith("+"):
182-
click.echo(click.style(line, fg="green"), nl=True)
195+
click.echo(click.style(line, fg="green"))
183196
elif line.startswith("-"):
184-
click.echo(click.style(line, fg="red"), nl=True)
197+
click.echo(click.style(line, fg="red"))
185198
else:
186-
click.echo(line, nl=True)
199+
click.echo(line)
187200
if click.confirm(f"Overwrite local {entry['path']} with remote version?"):
188201
os.remove(_path)
189202
create_file()
190-
203+
stats["updated"] += 1
204+
else:
205+
stats["skipped"] += 1
206+
else:
207+
click.echo(click.style(" [ok]", fg="green"))
208+
stats["unchanged"] += 1
191209
else:
210+
click.echo(click.style(" [new]", fg="green"))
192211
create_file()
212+
stats["new"] += 1
213+
214+
click.echo("Fetching scripts from server...")
193215

194216
# Process nodes first
195217
async for node in tree.list(skel_type="node"):
@@ -199,6 +221,13 @@ def create_file():
199221
async for leaf in tree.list(skel_type="leaf"):
200222
await process_entry(leaf, False)
201223

224+
click.echo("")
225+
click.echo(click.style("Summary:", bold=True))
226+
click.echo(f" new: {stats['new']}")
227+
click.echo(f" updated: {stats['updated']}")
228+
click.echo(f" skipped: {stats['skipped']}")
229+
click.echo(f" unchanged: {stats['unchanged']}")
230+
202231
asyncio.run(main())
203232

204233

0 commit comments

Comments
 (0)