#!/bin/bash
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
source "$(dirname "$0")/lib/ulib/ulib" || exit 1
urequire DEFAULTS password

function display_help() {
    uecho "$scriptname: générer un mot de passe au hasard

USAGE
    $scriptname [options]

OPTIONS
    -l, --len LEN
        Spécifier le nombre de caractères du mot de passe généré
    -U, --upper COUNT
    -L, --lower COUNT
    -A, --alpha COUNT
    -N, --number COUNT
    -S, --symbol COUNT
    -B, --special COUNT
        Spécifier le nombre minimum de chaque classe de caractère"
}

len=
upper=
lower=
alpha=
number=
symbol=
special=
parse_opts "${PRETTYOPTS[@]}" \
    --help '$exit_with display_help' \
    -l:,--len: len= \
    -U:,--upper: upper= \
    -L:,--lower: lower= \
    -A:,--alpha: alpha= \
    -N:,--number: number= \
    -S:,--symbol: symbol= \
    -B:,--special: special= \
    @ args -- "$@" && set -- "${args[@]}" || die "$args"

[ -n "$len" ] || len="$GENPASS_LEN"
[ -n "$upper" ] || upper="${GENPASS_COUNTS[0]}"
[ -n "$lower" ] || lower="${GENPASS_COUNTS[1]}"
[ -n "$alpha" ] || alpha="${GENPASS_COUNTS[2]}"
[ -n "$number" ] || number="${GENPASS_COUNTS[3]}"
[ -n "$symbol" ] || symbol="${GENPASS_COUNTS[4]}"
[ -n "$special" ] || special="${GENPASS_COUNTS[5]}"

GENPASS_LEN="$len"
GENPASS_COUNTS=("$upper" "$lower" "$alpha" "$number" "$symbol" "$special")
genpass