import argparse
from formats import gob
from util import bulkrw


args = None


def archive_gob():
    print('Archiving "' + args.directory + '" into GOB "' + args.gob + '"')

    entries = bulkrw.read_files(args.directory, args.recursive)
    gob.write(args.gob, entries)

    print('Done')


def extract_gob():
    print('Extracting "' + args.gob + '" into directory "' + args.directory + '"')

    entries = gob.read(args.gob)
    bad_entries = bulkrw.write_files(args.directory, entries, args.organize)

    if args.interactive and bad_entries:
        print('Some files could not be saved. Please provide a name for each file when prompted.')
        bulkrw.write_files_interactive(args.directory, bad_entries)
    elif bad_entries:
        print('Some files could not be saved. Use the "-i" or "--interactive" option to extract these files.')

    print('Done')


if __name__ == '__main__':
    parser = argparse.ArgumentParser(prog='gobtool',
                                     description='Tool for Star Wars: Dark Forces GOB archives.')

    parser.add_argument('-r', '--recursive',
                        help='archive all files in the directory and its subdirectories (archive mode only)',
                        action='store_true')
    parser.add_argument('-o', '--organize',
                        help='create a subdirectory for each file extension in the archive (extract mode only)',
                        action='store_true')
    parser.add_argument('-i', '--interactive',
                        help='manual renaming when extracting files with bad filenames',
                        action='store_true')

    parser.add_argument('mode', choices=['archive', 'extract'],
                        help='mode of operation')
    parser.add_argument('gob', help='GOB to extract from / archive to')
    parser.add_argument('directory', help='directory to extract to / archive from')

    args = parser.parse_args()

    if args.mode == 'archive':
        archive_gob()
    elif args.mode == 'extract':
        extract_gob()

import argparse
from formats import gob
from util import bulkrw


args = None


def archive_gob():
    print('Archiving "' + args.directory + '" into GOB "' + args.gob + '"')

    entries = bulkrw.read_files(args.directory, args.recursive)
    gob.write(args.gob, entries)

    print('Done')


def extract_gob():
    print('Extracting "' + args.gob + '" into directory "' + args.directory + '"')

    entries = gob.read(args.gob)
    bad_entries = bulkrw.write_files(args.directory, entries, args.organize)

    if args.interactive and bad_entries:
        print('Some files could not be saved. Please provide a name for each file when prompted.')
        bulkrw.write_files_interactive(args.directory, bad_entries)
    elif bad_entries:
        print('Some files could not be saved. Use the "-i" or "--interactive" option to extract these files.')

    print('Done')


def main():
    parser = argparse.ArgumentParser(prog='gobtool', description='Tool for Star Wars: Dark Forces GOB archives.')
    subparsers = parser.add_subparsers(dest='cmd', required=True, help='the operation to perform')


    # Extract command subparser.
    extract_parser = subparsers.add_parser('extract', help='extract from a GOB')
    extract_parser.add_argument('-o', '--organize', help='create a subdirectory for each file extension in the archive', action='store_true')
    extract_parser.add_argument('-i', '--interactive', help='manual renaming when extracting files with bad filenames', action='store_true')
    extract_parser.add_argument('gob', help='GOB to extract from')
    extract_parser.add_argument('directory', help='directory to extract into')


    # Archive command subparser.
    archive_parser = subparsers.add_parser('archive', help='archive into a GOB')
    archive_parser.add_argument('-r', '--recursive', help='archive all files in the directory and its subdirectories', action='store_true')
    archive_parser.add_argument('directory', help='directory to archive from')
    archive_parser.add_argument('gob', help='GOB to archive into')


    args = parser.parse_args()


    if args.cmd == 'archive':
        archive_gob()
    elif args.cmd == 'extract':
        extract_gob()


if __name__ == '__main__':
    main()

Add subparsers to gobtool.