#!/bin/python
#
# Copyright (c) 2013-2014 Rafael Martinez Guerrero / PostgreSQL-es
# rafael@postgresql.org.es / http://www.postgresql.org.es/
#
# Copyright (c) 2014 USIT-University of Oslo
#
# This file is part of Pgbackman
# https://github.com/rafaelma/pgbackman
#
# PgBackMan 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.
#
# PgBackMan 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 Pgbackman.  If not, see <http://www.gnu.org/licenses/>.

import sys
import os

from pgbackman.cli import * 

if __name__ == '__main__':

    try:
        
        if len(sys.argv) > 1:
            if sys.argv[1] =='--use-csv-format':

                cli = pgbackman_cli()
                cli.output_format = 'csv'
                cli.db.output_format = 'csv'
                    
                cli.onecmd(' '.join(sys.argv[2:]))

            else:
                cli = pgbackman_cli()
                cli.onecmd(' '.join(sys.argv[1:]))

        elif len(sys.argv) == 1:
            os.system('clear')

            pgbackman_cli().check_pgbackman_database_version()
            pgbackman_cli().cmdloop()
        else:
            raise NotImplementedError
        
    except KeyboardInterrupt:
        print
        print "\nDone, thank you for using PgBackMan"

        sys.exit(0)
