Reinstate toot post --using option

This commit is contained in:
Ivan Habunek 2023-12-28 19:09:48 +01:00
parent 2e2945822a
commit 11aaa1dc29
No known key found for this signature in database
GPG Key ID: F5F0623FF5EBCB3D
1 changed files with 18 additions and 5 deletions

View File

@ -6,8 +6,8 @@ from datetime import datetime, timedelta, timezone
from time import sleep, time
from typing import BinaryIO, Optional, Tuple
from toot import api
from toot.cli import cli, json_option, pass_context, Context
from toot import api, config
from toot.cli import AccountParamType, cli, json_option, pass_context, Context
from toot.cli import DURATION_EXAMPLES, VISIBILITY_CHOICES
from toot.cli.validators import validate_duration, validate_language
from toot.entities import MediaAttachment, from_dict
@ -106,6 +106,11 @@ from toot.utils.datetime import parse_datetime
is_flag=True,
default=False,
)
@click.option(
"-u", "--using",
type=AccountParamType(),
help="The account to use, overrides the active account.",
)
@json_option
@pass_context
def post(
@ -127,12 +132,20 @@ def post(
poll_expires_in: int,
poll_multiple: bool,
poll_hide_totals: bool,
json: bool
json: bool,
using: str
):
"""Post a new status"""
if len(media) > 4:
raise click.ClickException("Cannot attach more than 4 files.")
if using:
user, app = config.get_user_app(using)
if not user or not app:
raise click.ClickException(f"Account '{using}' not found. Run `toot auth` to see available accounts.")
else:
user, app = ctx.user, ctx.app
media_ids = _upload_media(ctx.app, ctx.user, media, descriptions, thumbnails)
status_text = _get_status_text(text, editor, media)
scheduled_at = _get_scheduled_at(scheduled_at, scheduled_in)
@ -141,8 +154,8 @@ def post(
raise click.ClickException("You must specify either text or media to post.")
response = api.post_status(
ctx.app,
ctx.user,
app,
user,
status_text,
visibility=visibility,
media_ids=media_ids,