# Path: cinje/util.py
# def flatten(input, file=None, encoding=None, errors='strict'):
# 	"""Return a flattened representation of a cinje chunk stream.
# 	
# 	This has several modes of operation.  If no `file` argument is given, output will be returned as a string.
# 	The type of string will be determined by the presence of an `encoding`; if one is given the returned value is a
# 	binary string, otherwise the native unicode representation.  If a `file` is present, chunks will be written
# 	iteratively through repeated calls to `file.write()`, and the amount of data (characters or bytes) written
# 	returned.  The type of string written will be determined by `encoding`, just as the return value is when not
# 	writing to a file-like object.  The `errors` argument is passed through when encoding.
# 	
# 	We can highly recommend using the various stremaing IO containers available in the
# 	[`io`](https://docs.python.org/3/library/io.html) module, though
# 	[`tempfile`](https://docs.python.org/3/library/tempfile.html) classes are also quite useful.
# 	"""
# 	
# 	input = stream(input, encoding, errors)
# 	
# 	if file is None:  # Exit early if we're not writing to a file.
# 		return b''.join(input) if encoding else ''.join(input)
# 	
# 	counter = 0
# 	
# 	for chunk in input:
# 		file.write(chunk)
# 		counter += len(chunk)
# 	
# 	return counter


import sys
	import pygments
	import pygments.lexers
	import pygments.formatters
from cinje import flatten




class CommandLineInterface(object):
	def __init__(self, arguments):
		remainder = list(arguments)
		kwargs = list((i, remainder.pop(i), v.partition('=')) for i, v in reversed(list(enumerate(arguments))) if v.startswith('--'))
		self.kwargs = {k[2:]: v for i, (k, _, v) in kwargs}
		self.flags = set(remainder.pop(i)[1:] for i, v in reversed(list(enumerate(remainder))) if v.startswith('-'))
		self.args = remainder
	
	def go(self, action, *args, **data):
		action = getattr(self, action)
		result = action(*args, **data)
		if isinstance(result, int):
			sys.exit(result)
		if result:
			print(result)
	
	def render(self, reference, *args, **kw):
		output = kw.pop('out', None)
		encoding = kw.pop('encoding', 'utf8')
		
		module, _, function = reference.partition(':')
		module = __import__(module, fromlist=(function, ))
		template = getattr(module, function)(*args, **kw)
		
		if output and output != '-':
			with open(output, 'wb') as fh:

# Path: cinje/util.py
# def flatten(input, file=None, encoding=None, errors='strict'):
# 	"""Return a flattened representation of a cinje chunk stream.
# 	
# 	This has several modes of operation.  If no `file` argument is given, output will be returned as a string.
# 	The type of string will be determined by the presence of an `encoding`; if one is given the returned value is a
# 	binary string, otherwise the native unicode representation.  If a `file` is present, chunks will be written
# 	iteratively through repeated calls to `file.write()`, and the amount of data (characters or bytes) written
# 	returned.  The type of string written will be determined by `encoding`, just as the return value is when not
# 	writing to a file-like object.  The `errors` argument is passed through when encoding.
# 	
# 	We can highly recommend using the various stremaing IO containers available in the
# 	[`io`](https://docs.python.org/3/library/io.html) module, though
# 	[`tempfile`](https://docs.python.org/3/library/tempfile.html) classes are also quite useful.
# 	"""
# 	
# 	input = stream(input, encoding, errors)
# 	
# 	if file is None:  # Exit early if we're not writing to a file.
# 		return b''.join(input) if encoding else ''.join(input)
# 	
# 	counter = 0
# 	
# 	for chunk in input:
# 		file.write(chunk)
# 		counter += len(chunk)
# 	
# 	return counter


# Path: cinje/__main__.py
import sys
	import pygments
	import pygments.lexers
	import pygments.formatters
from cinje import flatten





class CommandLineInterface(object):
	def __init__(self, arguments):
		remainder = list(arguments)
		kwargs = list((i, remainder.pop(i), v.partition('=')) for i, v in reversed(list(enumerate(arguments))) if v.startswith('--'))
		self.kwargs = {k[2:]: v for i, (k, _, v) in kwargs}
		self.flags = set(remainder.pop(i)[1:] for i, v in reversed(list(enumerate(remainder))) if v.startswith('-'))
		self.args = remainder
	
	def go(self, action, *args, **data):
		action = getattr(self, action)
		result = action(*args, **data)
		if isinstance(result, int):
			sys.exit(result)
		if result:
			print(result)
	
	def render(self, reference, *args, **kw):
		output = kw.pop('out', None)
		encoding = kw.pop('encoding', 'utf8')
		
		module, _, function = reference.partition(':')
		module = __import__(module, fromlist=(function, ))
		template = getattr(module, function)(*args, **kw)
		
		if output and output != '-':
			with open(output, 'wb') as fh:

				flatten(template, fh, encoding=encoding)