mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
Rework cmdparse.Script API
The API now requires a command argument from signature. Parsing errors (no command from input) is thrown as a custom exception, and caught by the outmost possible invocation to emit a message from click.
This commit is contained in:
+11
-6
@@ -4,22 +4,27 @@ import shlex
|
||||
import six
|
||||
|
||||
|
||||
class ScriptEmptyError(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
class Script(object):
|
||||
"""Parse a script line (in Pipfile's [scripts] section).
|
||||
|
||||
This always works in POSIX mode, even on Windows.
|
||||
"""
|
||||
def __init__(self, parts):
|
||||
if not parts:
|
||||
raise ValueError('invalid script')
|
||||
self._parts = parts
|
||||
|
||||
def __init__(self, command, args=None):
|
||||
self._parts = [command]
|
||||
if args:
|
||||
self._parts.extend(args)
|
||||
|
||||
@classmethod
|
||||
def parse(cls, value):
|
||||
if isinstance(value, six.string_types):
|
||||
value = shlex.split(value)
|
||||
return cls(value)
|
||||
if not value:
|
||||
raise ScriptEmptyError(value)
|
||||
return cls(value[0], value[1:])
|
||||
|
||||
def __repr__(self):
|
||||
return 'Script({0!r})'.format(self._parts)
|
||||
|
||||
Reference in New Issue
Block a user