Parse command line arguments using Typer.
(argv: Optional[Sequence[str]] = None)
| 152 | |
| 153 | |
| 154 | async def parse_cmd(argv: Optional[Sequence[str]] = None): |
| 155 | """Parse command line arguments using Typer.""" |
| 156 | |
| 157 | app = typer.Typer(add_completion=False) |
| 158 | |
| 159 | @app.callback(invoke_without_command=True) |
| 160 | def main( |
| 161 | platform: Annotated[ |
| 162 | PlatformEnum, |
| 163 | typer.Option( |
| 164 | "--platform", |
| 165 | help="Media platform selection (xhs=XiaoHongShu | dy=Douyin | ks=Kuaishou | bili=Bilibili | wb=Weibo | tieba=Baidu Tieba | zhihu=Zhihu)", |
| 166 | rich_help_panel="Basic Configuration", |
| 167 | ), |
| 168 | ] = _coerce_enum(PlatformEnum, config.PLATFORM, PlatformEnum.XHS), |
| 169 | lt: Annotated[ |
| 170 | LoginTypeEnum, |
| 171 | typer.Option( |
| 172 | "--lt", |
| 173 | help="Login type (qrcode=QR Code | phone=Phone | cookie=Cookie)", |
| 174 | rich_help_panel="Account Configuration", |
| 175 | ), |
| 176 | ] = _coerce_enum(LoginTypeEnum, config.LOGIN_TYPE, LoginTypeEnum.QRCODE), |
| 177 | crawler_type: Annotated[ |
| 178 | CrawlerTypeEnum, |
| 179 | typer.Option( |
| 180 | "--type", |
| 181 | help="Crawler type (search=Search | detail=Detail | creator=Creator)", |
| 182 | rich_help_panel="Basic Configuration", |
| 183 | ), |
| 184 | ] = _coerce_enum(CrawlerTypeEnum, config.CRAWLER_TYPE, CrawlerTypeEnum.SEARCH), |
| 185 | start: Annotated[ |
| 186 | int, |
| 187 | typer.Option( |
| 188 | "--start", |
| 189 | help="Starting page number", |
| 190 | rich_help_panel="Basic Configuration", |
| 191 | ), |
| 192 | ] = config.START_PAGE, |
| 193 | keywords: Annotated[ |
| 194 | str, |
| 195 | typer.Option( |
| 196 | "--keywords", |
| 197 | help="Enter keywords, multiple keywords separated by commas", |
| 198 | rich_help_panel="Basic Configuration", |
| 199 | ), |
| 200 | ] = config.KEYWORDS, |
| 201 | get_comment: Annotated[ |
| 202 | str, |
| 203 | typer.Option( |
| 204 | "--get_comment", |
| 205 | help="Whether to crawl first-level comments, supports yes/true/t/y/1 or no/false/f/n/0", |
| 206 | rich_help_panel="Comment Configuration", |
| 207 | show_default=True, |
| 208 | ), |
| 209 | ] = str(config.ENABLE_GET_COMMENTS), |
| 210 | get_sub_comment: Annotated[ |
| 211 | str, |