Skip to content

Commit 9c66fa4

Browse files
Merge pull request #6 from arthur-debert:better-docs
Better devx
2 parents d4ba139 + e6a216f commit 9c66fa4

File tree

14 files changed

+966
-92
lines changed

14 files changed

+966
-92
lines changed

.markdownlint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "MD013": false, "MD029": false, "MD014": false }

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,33 @@ Access deeply **nested values** using intuitive dot-separated paths (e.g., **`pe
3535

3636
Dotcat is a good **unix citizen** with well structured **exit codes** so it can take part of your command pipeline like cat or grep would.
3737

38+
Includes **ZSH autocompletion** for both file paths and dotted paths, making it even easier to navigate complex data structures.
39+
3840
## Installation
3941

4042
If you have a global pip install, this will install dotcat globally:
4143

4244
```bash
4345
pip install dotcat
4446
```
47+
48+
## ZSH Completion
49+
50+
Dotcat comes with ZSH completion support that is automatically installed when you install the package with pip. The installation script will:
51+
52+
1. Look for appropriate ZSH completion directories
53+
2. Install the completion files if possible
54+
3. Notify you of the installation location
55+
56+
If the automatic installation fails, you can manually install the completions:
57+
58+
```bash
59+
# Copy the completion script to your ZSH completions directory
60+
mkdir -p ~/.zsh/completions
61+
cp /path/to/installed/package/zsh/_dotcat ~/.zsh/completions/
62+
63+
# Or run the installation script directly
64+
dotcat-install-completions
65+
```
66+
67+
See the [ZSH completion README](zsh/README.md) for detailed instructions.

bin/usage-samples

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#! /usr/bin/env bash
2+
3+
# Don't exit on error
4+
set +e
5+
6+
## this files just collects all possible outputs for regular and errors so
7+
## that we can test the output of the program
8+
9+
# Function to indent each line of input by 4 spaces
10+
function indent() {
11+
sed 's/^/ /'
12+
}
13+
14+
function run_command() {
15+
local description="$2"
16+
echo ""
17+
echo -e "\033[1m$description: \033[0m"
18+
echo ""
19+
eval "$1" | indent
20+
echo ""
21+
}
22+
23+
run_command "dotcat" "no arguments, quick usage"
24+
25+
run_command "dotcat --help" "--help"
26+
27+
run_command "dotcat help" "help"
28+
29+
run_command "dotcat pyproject.toml project.authors" "correct usage, both file exists and keys is found"
30+
31+
run_command "dotcat pyproject.toml" "missing dotted-path"
32+
33+
run_command "dotcat project.authors" "missing file"
34+
35+
run_command "dotcat nothere.toml project.authors" "no such file"
36+
37+
run_command "dotcat pyproject.toml project.nothere" "missing dotted-path"
38+
39+
run_command "dotcat tests/fixtures/malformed.json python.editor.tabSize" "malformed file"
40+
41+
# Reset exit behavior
42+
set -e

pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
packages = [{ include = "dotcat", from = "src" }]
7-
include = ["templates", "template/**", "LICENSE", "README.md"]
7+
include = ["templates", "template/**", "LICENSE", "README.md", "zsh/**"]
88
exclude = ["tests"]
99

1010
[project]
11-
version = "0.9.0"
11+
version = "0.9.1"
1212

1313
name = "dotcat"
1414
readme = { file = "README.md", content-type = "text/markdown" }
@@ -79,7 +79,8 @@ docs = [
7979

8080
[project.scripts]
8181
dotcat = "dotcat:main"
82-
82+
install-dotcat-completions = "dotcat.install_completions:main"
83+
dotcat-install-completions = "dotcat.install_completions:main"
8384

8485
[tool.pytest.ini_options]
8586
addopts = "-ra -q"

src/dotcat/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
from .dotcat import run, main
1+
from .dotcat import run, main, USAGE, HELP
2+
from . import install_completions
3+
4+
__all__ = ["run", "main", "USAGE", "HELP", "install_completions"]

src/dotcat/__version__.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,38 @@
1-
import importlib;
2-
__version__ = importlib.metadata.version('dotcat')
1+
from importlib import metadata
2+
import pathlib
3+
import toml
4+
5+
6+
def get_version_from_toml():
7+
"""
8+
Extract version from pyproject.toml file.
9+
10+
Returns:
11+
str: The version string or "unknown" if not found
12+
"""
13+
try:
14+
# Find the project root (where pyproject.toml is located)
15+
current_file = pathlib.Path(__file__)
16+
project_root = (
17+
current_file.parent.parent.parent
18+
) # src/dotcat -> src -> project root
19+
pyproject_path = project_root / "pyproject.toml"
20+
21+
if pyproject_path.exists():
22+
# Parse pyproject.toml using the toml library
23+
pyproject_data = toml.load(pyproject_path)
24+
return pyproject_data.get("project", {}).get("version", "unknown")
25+
except Exception:
26+
pass
27+
return "unknown"
28+
29+
30+
# Try to get version from package metadata (works when installed)
31+
try:
32+
__version__ = metadata.version("dotcat")
33+
except metadata.PackageNotFoundError:
34+
# Fallback: read version from pyproject.toml (works during development/CI)
35+
__version__ = get_version_from_toml()
36+
37+
# Make the function available for testing
38+
__all__ = ["get_version_from_toml"]

0 commit comments

Comments
 (0)