Skip to content

Commit

Permalink
Merge pull request #237 from tomerfiliba/cli_run
Browse files Browse the repository at this point in the history
Cli direct run
  • Loading branch information
henryiii committed Nov 18, 2015
2 parents 5644c93 + 330eef1 commit 39c0a7a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ And you can run it::

So far you've only seen the very basic usage. We'll now start to explore the library.

.. versionadded:: 1.6.1

You can also directly run the app, as ``MyApp()``, without arguments, instead of calling ``.main()``.

Application
-----------
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ def main(self, *srcfiles):


if __name__ == "__main__":
MyCompiler.run()
MyCompiler()

13 changes: 13 additions & 0 deletions plumbum/cli/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ def main(self, src, dst):
nested_command = None
_unbound_switches = ()

def __new__(cls, executable=None):
"""Allows running the class directly as a shortcut for main.
This is neccisary for some setup scripts that want a single function,
instead of an expression with a dot in it."""


if executable is None:
return cls.run()
# This return value was not a class instance, so __init__ is never called
else:
return super(Application, cls).__new__(cls)

def __init__(self, executable):
# Filter colors

Expand Down Expand Up @@ -166,6 +178,7 @@ def __init__(self, executable):
if swinfo.envname:
self._switches_by_envar[swinfo.envname] = swinfo


@property
def root_app(self):
return self.parent.root_app if self.parent else self
Expand Down

0 comments on commit 39c0a7a

Please sign in to comment.