1
0
mirror of https://github.com/ihabunek/toot.git synced 2024-12-04 14:46:33 -05:00

Add --language option to post command

Used to override language detection.
This commit is contained in:
Ivan Habunek 2019-07-30 16:13:29 +02:00
parent e5bba7e9b3
commit a7e4f9d888
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95
4 changed files with 23 additions and 4 deletions

View File

@ -5,6 +5,7 @@ Changelog
* Add `toot notifications` to show notifications (thanks @dlax)
* Add posting and replying to curses interface (thanks @Skehmatics)
* Add `--language` option to `toot post`
**0.21.0 (2019-02-15)**

View File

@ -92,7 +92,8 @@ def post_status(
media_ids=None,
sensitive=False,
spoiler_text=None,
in_reply_to_id=None
in_reply_to_id=None,
language=None,
):
"""
Posts a new status.
@ -110,6 +111,7 @@ def post_status(
'sensitive': str_bool(sensitive),
'spoiler_text': spoiler_text,
'in_reply_to_id': in_reply_to_id,
'language': language,
}, headers=headers).json()

View File

@ -100,6 +100,7 @@ def post(app, user, args):
sensitive=args.sensitive,
spoiler_text=args.spoiler_text,
in_reply_to_id=args.reply_to,
language=args.language,
)
print_out("Toot posted: <green>{}</green>".format(response.get('url')))

View File

@ -13,8 +13,19 @@ from toot.output import print_out, print_err
VISIBILITY_CHOICES = ['public', 'unlisted', 'private', 'direct']
def language(value):
"""Validates the language parameter"""
if len(value) != 3:
raise ArgumentTypeError(
"Invalid language specified: '{}'. Expected a 3 letter "
"abbreviation according to ISO 639-2 standard.".format(value)
)
return value
def visibility(value):
"""Validates the visibilty parameter"""
"""Validates the visibility parameter"""
if value not in VISIBILITY_CHOICES:
raise ValueError("Invalid visibility value")
@ -275,11 +286,15 @@ POST_COMMANDS = [
}),
(["-p", "--spoiler-text"], {
"type": str,
"help": 'text to be shown as a warning before the actual content',
"help": "text to be shown as a warning before the actual content",
}),
(["-r", "--reply-to"], {
"type": int,
"help": 'local ID of the status you want to reply to',
"help": "local ID of the status you want to reply to",
}),
(["-l", "--language"], {
"type": language,
"help": "ISO 639-2 language code of the toot, to skip automatic detection",
}),
],
require_auth=True,