Esempio n. 1
0
#!/bin/env python

from instacmd import InstaCmd

cmd = InstaCmd()

@cmd.add('hi-mom')
def hi_mom(args):
	'''says hi to your mom'''
	print 'hi mom!'

@cmd.add('fail')
def fail(args):
	'''fails'''
	raise 'FAIL'

from sys import argv
cmd.run(argv)
Esempio n. 2
0
#!/bin/env python3

"""
"""

from instacmd import InstaCmd
cmd = InstaCmd()

from collections import namedtuple

class MatchFlags:
	empty, index, wild = 0, 1, 2

MatchSpec = namedtuple('MatchSpec', 'ok match wildcards flags detail'.split())

@cmd.debug
def match(ls, lp, j, wc, i, d, p):
	wcs = []
	w = d
	for idx,s in enumerate(p):
		cmd.debug_locals(w=w,idx=idx,s=s)
		if lp(w):
			return MatchSpec(False, None, None, MatchFlags.empty, 'path too deep')
		o = ls(w)
		if s in o:
			w = j(w, s)
		elif wc in o:
			w = j(w, wc)
			if lp(w):
				wcs.append(p[idx:])
				return MatchSpec(True, w, wcs, MatchFlags.wild, 'wildcard tail')