cli: Write album to stdout, all else to stderr

To facilitate scripting, all status messages, etc. are now printed to the
standard error stream.  If the standard output stream is not a terminal,
the name of the album to be ripped is printed there, on the assumption that the
calling script is capturing it, e.g. in a variable.
pull/3/head
Dustin 2021-01-24 13:18:34 -06:00
parent b0540e494c
commit 9b63933eb9
1 changed files with 5 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import logging import logging
import os import os
from pathlib import Path from pathlib import Path
import sys
from typing import Any, Dict, Iterable, List, Optional from typing import Any, Dict, Iterable, List, Optional
import typer import typer
@ -94,7 +95,7 @@ def prompt_menu(console: Console, choices: Iterable[Any]) -> int:
console.print(f'[bright_yellow]{idx + 1})[/bright_yellow]: {choice}') console.print(f'[bright_yellow]{idx + 1})[/bright_yellow]: {choice}')
max_ += 1 max_ += 1
while 1: while 1:
choice = Prompt.ask('Selection') choice = Prompt.ask('Selection', console=console)
try: try:
i = int(choice) i = int(choice)
except ValueError: except ValueError:
@ -155,7 +156,7 @@ def run(
help='Increase log level (can be repated)', help='Increase log level (can be repated)',
), ),
): ):
console = Console(highlight=False) console = Console(highlight=False, stderr=True)
if verbose < 1: if verbose < 1:
level = logging.WARNING level = logging.WARNING
elif verbose < 2: elif verbose < 2:
@ -179,6 +180,8 @@ def run(
release = get_release_by_id(mbid) release = get_release_by_id(mbid)
else: else:
release = prompt_release(console, dev) release = prompt_release(console, dev)
if not sys.stdout.isatty():
print(f'{release.artist_credit_phrase} - {release.title}')
console.print(f'Ripping {format_release(release)}') console.print(f'Ripping {format_release(release)}')
num_discs = len(release.medium_list) num_discs = len(release.medium_list)