diff --git a/CHANGELOG.md b/CHANGELOG.md index 56dc27c..6bc0a23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)** diff --git a/toot/api.py b/toot/api.py index ab02edd..3e92c26 100644 --- a/toot/api.py +++ b/toot/api.py @@ -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() diff --git a/toot/commands.py b/toot/commands.py index a4d7d86..139ce8f 100644 --- a/toot/commands.py +++ b/toot/commands.py @@ -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: {}".format(response.get('url'))) diff --git a/toot/console.py b/toot/console.py index ab3b19a..ed4d31d 100644 --- a/toot/console.py +++ b/toot/console.py @@ -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,