sparql-cli 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sparql/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ """SPARQL CLI - Query SPARQL endpoints from the command line."""
2
+
3
+ from sparql import cli, core, formatters
4
+ from sparql._version import __version__
5
+
6
+ __all__ = ["__version__", "cli", "core", "formatters"]
sparql/__main__.py ADDED
@@ -0,0 +1,6 @@
1
+ """Module entry point for python -m sparql."""
2
+
3
+ from sparql.cli.main import app
4
+
5
+ if __name__ == "__main__":
6
+ app()
sparql/_version.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
sparql/cli/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from sparql.cli.main import app
2
+
3
+ __all__ = ["app"]
@@ -0,0 +1 @@
1
+ """CLI commands for SPARQL CLI."""
@@ -0,0 +1,143 @@
1
+ """Config command for displaying and managing configuration."""
2
+
3
+ import json
4
+ import os
5
+
6
+ import typer
7
+
8
+ from sparql.core.config import AuthType, load_config, resolve_config
9
+ from sparql.core.exceptions import ConfigError
10
+ from sparql.core.exit_codes import ExitCode
11
+
12
+ config_app = typer.Typer(help="Configuration management commands")
13
+
14
+ # Width of separator line in human-readable output
15
+ SEPARATOR_WIDTH = 40
16
+
17
+
18
+ @config_app.command("show")
19
+ def show(
20
+ json_output: bool = typer.Option(
21
+ False,
22
+ "--json",
23
+ help="Output as JSON",
24
+ ),
25
+ ) -> None:
26
+ """Display current effective configuration with source attribution."""
27
+ try:
28
+ config = load_config()
29
+ resolved = resolve_config(config)
30
+ except ConfigError as e:
31
+ typer.echo(f"Config error: {e}", err=True)
32
+ raise typer.Exit(ExitCode.CONFIG_ERROR) from e
33
+
34
+ # Determine sources for each setting
35
+ env_endpoint = os.getenv("SPARQL_ENDPOINT")
36
+ env_timeout = os.getenv("SPARQL_TIMEOUT")
37
+ env_profile = os.getenv("SPARQL_PROFILE")
38
+ env_user = os.getenv("SPARQL_USER")
39
+
40
+ if json_output:
41
+ output = {
42
+ "default_endpoint": config.default_endpoint,
43
+ "effective": {
44
+ "endpoint": resolved.endpoint,
45
+ "endpoint_type": resolved.endpoint_type.value,
46
+ "timeout": resolved.timeout,
47
+ "format": resolved.format,
48
+ "auth_type": resolved.auth_type.value,
49
+ "username": resolved.username,
50
+ "has_password": resolved.password is not None,
51
+ "database": resolved.database,
52
+ "namespace": resolved.namespace,
53
+ "repository": resolved.repository,
54
+ "reasoning": resolved.reasoning,
55
+ },
56
+ "profiles": {
57
+ name: {
58
+ "url": profile.url,
59
+ "endpoint_type": profile.endpoint_type.value,
60
+ "timeout": profile.timeout,
61
+ "auth_type": profile.auth_type.value,
62
+ "username": profile.username,
63
+ "has_password": profile.password is not None,
64
+ "database": profile.database,
65
+ "namespace": profile.namespace,
66
+ "repository": profile.repository,
67
+ "reasoning": profile.reasoning,
68
+ }
69
+ for name, profile in config.endpoints.items()
70
+ },
71
+ }
72
+ typer.echo(json.dumps(output, indent=2))
73
+ else:
74
+ typer.echo("Current Configuration")
75
+ typer.echo("=" * SEPARATOR_WIDTH)
76
+ typer.echo("")
77
+ typer.echo(f"Default profile: {config.default_endpoint}")
78
+ if env_profile:
79
+ typer.echo(f" (override: SPARQL_PROFILE={env_profile})")
80
+ typer.echo("")
81
+ typer.echo("Effective Settings:")
82
+ typer.echo(f" endpoint: {resolved.endpoint}")
83
+ if env_endpoint:
84
+ typer.echo(" (override: SPARQL_ENDPOINT)")
85
+ typer.echo(f" type: {resolved.endpoint_type.value}")
86
+ typer.echo(f" timeout: {resolved.timeout}s")
87
+ if env_timeout:
88
+ typer.echo(" (override: SPARQL_TIMEOUT)")
89
+ typer.echo(f" format: {resolved.format}")
90
+ if resolved.auth_type != AuthType.NONE:
91
+ typer.echo(f" auth: {resolved.auth_type.value}")
92
+ typer.echo(f" username: {resolved.username or '(not set)'}")
93
+ if env_user:
94
+ typer.echo(" (override: SPARQL_USER)")
95
+ typer.echo(f" password: {'***' if resolved.password else '(not set)'}")
96
+ # Show server-specific params if set
97
+ if resolved.database:
98
+ typer.echo(f" database: {resolved.database}")
99
+ if resolved.namespace:
100
+ typer.echo(f" namespace: {resolved.namespace}")
101
+ if resolved.repository:
102
+ typer.echo(f" repository: {resolved.repository}")
103
+ if resolved.reasoning is not None:
104
+ typer.echo(f" reasoning: {resolved.reasoning}")
105
+ typer.echo("")
106
+
107
+ if config.endpoints:
108
+ typer.echo("Configured Profiles:")
109
+ for name, profile in config.endpoints.items():
110
+ marker = " *" if name == config.default_endpoint else ""
111
+ typer.echo(f" [{name}]{marker}")
112
+ typer.echo(f" url: {profile.url}")
113
+ typer.echo(f" type: {profile.endpoint_type.value}")
114
+ if profile.timeout:
115
+ typer.echo(f" timeout: {profile.timeout}s")
116
+ if profile.auth_type != AuthType.NONE:
117
+ typer.echo(f" auth: {profile.auth_type.value}")
118
+ if profile.username:
119
+ typer.echo(f" user: {profile.username}")
120
+ # Server-specific params
121
+ if profile.database:
122
+ typer.echo(f" database: {profile.database}")
123
+ if profile.namespace:
124
+ typer.echo(f" namespace: {profile.namespace}")
125
+ if profile.repository:
126
+ typer.echo(f" repository: {profile.repository}")
127
+ if profile.reasoning is not None:
128
+ typer.echo(f" reasoning: {profile.reasoning}")
129
+ else:
130
+ typer.echo("Profiles: none configured")
131
+
132
+
133
+ @config_app.command("profiles")
134
+ def profiles() -> None:
135
+ """List available endpoint profiles. Default profile is marked with *."""
136
+ try:
137
+ config = load_config()
138
+ except ConfigError as e:
139
+ typer.echo(f"Config error: {e}", err=True)
140
+ raise typer.Exit(ExitCode.CONFIG_ERROR) from e
141
+ for name in config.endpoints:
142
+ marker = " *" if name == config.default_endpoint else ""
143
+ typer.echo(f"{name}{marker}")