Permalink
Browse files

add @append command to append items to a list

@append 1 2 3 -i 4 5 6
[1, 2, 3, 4, 5, 6]

✗ @append 1 2 3 -i 4
[1, 2, 3, 4]

@append 1 -i 4
[1, 4]

@append 1 -i
[1, true]

@append 1 -a
ValueError: items parameter required

@append 1 -i 1 2 3
[1, 1, 2, 3]

@append 1
[2, 3, 4]^D
[1, 2, 3, 4]

@echo 1 2 3 | @append 0
[0, 1, 2, 3]

@echo 1 2 3 | @append -i 0
[1, 2, 3, 0]
  • Loading branch information...
1 parent 549e891 commit b035e6d0cc4cfd8f427c2a25acff715aac6a98bd @marianoguerra committed Mar 30, 2012
Showing with 34 additions and 0 deletions.
  1. +1 −0 bin/@append
  2. +33 −0 yel/commands.py
View
View
@@ -909,6 +909,39 @@ def process_single(self, item):
'''do the process on single value'''
raise ValueError("type parameter required")
+class Append(MultiTypeCommand):
+ '''append items to another list'''
+
+ SHORT = "append"
+ LOND = "append"
+
+ EXPAND_SHORT_OPTIONS = {
+ "i": "items"
+ }
+
+ def process_list(self, items):
+ '''do the process on items'''
+ to_append = self.get_args_list(True, False, False)
+ items.extend(to_append)
+ return items
+
+ def process_object(self, items):
+ '''do the process on object'''
+
+ current = self.get_args_list(True)
+
+ to_append = items.get("items", None)
+
+ if to_append is None:
+ raise ValueError("items parameter required")
+
+ current.extend(util.listify(to_append))
+ return current
+
+ def process_single(self, item):
+ '''do the process on single value'''
+ return self.process_list([item])
+
def load_commands():
'''load available commands'''
for attr in globals().values():

0 comments on commit b035e6d

Please sign in to comment.