#!/usr/bin/env python 
#!/usr/bin/env python
##
##
##          Airget: the open source package installer: pip edition
##
##          
##
##          Copyright 2015 Aaron Gill-Braun
##              www.github.com/airget

import os
import click
import wget
import getpass
import subprocess
import sys

user = getpass.getuser()

packages = {'atom': 'atom.py','homebrew': 'homebrew.py', 'vim': 'vim.py', 'git': 'git.py'}

pkglist = """


- atom: An open source text editor.
- vim: A Terminal text editor.
- homebrew: a package manager for Mac OSX.
- git: The git tools.




"""
versionnum = '''

Airget version: 0.1

'''






@click.command()

@click.option('-g',default='', help='Gets specified package: -g <package>')
@click.option('-l', flag_value="list", default=False, help='Lists all packages.')
@click.option('--dust', flag_value="dust", default=False, help='Cleans out the download cache.')
@click.option('--version', flag_value="version", default=False, help='Displays the current version of airget.')


def cli(g, l, version, dust):
    """
+------------------------------------------------------+                         
|                                                      |                        
|                                                      |                                                 
|                 ___   _              __              |                       
|                / _ | (_)______ ____ / /_             |                       
|               / __ |/ / __/ _ `/ -_) __/             |                       
|              /_/ |_/_/_/  \_, /\__/\__/              |                       
|                          /___/                       |                      
|                                                      |                       
|                                                      |                                                                                                                                                                         
+------------------------------------------------------+\n



           The open source package installer



"""
   
    if g:
        if g in packages:
            os.chdir('/Library/Caches')
            os.system('mkdir Airget')
            os.chdir('/Library/Caches/Airget')
            pkg = 'https://raw.githubusercontent.com/Airget/airget-packages/master/'+packages[g]
            wget.download(pkg)
            execfile('/Library/Caches/Airget/'+packages[g])
        
        
        else:
            print "'", g, "'", " is not recognized as a package."

    if version:
        print versionnum
        sys.exit()
    if l:
        print pkglist
        sys.exit()

    if dust:
        os.system('python /Library/Caches/Airget/tools/clean.py')
        sys.exit()
    
   
    if not l or version or g or dust:
        os.system('airget --help')
        

if __name__ == '__main__':
                cli()
 

