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
2015-02-26 16:22:21 -05:00

37 lines
1003 B
Python

from commands import BaseCommand, register_cmd
from tree import TreeNode
@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 TreeNode(b'example')
yield TreeNode(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 TreeNode(args.encode("utf-8"))
for node in input_generator:
line = node.data
yield TreeNode(line)
return output_generator