import click
import pathlib
import toleo
import xdg.BaseDirectory
from .table import create_table


@click.command()
@click.option('--collection', '-c', 'collection_name', default='default')
def cli(collection_name):
    ''' Entry point for application. '''
    xdg_config_home = pathlib.Path(xdg.BaseDirectory.xdg_config_home)
    config_dir = xdg_config_home / 'toleo'
    config = (config_dir / collection_name).with_suffix('.yaml')
    try:
        collection = toleo.Collection(config)
    except OSError as err:
        msg = 'no config for collection "{}" ({})'
        raise click.ClickException(msg.format(config.stem, err.filename))
    except AttributeError as err:
        raise click.ClickException(err)
    else:
        results = toleo.process(collection)
        table = create_table(results)
        print(table)

@@ -124,16 +124,22 @@
 .option(
+'-c', 
 '--colle
@@ -149,14 +149,8 @@
 on',
- '-c',
  'co
@@ -184,16 +184,61 @@
 fault')%0A
+@click.option('-v', '--verbose', count=True)%0A
 def cli(
@@ -252,16 +252,25 @@
 ion_name
+, verbose
 ):%0A    '
@@ -546,188 +546,108 @@
     
-except OSError as err:%0A        msg = 'no config for collection %22%7B%7D%22 (%7B%7D)'%0A        raise click.ClickException(msg.format(config.stem, err.filename))%0A    except AttributeError as err
+    results = toleo.process(collection)%0A    except toleo.ToleoException as e:%0A        if verbose %3E 0
 :%0A  
@@ -656,44 +656,28 @@
     
+    
 raise 
-click.ClickException(err)%0A
+e%0A  
     
+  
 else
@@ -690,48 +690,21 @@
     
-results = toleo.process(collection)%0A    
+    e.quit()%0A
     
@@ -733,20 +733,16 @@
 esults)%0A
-    
     prin

add verbose flag and better exception handling