"""
CLI entrypoint & parser configuration.

Builds on top of Invoke's core functionality for same.
"""

from invoke import Program, __version__ as invoke, FilesystemLoader, Argument
from paramiko import __version__ as paramiko

from . import __version__ as fabric


class Fab(Program):
    def print_version(self):
        super(Fab, self).print_version()
        print("Paramiko {0}".format(paramiko))
        print("Invoke {0}".format(invoke))

    def core_args(self):
        core_args = super(Fab, self).core_args()
        my_args = [
            Argument(
                names=('H', 'hosts'),
                help="Host name(s) to execute tasks against.",
            ),
        ]
        return core_args + my_args


class FabfileLoader(FilesystemLoader):
    # TODO: we may run into issues re: swapping loader "strategies" (eg
    # FilesystemLoader vs...something else eventually) versus this sort of
    # "just tweaking DEFAULT_COLLECTION_NAME" setting. Maybe just make the
    # default collection name itself a runtime option?
    DEFAULT_COLLECTION_NAME = 'fabfile'


program = Fab(
    name="Fabric",
    version=fabric,
    loader_class=FabfileLoader,
)

@@ -128,31 +128,8 @@
 ram,
- __version__ as invoke,
  Fil
@@ -151,16 +151,73 @@
 Argument
+, Task, Executor%0Afrom invoke import __version__ as invoke
 %0Afrom pa
@@ -753,16 +753,826 @@
 _args%0A%0A%0A
+# TODO: come up w/ a better name heh%0Aclass FabExecutor(Executor):%0A    def expand_tasks(self, tasks):%0A        # We still want pre/post tasks expanded, so run our parent%0A        tasks = super(FabExecutor, self).expand_tasks(tasks)%0A        # Then tack on remainder to the end, if necessary%0A        if self.core.remainder:%0A            def anonymous(c):%0A                c.run(self.core.remainder)%0A            tasks.append(Task(body=anonymous, contextualized=True))%0A        return tasks%0A%0A# TODO: would be nice to run w/o a fabfile present if we give a remainder%0A# TODO: this also means running w/o any tasks, so tweaking core program loop%0A# TODO: the above is present in Fab 1 and isn't SUPER required (it does nothing%0A# you can't do w/ vanilla ssh client) but nice-to-have for backwards compat /%0A# testing / etc.%0A%0A%0A
 class Fa
@@ -1975,16 +1975,16 @@
 fabric,%0A
-
     load
@@ -2007,10 +2007,42 @@
 Loader,%0A
+    executor_class=FabExecutor,%0A
 )%0A

Implement basic remainder-as-task functionality.