Include built-in lists in show, log errors from remove

kivy_mainline_and_py3.8
Tyler Goodlet 2018-04-10 14:13:00 -04:00
parent 381df2815d
commit 577ca43c02
1 changed files with 13 additions and 3 deletions

View File

@ -149,7 +149,7 @@ def watchlists(ctx, loglevel, config_dir):
@click.argument('name', nargs=1, required=False) @click.argument('name', nargs=1, required=False)
@click.pass_context @click.pass_context
def show(ctx, name): def show(ctx, name):
watchlist = ctx.obj['watchlist'] watchlist = wl.merge_watchlist(ctx.obj['watchlist'], wl._builtins)
click.echo(colorize_json( click.echo(colorize_json(
watchlist if name is None else watchlist[name])) watchlist if name is None else watchlist[name]))
@ -180,7 +180,17 @@ def add(ctx, name, ticker_name):
@click.argument('ticker_name', nargs=1, required=True) @click.argument('ticker_name', nargs=1, required=True)
@click.pass_context @click.pass_context
def remove(ctx, name, ticker_name): def remove(ctx, name, ticker_name):
try:
watchlist = wl.remove_ticker(name, ticker_name, ctx.obj['watchlist']) watchlist = wl.remove_ticker(name, ticker_name, ctx.obj['watchlist'])
except KeyError:
log.error(f"No watchlist with name `{name}` could be found?")
except ValueError:
if name in wl._builtins and ticker_name in wl._builtins[name]:
log.error(f"Can not remove ticker `{ticker_name}` from built-in "
f"list `{name}`")
else:
log.error(f"Ticker `{ticker_name}` not found in list `{name}`")
else:
wl.write_to_file(watchlist, ctx.obj['path']) wl.write_to_file(watchlist, ctx.obj['path'])