#!/bin/bash
#
# lib/msg
#
# Copyright (c) 2011-2013 LibreVPN <vpn@hackcoop.com.ar>
#
# See AUTHORS for a list of contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General
# Public License along with this program.  If not, see
# <http://www.gnu.org/licenses/>.
#
#

# Hace falta tener gettext instalado
requires gettext

# La base para todos los mensajes, se imprime en stderr
_msg() {
    msg=$1; shift
    printf "> $msg\n" "$@" 1>&2
}

msg() {
    msg="$(gettext "$1")"; shift
    _msg "$msg" "$@"
}

error() {
    msg="$(gettext "$1")"; shift
    _msg "$(gettext "ERROR:") ${msg}" "$@"
}

warning() {
    msg="$(gettext "$1")"; shift
    _msg "$(gettext "ALERTA:") ${msg}" "$@"
}

# Mensaje de error y salir
fatal_error() {
    error "$@"
    exit 1
}

# Sugerir algo
tip() {
  msg="$(gettext "$1")"; shift
  _msg "$(gettext "Tip:") ${msg}" "$@"
}

# Muestra el manual
# $1 el comando para obtener la ayuda
help() {
    man $1 || man ${LVPN_DIR}/doc/es/$1.1
}
