Skip to content

Commit 38b087e

Browse files
committed
Fix interactive mode
1 parent 94eb5e5 commit 38b087e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ options:
6161
-f {auto,json,string}, --format {auto,json,string}
6262
Input format (default=auto)
6363
-o <arg>, --output <arg>
64-
JSON output file (- for stdin)
64+
JSON output file (default=stdout)
6565
-oc <arg>, --ocharset <arg>
6666
Output character set (default=utf-8)
6767
-time Print performance timers to stderr
@@ -70,7 +70,7 @@ options:
7070
JSONata variable bindings
7171
-bf <file>, --bindings-file <file>
7272
JSONata variable bindings file
73-
-it, --interactive Interactive REPL
73+
-it, --interactive Interactive REPL (requires input file)
7474
```
7575

7676
### Examples
@@ -100,6 +100,11 @@ helloworld.json
100100
101101
]
102102
}
103+
104+
% python3 -m jsonata.cli -i helloworld.json -it
105+
Enter an expression to have it evaluated.
106+
JSONata> (a & b)
107+
hello world
103108
```
104109

105110
## Running Tests

src/jsonata/cli/__main__.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def get_options(argv: Optional[list[str]] = None) -> argparse.ArgumentParser:
5454
)
5555
parser.add_argument(
5656
"-o", "--output", metavar="<arg>",
57-
help="JSON output file (- for stdin)"
57+
help="JSON output file (default=stdout)"
5858
)
5959
parser.add_argument(
6060
"-oc", "--ocharset", default="utf-8", metavar="<arg>",
@@ -78,7 +78,7 @@ def get_options(argv: Optional[list[str]] = None) -> argparse.ArgumentParser:
7878
)
7979
parser.add_argument(
8080
"-it", "--interactive", default=False, action="store_true",
81-
help="Interactive REPL"
81+
help="Interactive REPL (requires input file)"
8282
)
8383

8484
# The expression
@@ -160,8 +160,9 @@ def main(argv: Optional[list[str]] = None) -> int:
160160
options = parser.parse_args(argv)
161161

162162
if options.expression is None and options.expr is None:
163-
parser.print_help()
164-
return 1
163+
if not options.interactive:
164+
parser.print_help()
165+
return 1
165166

166167
icharset = options.icharset
167168
ocharset = options.icharset
@@ -187,6 +188,9 @@ def main(argv: Optional[list[str]] = None) -> int:
187188
bindings = json.loads(bindings_str)
188189

189190
if options.input == '-' or options.input is None:
191+
if options.interactive:
192+
parser.print_help()
193+
return 1
190194
input = sys.stdin.read()
191195
else:
192196
with open(options.input, 'r', encoding=icharset) as fd:

0 commit comments

Comments
 (0)