#!/bin/bash
#
# Copyright (C) 2025 Pavel Khromov <hromovpi@altlinux.org>
#
# This file 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, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#

set -o pipefail

. shell-args
. shell-error
. shell-getopt

show_help() {
cat <<-EOF
Usage: $PROG <command>

Commands:
  info                    get all categories info

Options:
  -h, --help              show this text and exit.

Report bugs to http://bugzilla.altlinux.org/

EOF
    exit
}

get-info() {
    local result_path="$(mktemp)"
    for file in /usr/share/alterator/components/categories/*; do
        cat "$file"
        echo -en '\0'
    done >> $result_path
    cat $result_path
    rm $result_path
}

TEMP=$(getopt -n $PROG -o $getopt_common_opts -l $getopt_common_longopts -- "$@") ||
        show_usage
eval set -- "$TEMP"

while :; do
        case "$1" in
        --)
                shift
                break
                ;;
        *)
                parse_common_option "$1"
                ;;
        esac
        shift
done

[ "$#" -gt 0 ] ||
        show_usage

case "$1" in
info)
        get-info
        ;;
*)
        show_help
        ;;
esac
