#!/usr/bin/env python

# Copyright 2024 Banana and contributors of https://github.com/portagefilelist
# 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 2 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 Street, Fifth Floor, Boston, MA 02110-1301 USA.

# standard library
import sys
import argparse

# pfl module
import pfl.e_file

VERSION='3.5.3'

parser = argparse.ArgumentParser(description='This script searches on \
https://www.portagefilelist.de for the given filename(slice.hpp) or \
path(/usr/include/exiv2/slice.hpp) and displays the result \
with further information from local portage. \
Using * as a wildcard (slice.*) (/usr/include/exiv2/*) works too.', add_help=False, allow_abbrev=False)

parser.add_argument('-h', '--help', action='help', help='Show this help message and exit.')
parser.add_argument('-v', '--version', action='version', version='e-file ' + VERSION)
parser.add_argument('--plain', action='store_true', default=False, help='Output in plain text.')
parser.add_argument('file', help='Filename or path to search for.')
args = parser.parse_args()

# options needed to run()
options = {
    'file': args.file,
    'outputPlain': args.plain
}

def main():
    options['stdout'] = True
    ret, out = pfl.e_file.run(options)
    sys.stdout.write(out)
    return ret

# run if not imported
if __name__ == '__main__':
    sys.exit(main())
