Issue 1:
Expected Behavior

Only the error message / usage information being printed

Actual Behavior

A traceback shows up above the usage information.

Environment

Python version: 2.7.14

Flask version: 1.0.2

Werkzeug version: 0.14.1

[adrian@blackhole:/tmp]> virtualenv testenv
New python executable in /tmp/testenv/bin/python2.7
Also creating executable in /tmp/testenv/bin/python
Installing setuptools, pip, wheel...done.

[adrian@blackhole:/tmp]> ./testenv/bin/pip install flask
Collecting flask
Using cached https://files.pythonhosted.org/packages/7f/e7/08578774ed4536d3242b14dacb4696386634607af824ea997202cd0edb4b/Flask-1.0.2-py2.py3-none-any.whl
Collecting Werkzeug>=0.14 (from flask)
Using cached https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl
Collecting click>=5.1 (from flask)
Using cached https://files.pythonhosted.org/packages/34/c1/8806f99713ddb993c5366c362b2f908f18269f8d792aff1abfd700775a77/click-6.7-py2.py3-none-any.whl
Collecting itsdangerous>=0.24 (from flask)
Collecting Jinja2>=2.10 (from flask)
Using cached https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl
Collecting MarkupSafe>=0.23 (from Jinja2>=2.10->flask)
Installing collected packages: Werkzeug, click, itsdangerous, MarkupSafe, Jinja2, flask
Successfully installed Jinja2-2.10 MarkupSafe-1.0 Werkzeug-0.14.1 click-6.7 flask-1.0.2 itsdangerous-0.24

[adrian@blackhole:/tmp]> ./testenv/bin/flask
Traceback (most recent call last):
File "/tmp/testenv/lib/python2.7/site-packages/flask/cli.py", line 529, in list_commands
rv.update(info.load_app().cli.list_commands(ctx))
File "/tmp/testenv/lib/python2.7/site-packages/flask/cli.py", line 384, in load_app
'Could not locate a Flask application. You did not provide '
NoAppException: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.
Usage: flask [OPTIONS] COMMAND [ARGS]...

A general utility script for Flask applications.

Provides commands from Flask, extensions, and the application. Loads the
application defined in the FLASK_APP environment variable, or from a
wsgi.py file. Setting the FLASK_ENV environment variable to 'development'
will enable debug mode.

$ export FLASK_APP=hello.py
$ export FLASK_ENV=development
$ flask run

Options:
--version Show the flask version
--help Show this message and exit.

Commands:
routes Show the routes for the app.
run Runs a development server.
shell Runs a shell in the app context.

Issue 2:
Expected Behavior

As there is the support for lazy loading the app, when running flask CLI without providing the proper environment variables we must see a better warning instead of raw exception.

Tell us what should happen.

we should see a better warning or message pointing to the problem

# there is no FLASK_APP env var
$ flask --help
WARNING: You need to define the app e.g: `export FLASK_APP=app.py`

Actual Behavior

Tell us what happens instead.

we see traceback before the help message

# there is no FLASK_APP env var
$ flask --help Sat 28 Apr 2018 01:25:50 PM -03
Traceback (most recent call last):
File "~Projects/personal/flasgger/venv/lib/python3.6/site-packages/flask/cli.py", line 235, in locate_app
__import__(module_name)
ModuleNotFoundError: No module named 'app'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "~/Projects/personal/flasgger/venv/lib/python3.6/site-packages/flask/cli.py", line 529, in list_commands
rv.update(info.load_app().cli.list_commands(ctx))
File "~/Projects/personal/flasgger/venv/lib/python3.6/site-packages/flask/cli.py", line 372, in load_app
app = locate_app(self, import_name, name)
File "~/Projects/personal/flasgger/venv/lib/python3.6/site-packages/flask/cli.py", line 246, in locate_app
'Could not import "{name}".'.format(name=module_name)
flask.cli.NoAppException: Could not import "app".
Usage: flask [OPTIONS] COMMAND [ARGS]...

A general utility script for Flask applications.

Provides commands from Flask, extensions, and the application. Loads the
application defined in the FLASK_APP environment variable, or from a
wsgi.py file. Setting the FLASK_ENV environment variable to 'development'
will enable debug mode.

$ export FLASK_APP=hello.py
$ export FLASK_ENV=development
$ flask run

Options:
--version Show the flask version
--help Show this message and exit.

Commands:
routes Show the routes for the app.
run Runs a development server.
shell Runs a shell in the app context.

The same happens to run

$ flask run 429ms  Sat 28 Apr 2018 01:32:48 PM -03
* Serving Flask app "app.py"
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
Usage: flask run [OPTIONS]

Error: Could not import "app".

The Error: Could not import "app". could include WARNING: You need to define the app e.g: export FLASK_APP=app.py

Suggestion

We could check the existence of FLASK_APP envvar before running any of the commands in the Group Cli, if FLASK_APP does not exist the dispatch of commands never happens.

Environment

Python version: 3.6.0

Flask version: Flask==1.0

Werkzeug version: Werkzeug==0.14.1

Click: click==6.7