Repository: weecology/retriever

Issue:
Catch errors when `install` and `download` are run w/o arguments
Running `install` and `download` without the name of a dataset triggers a messy Python error. We should report the associated usage help instead.

```
ethan@gandalf:~$ retriever install
Traceback (most recent call last):
  File "/home/ethan/miniconda3/bin/retriever", line 11, in <module>
    load_entry_point('retriever==2.0.dev0', 'console_scripts', 'retriever')()
  File "/home/ethan/miniconda3/lib/python3.5/site-packages/retriever/__main__.py", line 159, in main
    engine = choose_engine(args.__dict__)
  File "/home/ethan/miniconda3/lib/python3.5/site-packages/retriever/lib/tools.py", line 124, in choose_engine
    enginename = enginename.lower()
AttributeError: 'NoneType' object has no attribute 'lower'
```


Discussion:
@ethanwhite could you try to run that command `retriever install` if error,
followed by `retriever update`
I think that the issue has been resolved.
@Parth-25m did you try to run `retriever install`?
And what os are you using?

yes

`retriever git:(master) retriever install

usage: retriever install [-h] [--compile] [--debug]
                     {mysql,postgres,sqlite,msaccess,csv,json,xml} ...

retriever install: error: too few arguments

➜  retriever git:(master) ✗ retriever download

Exception: no dataset specified.
`
Looks like this might be a Python version number difference. On Ubuntu using Python 2 I get the correct behavior, but using Python 3 I get the error reported above. Can anyone else confirm that this is the source of the different behaviors?
I am on Ubuntu, running Python 3 with the most current version of retriever. I am also getting the error above, mentioned by Ethan. 
This could be a permission issue, could you give me the sequence of  command you are running including the command you are using to install
```
pip install . --upgrade
retriever install
```

@henrykironde - are you not seeing this on Python 3?

Resolving patch:
diff --git a/__init__.py b/__init__.py
--- a/__init__.py
+++ b/__init__.py
@@ -210,3 +210,19 @@ def set_proxy():
     }
 }
 """
+CITATION = """Morris, B.D. and E.P. White. 2013. The EcoData Retriever: improving access to
+existing ecological data. PLOS ONE 8:e65848.
+http://doi.org/doi:10.1371/journal.pone.0065848
+
+@article{morris2013ecodata,
+  title={The EcoData Retriever: Improving Access to Existing Ecological Data},
+  author={Morris, Benjamin D and White, Ethan P},
+  journal={PLOS One},
+  volume={8},
+  number={6},
+  pages={e65848},
+  year={2013},
+  publisher={Public Library of Science}
+  doi={10.1371/journal.pone.0065848}
+}
+"""
diff --git a/__main__.py b/__main__.py
--- a/__main__.py
+++ b/__main__.py
@@ -20,7 +20,7 @@
     # set default encoding to latin-1 to decode source text
     sys.setdefaultencoding('latin-1')
 
-from retriever import VERSION, SCRIPT_LIST, HOME_DIR, sample_script, current_platform
+from retriever import VERSION, SCRIPT_LIST, HOME_DIR, sample_script, CITATION
 from retriever.engines import engine_list
 from retriever.lib.repository import check_for_updates
 from retriever.lib.tools import choose_engine, name_matches, reset_retriever
@@ -41,6 +41,9 @@ def main():
 
         args = parser.parse_args()
 
+        if args.command == "install" and not args.engine:
+            parser.parse_args(['install','-h'])
+
         if args.quiet:
             sys.stdout = open(os.devnull, 'w')
 
@@ -57,10 +60,8 @@ def main():
 
         elif args.command == 'citation':
             if args.dataset is None:
-                citation_path = os.path.join(os.path.split(__file__)[0], '../CITATION')
                 print("\nCitation for retriever:\n")
-                with open(citation_path) as citation_file:
-                    print(citation_file.read())
+                print(CITATION)
             else:
                 scripts = name_matches(script_list, args.dataset)
                 for dataset in scripts:
diff --git a/lib/get_opts.py b/lib/get_opts.py
--- a/lib/get_opts.py
+++ b/lib/get_opts.py
@@ -3,7 +3,7 @@
 from retriever.engines import engine_list
 
 
-parser = argparse.ArgumentParser()
+parser = argparse.ArgumentParser(prog="retriever")
 parser.add_argument('-v', '--version', action='version', version=VERSION)
 parser.add_argument('-q', '--quiet', help='suppress command-line output', action='store_true')
 
@@ -37,7 +37,7 @@
 reset_parser.add_argument('scope', help='things to reset: all, scripts, data, or connections', choices=['all', 'scripts', 'data', 'connections'])
 install_parser.add_argument('--compile', help='force re-compile of script before downloading', action='store_true')
 install_parser.add_argument('--debug', help='run in debug mode', action='store_true')
-download_parser.add_argument('dataset', help='dataset name', nargs='?', default=None)
+download_parser.add_argument('dataset', help='dataset name')
 ls_parser.add_argument('-l', help='verbose list of datasets containing following keywords (lists all when no keywords are specified)', nargs='*')
 delete_json_parser.add_argument('dataset', help='dataset name')
 # retriever Install {Engine} ..
@@ -49,7 +49,7 @@
         pass
     else:
         engine_parser = install_subparsers.add_parser(engine.abbreviation, help=engine.name)
-        engine_parser.add_argument('dataset', help='dataset name', nargs='?', default=None)
+        engine_parser.add_argument('dataset', help='dataset name')
 
     abbreviations = set('h')
 


Test patch: