Skip to content

Commit 7c524a3

Browse files
authored
Merge pull request #23 from pdecat/feat/cli
Add script to allow installation with pipx and simplify CLI usage
2 parents 6e2d081 + b7a9869 commit 7c524a3

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The JSONata documentation can be found [here](https://jsonata.org).
1818
## Installation
1919

2020
```
21-
pip install jsonata-python
21+
pipx install jsonata-python
2222
```
2323

2424
## Getting Started
@@ -39,8 +39,8 @@ A very simple start:
3939
The CLI provides the same functionality as the [Dashjoin JSONata CLI](https://github.com/dashjoin/jsonata-cli).
4040

4141
```
42-
% python3 -m jsonata.cli
43-
usage: jsonata.cli [-h] [-v] [-e <file>] [-i <arg>] [-ic <arg>] [-f {auto,json,string}] [-o <arg>] [-oc <arg>] [-time] [-c] [-b <json-string>]
42+
% jsonata -h
43+
usage: jsonata [-h] [-v] [-e <file>] [-i <arg>] [-ic <arg>] [-f {auto,json,string}] [-o <arg>] [-oc <arg>] [-time] [-c] [-b <json-string>]
4444
[-bf <file>] [-it]
4545
[expr]
4646
@@ -76,19 +76,19 @@ options:
7676
### Examples
7777

7878
```
79-
% echo '{"a":"hello", "b":" world"}' | python3 -m jsonata.cli '(a & b)'
79+
% echo '{"a":"hello", "b":" world"}' | jsonata '(a & b)'
8080
hello world
8181
82-
% echo '{"a":"hello", "b":" world"}' | python3 -m jsonata.cli -o helloworld.json $
82+
% echo '{"a":"hello", "b":" world"}' | jsonata -o helloworld.json $
8383
# helloworld.json written
8484
85-
% ls | python3 -m jsonata.cli $
85+
% ls | jsonata $
8686
helloworld.json
8787
88-
% ps -o pid="",%cpu="",%mem="" | python3 -m jsonata.cli '$.$split(/\n/).$trim().[ $split(/\s+/)[$length()>0].$number() ]' -c
88+
% ps -o pid="",%cpu="",%mem="" | jsonata '$.$split(/\n/).$trim().[ $split(/\s+/)[$length()>0].$number() ]' -c
8989
[[4105,0,0],[4646,0,0],[4666,0,0],[33696,0,0]...]
9090
91-
% curl -s https://raw.githubusercontent.com/jsonata-js/jsonata/master/test/test-suite/datasets/dataset1.json | python3 -m jsonata.cli '{"Name": FirstName & " " & Surname, "Cities": **.City, "Emails": Email[type="home"].address}'
91+
% curl -s https://raw.githubusercontent.com/jsonata-js/jsonata/master/test/test-suite/datasets/dataset1.json | jsonata '{"Name": FirstName & " " & Surname, "Cities": **.City, "Emails": Email[type="home"].address}'
9292
{
9393
"Name": "Fred Smith",
9494
"Cities": [
@@ -101,7 +101,7 @@ helloworld.json
101101
]
102102
}
103103
104-
% python3 -m jsonata.cli -i helloworld.json -it
104+
% jsonata -i helloworld.json -it
105105
Enter an expression to have it evaluated.
106106
JSONata> (a & b)
107107
hello world

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
requires = ["hatchling"]
33
build-backend = "hatchling.build"
44

5+
[project.scripts]
6+
jsonata = "jsonata.cli.__main__:main"
57

68
[project]
79
name = "jsonata-python"

src/jsonata/cli/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
def get_options(argv: Optional[list[str]] = None) -> argparse.ArgumentParser:
3333
"""Parses command-line arguments.
3434
"""
35-
parser = argparse.ArgumentParser(prog="jsonata.cli", description="Pure Python JSONata CLI")
35+
parser = argparse.ArgumentParser(prog="jsonata", description="Pure Python JSONata CLI")
3636
parser.add_argument(
3737
"-v", "--version", action='version', version='%(prog)s 0.6.0')
3838

0 commit comments

Comments
 (0)