Load the twtxt config at CLI init
This commit is contained in:
parent
d0173641ef
commit
6b4ce6106f
|
@ -13,11 +13,16 @@ import click
|
||||||
@click.option('-k', '--insecure', is_flag=True)
|
@click.option('-k', '--insecure', is_flag=True)
|
||||||
@click.option('-f', '--format',
|
@click.option('-f', '--format',
|
||||||
type=click.Choice(output.registry.keys()),
|
type=click.Choice(output.registry.keys()),
|
||||||
default='raw')
|
default='pretty')
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def cli(ctx, registry_url, insecure, format):
|
def cli(ctx, registry_url, insecure, format):
|
||||||
ctx.obj = Namespace()
|
ctx.obj = Namespace()
|
||||||
|
|
||||||
|
try:
|
||||||
|
ctx.obj.conf = Config.discover()
|
||||||
|
except ValueError:
|
||||||
|
ctx.obj.conf = Namespace()
|
||||||
|
|
||||||
scheme, netloc, path, query, fragment = urlsplit(registry_url)
|
scheme, netloc, path, query, fragment = urlsplit(registry_url)
|
||||||
if not scheme:
|
if not scheme:
|
||||||
scheme = 'https'
|
scheme = 'https'
|
||||||
|
@ -64,9 +69,9 @@ def register(ctx, nickname, url):
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def users(ctx, query):
|
def users(ctx, query):
|
||||||
try:
|
try:
|
||||||
click.echo(ctx.obj.formatter.format_users(
|
click.echo(ctx.obj.formatter.format_users(
|
||||||
ctx.obj.client.list_users(q=query)
|
ctx.obj.client.list_users(q=query)
|
||||||
))
|
))
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
click.echo(ctx.obj.formatter.format_response(e.response))
|
click.echo(ctx.obj.formatter.format_response(e.response))
|
||||||
|
|
||||||
|
@ -76,9 +81,9 @@ def users(ctx, query):
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def tweets(ctx, query):
|
def tweets(ctx, query):
|
||||||
try:
|
try:
|
||||||
click.echo(ctx.obj.formatter.format_tweets(
|
click.echo(ctx.obj.formatter.format_tweets(
|
||||||
ctx.obj.client.list_tweets(q=query)
|
ctx.obj.client.list_tweets(q=query)
|
||||||
))
|
))
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
click.echo(ctx.obj.formatter.format_response(e.response))
|
click.echo(ctx.obj.formatter.format_response(e.response))
|
||||||
|
|
||||||
|
@ -111,9 +116,9 @@ def mentions(ctx, name_or_url):
|
||||||
url = config.twturl
|
url = config.twturl
|
||||||
|
|
||||||
try:
|
try:
|
||||||
click.echo(ctx.obj.formatter.format_tweets(
|
click.echo(ctx.obj.formatter.format_tweets(
|
||||||
ctx.obj.client.list_mentions(url)
|
ctx.obj.client.list_mentions(url)
|
||||||
))
|
))
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
click.echo(ctx.obj.formatter.format_response(e.response))
|
click.echo(ctx.obj.formatter.format_response(e.response))
|
||||||
|
|
||||||
|
@ -123,9 +128,9 @@ def mentions(ctx, name_or_url):
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def tag(ctx, name):
|
def tag(ctx, name):
|
||||||
try:
|
try:
|
||||||
click.echo(ctx.obj.formatter.format_tweets(
|
click.echo(ctx.obj.formatter.format_tweets(
|
||||||
ctx.obj.client.list_tag_tweets(name)
|
ctx.obj.client.list_tag_tweets(name)
|
||||||
))
|
))
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
click.echo(ctx.obj.formatter.format_response(e.response))
|
click.echo(ctx.obj.formatter.format_response(e.response))
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import urllib
|
import urllib
|
||||||
|
import click
|
||||||
import requests
|
import requests
|
||||||
from twtxt.config import Config
|
|
||||||
|
|
||||||
|
|
||||||
class RegistryClient(object):
|
class RegistryClient(object):
|
||||||
|
@ -12,12 +12,8 @@ class RegistryClient(object):
|
||||||
|
|
||||||
from twtxt_registry_client import __version__
|
from twtxt_registry_client import __version__
|
||||||
if disclose_identity or disclose_identity is None:
|
if disclose_identity or disclose_identity is None:
|
||||||
try:
|
config = click.get_current_context().obj.conf
|
||||||
config = Config.discover()
|
disclose_identity = config.get('disclose_identity', False)
|
||||||
except ValueError:
|
|
||||||
disclose_identity = False
|
|
||||||
else:
|
|
||||||
disclose_identity = config.disclose_identity
|
|
||||||
|
|
||||||
if disclose_identity:
|
if disclose_identity:
|
||||||
user_agent = 'twtxt-registry/{} (+{}; @{})'.format(
|
user_agent = 'twtxt-registry/{} (+{}; @{})'.format(
|
||||||
|
|
Reference in New Issue