Download testbed/PyThaiNLP__pythainlp/pythainlp/cli/__init__.py from hc99/FEA-Bench: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/datasets/hc99/FEA-Bench/resolve/main/testbed/PyThaiNLP__pythainlp/pythainlp/cli/__init__.py
- Command line
-
hf download hf://datasets/hc99/FEA-Bench/testbed/PyThaiNLP__pythainlp/pythainlp/cli/__init__.py
-
curl -L -o __init__.py https://huggingface.co/datasets/hc99/FEA-Bench/resolve/main/testbed/PyThaiNLP__pythainlp/pythainlp/cli/__init__.py
1.05 kB
| # -*- coding: utf-8 -*- | |
| # SPDX-FileCopyrightText: 2016-2025 PyThaiNLP Project | |
| # SPDX-FileType: SOURCE | |
| # SPDX-License-Identifier: Apache-2.0 | |
| """Command line helpers.""" | |
| import io | |
| import sys | |
| from argparse import ArgumentError, ArgumentParser | |
| sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8") | |
| sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding="utf-8") | |
| # a command should start with a verb when possible | |
| COMMANDS = sorted(["data", "soundex", "tag", "tokenize", "benchmark"]) | |
| CLI_NAME = "thainlp" | |
| def make_usage(command: str) -> dict: | |
| prog = f"{CLI_NAME} {command}" | |
| return {"prog": prog, "usage": f"{prog} [options]"} | |
| def exit_if_empty(command: str, parser: ArgumentParser) -> None: | |
| """Print help and exit if command is empty. | |
| :param command: command from command line | |
| :type command: str | |
| :param parser: parser object of the app | |
| :type parser: ArgumentParser | |
| """ | |
| if not command: | |
| if parser: | |
| parser.print_help() | |
| raise ArgumentError(None, "No command provided.") | |