feat: add --version flag to the CLI (#303)
This commit is contained in:
+3
-1
@@ -2,6 +2,7 @@ from pathlib import Path
|
|||||||
from subprocess import check_output
|
from subprocess import check_output
|
||||||
from sys import executable as python_executable
|
from sys import executable as python_executable
|
||||||
|
|
||||||
|
from scrapling import __version__
|
||||||
from scrapling.core.utils import log
|
from scrapling.core.utils import log
|
||||||
from scrapling.engines.toolbelt.custom import Response
|
from scrapling.engines.toolbelt.custom import Response
|
||||||
from scrapling.core.utils._shell import _CookieParser, _ParseHeaders
|
from scrapling.core.utils._shell import _CookieParser, _ParseHeaders
|
||||||
@@ -10,7 +11,7 @@ from scrapling.core._types import List, Optional, Dict, Tuple, Any, Callable
|
|||||||
from orjson import loads as json_loads, JSONDecodeError
|
from orjson import loads as json_loads, JSONDecodeError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from click import command, option, Choice, group, argument
|
from click import command, option, Choice, group, argument, version_option
|
||||||
except (ImportError, ModuleNotFoundError) as e:
|
except (ImportError, ModuleNotFoundError) as e:
|
||||||
raise ModuleNotFoundError(
|
raise ModuleNotFoundError(
|
||||||
"You need to install scrapling with any of the extras to enable Shell commands. See: https://scrapling.readthedocs.io/en/latest/#installation"
|
"You need to install scrapling with any of the extras to enable Shell commands. See: https://scrapling.readthedocs.io/en/latest/#installation"
|
||||||
@@ -650,6 +651,7 @@ def stealthy_fetch(
|
|||||||
|
|
||||||
|
|
||||||
@group()
|
@group()
|
||||||
|
@version_option(version=__version__, prog_name="Scrapling")
|
||||||
def main():
|
def main():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ from unittest.mock import patch, MagicMock
|
|||||||
import pytest_httpbin
|
import pytest_httpbin
|
||||||
|
|
||||||
from scrapling.parser import Selector
|
from scrapling.parser import Selector
|
||||||
|
from scrapling import __version__
|
||||||
from scrapling.cli import (
|
from scrapling.cli import (
|
||||||
shell, mcp, get, post, put, delete, fetch, stealthy_fetch
|
main, shell, mcp, get, post, put, delete, fetch, stealthy_fetch
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -32,6 +33,12 @@ class TestCLI:
|
|||||||
def runner(self):
|
def runner(self):
|
||||||
return CliRunner()
|
return CliRunner()
|
||||||
|
|
||||||
|
def test_version_flag(self, runner):
|
||||||
|
"""Test that the --version flag prints the Scrapling version and exits"""
|
||||||
|
result = runner.invoke(main, ['--version'])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert result.output.strip() == f'Scrapling, version {__version__}'
|
||||||
|
|
||||||
def test_shell_command(self, runner):
|
def test_shell_command(self, runner):
|
||||||
"""Test shell command"""
|
"""Test shell command"""
|
||||||
with patch('scrapling.core.shell.CustomShell') as mock_shell:
|
with patch('scrapling.core.shell.CustomShell') as mock_shell:
|
||||||
|
|||||||
Reference in New Issue
Block a user