handle no arguments or non-file/non-existen filenames
When using `pecan serve` we should be able to handle nicely when no options or bad filenames are given to avoid seeing a not so helpful traceback.
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
"""
|
||||
PasteScript serve command for Pecan.
|
||||
"""
|
||||
from paste import httpserver
|
||||
from paste import httpserver
|
||||
from paste.script import command as paste_command
|
||||
from paste.script.serve import ServeCommand as _ServeCommand
|
||||
|
||||
from base import Command
|
||||
|
||||
from base import Command
|
||||
import os
|
||||
import re
|
||||
|
||||
|
||||
@@ -43,10 +44,12 @@ class ServeCommand(_ServeCommand, Command):
|
||||
setattr(self.options, 'app_name', None)
|
||||
setattr(self.options, 'server', None)
|
||||
setattr(self.options, 'server_name', None)
|
||||
|
||||
|
||||
config_file = self.validate_file(self.args)
|
||||
|
||||
# for file-watching to work, we need a filename, not a module
|
||||
if self.requires_config_file and self.args:
|
||||
self.config = self.load_configuration(self.args[0])
|
||||
self.config = self.load_configuration(config_file)
|
||||
self.args[0] = self.config.__file__
|
||||
if self.options.reload is None:
|
||||
self.options.reload = getattr(self.config.app, 'reload', False)
|
||||
@@ -59,3 +62,8 @@ class ServeCommand(_ServeCommand, Command):
|
||||
|
||||
def loadapp(self, app_spec, name, relative_to, **kw):
|
||||
return self.load_app(self.config)
|
||||
|
||||
def validate_file(self, argv):
|
||||
if not argv or not os.path.isfile(argv[0]):
|
||||
raise paste_command.BadCommand('This command needs a valid config file.')
|
||||
return argv[0]
|
||||
|
||||
Reference in New Issue
Block a user