mirror of
https://github.com/ihabunek/toot.git
synced 2024-09-29 04:35:54 -04:00
Output of config and settings files is now optional (toot diag -f)
This commit is contained in:
parent
df98705627
commit
b088ce9585
@ -1,3 +1,4 @@
|
|||||||
|
import click
|
||||||
from toot.output import print_diags
|
from toot.output import print_diags
|
||||||
from toot.cli import (
|
from toot.cli import (
|
||||||
cli,
|
cli,
|
||||||
@ -7,8 +8,14 @@ from toot.cli import (
|
|||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
|
@click.option(
|
||||||
|
"-f",
|
||||||
|
"--files",
|
||||||
|
is_flag=True,
|
||||||
|
help="Print contents of the config and settings files in diagnostic output",
|
||||||
|
)
|
||||||
@pass_context
|
@pass_context
|
||||||
def diag(ctx: Context):
|
def diag(ctx: Context, files: bool):
|
||||||
"""Display useful information for diagnosing problems"""
|
"""Display useful information for diagnosing problems"""
|
||||||
|
|
||||||
print_diags()
|
print_diags(files)
|
||||||
|
@ -314,7 +314,7 @@ def format_account_name(account: Account) -> str:
|
|||||||
return acct
|
return acct
|
||||||
|
|
||||||
|
|
||||||
def print_diags():
|
def print_diags(include_files: bool):
|
||||||
from importlib.metadata import version
|
from importlib.metadata import version
|
||||||
|
|
||||||
click.echo(f'{green(f"Diagnostic Information")}')
|
click.echo(f'{green(f"Diagnostic Information")}')
|
||||||
@ -326,30 +326,6 @@ def print_diags():
|
|||||||
from toot import __version__, config, settings
|
from toot import __version__, config, settings
|
||||||
click.echo(f'{green(f"Toot version:")} {__version__}')
|
click.echo(f'{green(f"Toot version:")} {__version__}')
|
||||||
|
|
||||||
click.echo(f'{green(f"Settings path:")} {settings.get_settings_path()}')
|
|
||||||
click.echo(f'{green(f"Settings file contents:")}')
|
|
||||||
try:
|
|
||||||
with open(settings.get_settings_path(), 'r') as f:
|
|
||||||
print(f.read())
|
|
||||||
except: # noqa
|
|
||||||
click.echo(f'{yellow(f"Could not open settings file")}')
|
|
||||||
|
|
||||||
click.echo('')
|
|
||||||
|
|
||||||
click.echo(f'{green(f"Config path:")} {config.get_config_file_path()}')
|
|
||||||
click.echo(f'{green(f"Config file contents:")}')
|
|
||||||
try:
|
|
||||||
with open(config.get_config_file_path(), 'r') as f:
|
|
||||||
for line in f:
|
|
||||||
if "client_" not in line and "token" not in line:
|
|
||||||
click.echo(line, nl=False)
|
|
||||||
else:
|
|
||||||
click.echo(f'{yellow("***LINE REDACTED***")}')
|
|
||||||
except: # noqa
|
|
||||||
click.echo(f'{yellow(f"Could not open config file")}')
|
|
||||||
|
|
||||||
click.echo('')
|
|
||||||
|
|
||||||
import platform
|
import platform
|
||||||
click.echo(f'{green(f"Platform:")} {platform.platform()}')
|
click.echo(f'{green(f"Platform:")} {platform.platform()}')
|
||||||
|
|
||||||
@ -375,6 +351,34 @@ def print_diags():
|
|||||||
|
|
||||||
click.echo(f"\t{dep}: {ver}")
|
click.echo(f"\t{dep}: {ver}")
|
||||||
|
|
||||||
|
click.echo(f'{green(f"Settings file path:")} {settings.get_settings_path()}')
|
||||||
|
click.echo(f'{green(f"Config file path:")} {config.get_config_file_path()}')
|
||||||
|
|
||||||
|
if include_files:
|
||||||
|
click.echo(f'{green(f"Settings file contents:")}')
|
||||||
|
try:
|
||||||
|
with open(settings.get_settings_path(), 'r') as f:
|
||||||
|
print(f.read())
|
||||||
|
except: # noqa
|
||||||
|
click.echo(f'{yellow(f"Could not open settings file")}')
|
||||||
|
|
||||||
|
click.echo('')
|
||||||
|
|
||||||
|
click.echo(f'{green(f"Config file contents:")}')
|
||||||
|
try:
|
||||||
|
with open(config.get_config_file_path(), 'r') as f:
|
||||||
|
for line in f:
|
||||||
|
# Do not output client secret or access token lines
|
||||||
|
if "client_" in line or "token" in line:
|
||||||
|
click.echo(f'{yellow("***CONTENTS REDACTED***")}')
|
||||||
|
else:
|
||||||
|
click.echo(line, nl=False)
|
||||||
|
|
||||||
|
except: # noqa
|
||||||
|
click.echo(f'{yellow(f"Could not open config file")}')
|
||||||
|
|
||||||
|
click.echo('')
|
||||||
|
|
||||||
|
|
||||||
# Shorthand functions for coloring output
|
# Shorthand functions for coloring output
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user