Skip to content

Commit 07e6eef

Browse files
authored
Add piping from stdin (#7)
1 parent 6c3e92d commit 07e6eef

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,25 @@ sudo snap install xjs
1717

1818
## ⌨️ Usage
1919

20-
With yaml:
20+
Read from a file (yaml or json):
2121

2222
```bash
2323
juju status --format yaml > juju-status.yaml
2424
xjs juju-status.yaml
2525
```
2626

27-
With json:
28-
2927
```bash
3028
juju status --format json > juju-status.json
3129
xjs juju-status.json
3230
```
3331

32+
Pipe stdin directly:
33+
34+
```bash
35+
juju status --format yaml | xjs --unwanted
36+
juju status --format json | xjs --show-units
37+
```
38+
3439
Options:
3540

3641
```bash

xjs/cli.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,8 @@ def filter_results(
612612
help="Show only units with unwanted workload or agent status",
613613
)
614614
@click.argument(
615-
"statusfiles", required=True, type=click.File("r"),
616-
nargs=-1, metavar="<status files>",
615+
"statusfiles", required=False, type=click.File("r"),
616+
nargs=-1, metavar="[status files]",
617617
)
618618
def main(
619619
statusfiles: tuple[TextIO, ...],
@@ -637,6 +637,16 @@ def main(
637637
agent_status: str,
638638
unwanted: bool,
639639
) -> None:
640+
if not statusfiles:
641+
if sys.stdin.isatty():
642+
console = Console()
643+
console.print(
644+
"[red]Error: no status files provided"
645+
" and no data piped to stdin[/red]",
646+
)
647+
sys.exit(1)
648+
statusfiles = (sys.stdin,)
649+
640650
color = not no_color
641651
controllers: dict[str, Controller] = {}
642652
for statusfile in statusfiles:

0 commit comments

Comments
 (0)