#!/usr/bin/env python
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import argparse
from os import path
import insult

parser = argparse.ArgumentParser(
    description="Command-line insult utility"
)

parser.add_argument(
    "--language", "-l",
    default="en",
    help="Language data to load"
)

parser.add_argument(
    "--words-dir", "-w",
    default=path.join(path.dirname(path.dirname(path.realpath(__file__))),
                      "share", "libinsult", "word_lists"),
    help="Base path for word lists data",
)

template_suffix = (
    "as <adjective> as <article target=adj1> "
    "<adjective min=1 max=3 id=adj1> <amount> of "
    "<adjective min=1 max=3> <animal> <animal_part>"
)

parser.add_argument(
    "template",
    nargs="*",
    default="You are " + template_suffix,
    help="Insult template",
)

parser.add_argument(
    "--who",
    default=None,
    help="Turns the default template into the third person",
)

args = parser.parse_args()


## \todo Different languages, plurals etc
if args.who:
    args.template = "%s is %s" % (args.who, template_suffix)

insulter = insult.Insulter()
insulter.load_directory(path.join(args.words_dir, args.language))
print(insulter.format(" ".join(args.template)))
