Skip to content

Commit

Permalink
Emit user admonition on make-config subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Apr 21, 2024
1 parent 54af569 commit 555248e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Unreleased
- Grafana Dashboard: Trim identifying information: `id`, `uid`,
`version`. Thanks, @bee-mois.
- Emit user admonition on `make-config` subcommand. Thanks,
@bee-mois.

## v0.0.3 - 2024-04-20
- Tests: Make sensor tests work, using a fake sysfs filesystem
Expand Down
4 changes: 4 additions & 0 deletions ds18b20_datalogger/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from ds18b20_datalogger.core import read_ds18b20_sensor_matrix, send_measurement_mqtt
from ds18b20_datalogger.model import Settings
from ds18b20_datalogger.util import msg

if sys.version_info < (3, 9):
from importlib_resources import files # pragma: nocover
Expand Down Expand Up @@ -33,6 +34,9 @@ def main():
send_measurement_mqtt(settings.mqtt, reading)

elif subcommand == "make-config":
print( # noqa: T201
msg("Please make sure to edit the configuration file before starting the program."), file=sys.stderr
)
config_template = files("ds18b20_datalogger") / "datalogger.yaml"
print(config_template.read_text(), file=sys.stdout) # noqa: T201

Expand Down
7 changes: 7 additions & 0 deletions ds18b20_datalogger/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ def partition(lst, chunksize: int) -> Generator[List[Any], None, None]:
"""
for i in range(0, len(lst), chunksize):
yield list(itertools.islice(lst, i, i + chunksize))


def msg(text: str):
"""
Return a text armoured with ANSI codes to make it appear in bright yellow.
"""
return f"\033[1;33m{text}\033[0m"
6 changes: 4 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ def test_cli_run_almost_success():


def test_cli_make_config():
exitcode, output = invoke("ds18b20-datalogger make-config")
config = yaml.safe_load(output)
command = shlex.split("ds18b20-datalogger make-config")
process = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # noqa: S603
config = yaml.safe_load(process.stdout)
assert "mqtt" in config
assert "one-wire" in config
assert b"Please make sure to edit the configuration" in process.stderr


def test_cli_make_dashboard():
Expand Down

0 comments on commit 555248e

Please sign in to comment.