This repository has been archived on 2015-04-29. You can view files and clone it, but cannot push or open issues or pull requests.
psh/example_cmd.py
Ian Adam Naval 5565f0c4ef Update api to use chain and call
Much sexier than __call__
2015-02-26 15:37:08 -05:00

34 lines
903 B
Python

from commands import BaseCommand, register_cmd
@register_cmd
class example_cmd(BaseCommand):
"""Simple command that just returns 'example' and 'command'. Does
nothing at all with the input."""
def call(self, *args, **kwargs):
def output_generator():
yield b'example'
yield b'command'
return output_generator
@register_cmd
class echo(BaseCommand):
"""Echoes anything from the command line arguments as well as input
from the previous command."""
def __init__(self, args):
super(echo, self).__init__()
self.args = args
def call(self,*args,**kwargs):
input_generator = self.get_input_generator()
def output_generator():
for args in self.args:
yield args.encode("utf-8")
for line in input_generator:
yield line
return output_generator