refresh_command.py¶
clew/refresh_command.py
`clew refresh` — bring an index current after an edit: fast in place when it can, full when not.
refresh_main
int clew.refresh_command.refresh_main(list[str] argv)
Refresh an index, fast tier first.
Called by _build, _build, _ensure_index, main, wiki_main
Tested by
Calls _build_argparser, _run_pipeline, target_for, try_fast_refresh
Source · 32 lines
def refresh_main(argv: list[str]) -> int:
"""THE FALLBACK IS THE ORDINARY BUILD, through the same `_run_pipeline` a plain `clew` runs,
so a refused fast tier produces exactly the index a full build would — and that build drops
any pending `fast.*` record, because it writes a fresh database.
@brief Entry point for `clew refresh`.
@return 0.
@version 1
"""
from .cli import _build_argparser, _run_pipeline
from .fasttier import try_fast_refresh
parser = argparse.ArgumentParser(
prog=f"clew {REFRESH_COMMAND}",
description="Refresh an index after an edit: in place when possible, else a full build.",
)
parser.add_argument("--repo-root", help="working tree (default: the current directory)")
parser.add_argument("--output", help="index path (default: where a plain build writes it)")
args = parser.parse_args(argv)
repo = Path(args.repo_root).expanduser().resolve() if args.repo_root else Path.cwd().resolve()
if args.output:
output = Path(args.output).expanduser().resolve()
else:
from .mcp_server.state import target_for
output = Path(target_for(repo).db_path)
if try_fast_refresh(output, repo, output.with_name(output.name + ".idxcache")) is None:
logger.info("refresh: running a full build")
_run_pipeline(
_build_argparser().parse_args(["--output", str(output), "--repo-root", str(repo)])
)
return 01 more lines, not shown