Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## \[Unreleased\]
## \[0.8.0\]

### Added

- Search with jmspath (@tiberium)
- Add validation whether path exists

## \[0.7.0\]

### Added

Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "toml-cli"
version = "0.7.0"
version = "0.8.0"
description = "Command line interface to read and write keys/values to/from toml files"
requires-python = ">=3.10"
dependencies = [
Expand All @@ -14,11 +14,10 @@ scripts = { toml = 'toml_cli:main'}

[tool.ruff]
line-length = 120
target-version = "py38"
target-version = "py310"

[tool.ruff.lint.isort]
force-single-line = true
known-first-party = ["pytest_nlcov"]

[tool.hatch.build.targets.wheel]
packages = ["toml_cli"]
Expand Down
13 changes: 0 additions & 13 deletions tests/toml_cli/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@
runner = CliRunner()


# def normalized(item):
# if isinstance(item, dict):
# return sorted((key, normalized(values)) for key, values in item.items())
# if isinstance(item, list):
# return sorted(normalized(x) for x in item)
# else:
# return item


# def compare(item1, item2):
# assert normalized(eval(item1)) == normalized(item2)


def test_get_value(tmp_path: pathlib.Path):
test_toml_path = tmp_path / "test.toml"
test_toml_path.write_text(
Expand Down
22 changes: 17 additions & 5 deletions toml_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@
app = typer.Typer(no_args_is_help=True)


DEFAULT_TOML_PATH = pathlib.Path("config.toml")


def path_callback(value: pathlib.Path):
if not value.exists():
raise typer.BadParameter(f"{value} does not exists")
return value


@app.command("get")
def get(
key: Optional[str] = typer.Argument(None),
toml_path: pathlib.Path = typer.Option(pathlib.Path("config.toml")),
toml_path: pathlib.Path = typer.Option(DEFAULT_TOML_PATH, callback=path_callback),
default: Optional[str] = typer.Option(None),
):
"""Get a value from a toml file."""
Expand Down Expand Up @@ -63,7 +72,7 @@ def get(
def set_(
key: str,
value: str,
toml_path: pathlib.Path = typer.Option(pathlib.Path("config.toml")),
toml_path: pathlib.Path = typer.Option(DEFAULT_TOML_PATH, callback=path_callback),
to_int: bool = typer.Option(False),
to_float: bool = typer.Option(False),
to_bool: bool = typer.Option(False),
Expand Down Expand Up @@ -125,7 +134,7 @@ def set_(
@app.command("add_section")
def add_section(
key: str,
toml_path: pathlib.Path = typer.Option(pathlib.Path("config.toml")),
toml_path: pathlib.Path = typer.Option(DEFAULT_TOML_PATH, callback=path_callback),
):
"""Add a section with the given key."""
toml_part = toml_file = tomlkit.parse(toml_path.read_text())
Expand All @@ -139,7 +148,10 @@ def add_section(


@app.command("unset")
def unset(key: str, toml_path: pathlib.Path = typer.Option(pathlib.Path("config.toml"))):
def unset(
key: str,
toml_path: pathlib.Path = typer.Option(DEFAULT_TOML_PATH, callback=path_callback),
):
"""Unset a value from a toml file."""
toml_part = toml_file = tomlkit.parse(toml_path.read_text())

Expand All @@ -157,7 +169,7 @@ def unset(key: str, toml_path: pathlib.Path = typer.Option(pathlib.Path("config.
@app.command("search")
def search(
jmespath_expression: str,
toml_path: pathlib.Path = typer.Option(pathlib.Path("config.toml")),
toml_path: pathlib.Path = typer.Option(DEFAULT_TOML_PATH, callback=path_callback),
):
"""Search for a value in a toml file using JMESPath query."""
toml_data = tomlkit.parse(toml_path.read_text())
Expand Down
Loading