Skip to content

Commit

Permalink
feat: output status in JSON (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
YDX-2147483647 authored Apr 4, 2023
1 parent 06e51bd commit 200b6a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Usage: bitsrun status [OPTIONS]
Check current network login status.
Options:
--json / --no-json Output in JSON format.
--help Show this message and exit.
```

Expand Down
11 changes: 9 additions & 2 deletions bitsrun/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from getpass import getpass
from json import dumps

import click
from rich import print_json
Expand Down Expand Up @@ -41,17 +42,23 @@ def config_paths():


@cli.command()
def status():
@click.option("--json/--no-json", default=False, help="Output in JSON format.")
def status(json: bool):
"""Check current network login status."""
login_status = get_login_status()

# Output in JSON format if `--json` is passed, then exit
if json:
print(dumps(login_status))
return

# Output in human-readable format
if login_status.get("user_name"):
click.echo(
click.style("bitsrun: ", fg="green")
+ f"{login_status['user_name']} ({login_status['online_ip']}) is online"
)
print_status_table(login_status)

else:
click.echo(
click.style("bitsrun: ", fg="cyan")
Expand Down

0 comments on commit 200b6a3

Please sign in to comment.