1212from collections .abc import Sequence
1313from typing import Any , Optional , Union
1414
15- from libvcs ._internal .run import run
15+ from libvcs ._internal .run import ProgressCallbackProtocol , run
1616from libvcs ._internal .types import StrOrBytesPath , StrPath
1717
1818_CMD = Union [StrOrBytesPath , Sequence [StrOrBytesPath ]]
@@ -34,7 +34,14 @@ class HgPagerType(enum.Enum):
3434
3535
3636class Hg :
37- def __init__ (self , * , dir : StrPath ) -> None :
37+ progress_callback : Optional [ProgressCallbackProtocol ] = None
38+
39+ def __init__ (
40+ self ,
41+ * ,
42+ dir : StrPath ,
43+ progress_callback : Optional [ProgressCallbackProtocol ] = None ,
44+ ) -> None :
3845 """Lite, typed, pythonic wrapper for hg(1).
3946
4047 Parameters
@@ -54,6 +61,8 @@ def __init__(self, *, dir: StrPath) -> None:
5461 else :
5562 self .dir = pathlib .Path (dir )
5663
64+ self .progress_callback = progress_callback
65+
5766 def __repr__ (self ) -> str :
5867 return f"<Hg dir={ self .dir } >"
5968
@@ -171,6 +180,9 @@ def run(
171180 if help is True :
172181 cli_args .append ("--help" )
173182
183+ if self .progress_callback is not None :
184+ kwargs ["callback" ] = self .progress_callback
185+
174186 return run (
175187 args = cli_args ,
176188 check_returncode = True if check_returncode is None else check_returncode ,
0 commit comments