Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.

Commit ae76c58

Browse files
committed
feat(pems_data): simple CLI for the cache
$ pems-cache -h usage: pems-cache [-h] [--key KEY] [--value VALUE] [{check,get,set}] Simple CLI for the cache positional arguments: {check,get,set} the operation to perform options: -h, --help show this help message and exit --key/-k KEY the item's key, required for get/set --value/-v VALUE the item's value, required for set
1 parent 6f9c373 commit ae76c58

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

pems_data/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ dynamic = ["version"]
55
requires-python = ">=3.12"
66
dependencies = ["boto3==1.39.7", "pandas==2.3.0", "redis==6.2.0"]
77

8+
[project.scripts]
9+
pems-cache = "pems_data.cli:cache"
10+
811
[build-system]
912
requires = ["setuptools>=75", "setuptools_scm>=8"]
1013
build-backend = "setuptools.build_meta"

pems_data/src/pems_data/cli.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import argparse
2+
import sys
3+
4+
from pems_data.cache import Cache
5+
6+
7+
def cache(): # prama: no cover
8+
parser = argparse.ArgumentParser("pems-cache", description="Simple CLI for the cache")
9+
parser.add_argument("op", choices=("check", "get", "set"), default="check", nargs="?", help="the operation to perform")
10+
parser.add_argument("--key", "-k", required=False, type=str, help="the item's key, required for get/set")
11+
parser.add_argument("--value", "-v", required=False, type=str, help="the item's value, required for set")
12+
parsed_args = parser.parse_args(sys.argv[1:])
13+
14+
c = Cache()
15+
16+
match parsed_args.op:
17+
case "get":
18+
if parsed_args.key:
19+
print(f"[{parsed_args.key}]: {c.get(parsed_args.key)}")
20+
else:
21+
parser.print_usage()
22+
raise SystemExit(1)
23+
case "set":
24+
if parsed_args.key and parsed_args.value:
25+
print(f"[{parsed_args.key}] = '{parsed_args.value}'")
26+
c.set(parsed_args.key, parsed_args.value)
27+
else:
28+
parser.print_usage()
29+
raise SystemExit(1)
30+
case _:
31+
print(f"cache is available: {c.is_available()}")

0 commit comments

Comments
 (0)