Exemple #1
0
def unfollow(app, user, args):
    account = _find_account(app, user, args.account)

    if not account:
        print_error("Account not found")
        return

    api.unfollow(app, user, account['id'])

    print(green("✓ You are no longer following %s" % args.account))
Exemple #2
0
def main():
    if os.getenv('TOOT_DEBUG'):
        logging.basicConfig(level=logging.DEBUG)

    # If something is piped in, append it to commandline arguments
    if not sys.stdin.isatty():
        sys.argv.append(sys.stdin.read())

    command_name = sys.argv[1] if len(sys.argv) > 1 else None
    args = sys.argv[2:]

    if not command_name:
        return print_usage()

    user = config.load_user()
    app = config.load_app(user.instance) if user else None

    try:
        run_command(app, user, command_name, args)
    except ConsoleError as e:
        print_error(str(e))
    except api.ApiError as e:
        print_error(str(e))
Exemple #3
0
def run_command(app, user, name, args):
    command = next((c for c in COMMANDS if c.name == name), None)

    if not command:
        print_error("Unknown command '{}'\n".format(name))
        print_usage()
        return

    parser = get_argument_parser(name, command)
    parsed_args = parser.parse_args(args)

    if command.require_auth and (not user or not app):
        print_error("This command requires that you are logged in.")
        print_error("Please run `toot login` first.")
        return

    fn = commands.__dict__.get(name)

    if not fn:
        raise NotImplementedError(
            "Command '{}' does not have an implementation.".format(name))

    return fn(app, user, parsed_args)