# Path: doxter/cmdargs.py
# class CmdArgs:
# 	def __init__(self, name, version, **kwargs):
# 		self.name = name
# 		self.version = version
# 		self.desc= name.capitalize() + ' v%d.%d.%d' % version
# 		self.usage = 'usage: %s [options]' % name
# 		self.error = 'Invalid options. Run `%s --help` for assistance.' % name
# 		self.__dict__ = dict(self.__dict__, **kwargs)
# 
# 		self.arguments = []
# 		self.examples = []
# 
# 	def add_example(self, example):
# 		self.examples.append(example)
# 
# 	def add_argument(self, name, **kwargs):
# 		opts = {'name' : '--%s' % name, 'shortname' : '-%s' % name[0]}
# 		self.arguments.append((name, dict(opts, **kwargs)))
# 
# 	def get_argument(self, name):
# 		for arg in self.arguments:
# 			_name, opts = arg
# 			if opts['name'] == name:
# 				return arg
# 			if opts['shortname'] == name:
# 				return arg
# 
# 		return None, None
# 
# 	def parse(self, argv):
# 		_argv = []
# 		args = CmdArgsList()
# 
# 		for arg in argv:
# 			if not arg.startswith('-'):
# 				_argv.append(arg)
# 				continue
# 
# 			name, opts = self.get_argument(arg)
# 
# 			if name == None:
# 				raise InvalidArgument('Argument `%s` is not a valid option.' % arg)
# 			else:
# 				value = True
# 				if 'type' in opts:
# 					type = opts['type']
# 					i = argv.index(arg)
# 					if i+1 < len(argv):
# 						value = argv.pop(i+1)
# 
# 						if value.startswith('-'):
# 							raise MissingValue('Argument `%s` requires a value.' % arg)
# 
# 						try:
# 							value = type(value)
# 						except ValueError, err:
# 							raise InvalidValue('Value `%s` of `%s` is expected to be of type `%s`.' % (value, arg, type.__name__))
# 
# 						args.append((name, value))
# 					else:
# 						raise MissingValue('Argument `%s` requires a value.' % arg)
# 				else:
# 					args.append((name, value))
# 
# 		args.append(('argv', tuple(_argv)))
# 
# 		return args
# 
# 	def show_version(self):
# 		print('%d.%d.%d' % self.version)
# 		return 0
# 
# 	def show_help(self):
# 		print(self.desc)
# 		print
# 		print(self.usage)
# 		if len(self.examples) > 0:
# 			print
# 			print('Examples:')
# 			for example in self.examples:
# 				print('\t%s %s' % (self.name, example))
# 		print
# 		print('Options:')
# 		for arg in self.arguments:
# 			name, opts = arg
# 			print('\t%s, %s\t%s' % (opts['shortname'], opts['name'], opts['desc']))
# 		return -1
# 
# 	def show_error(self, error):
# 		print(error)
# 		print(self.error)
# 		return -1
# 
# class CmdParseError(Exception):
# 	pass


import sys, os, glob, shutil, time
import doxter
	import _plugins as plugins
from doxter.cmdargs import CmdArgs, CmdParseError
from doxter.processors import *
	from _plugins import *
		from cmdserver import CmdServer
			shutil.copy(file, output_file)
		elif os.path.isdir(file):
			if os.path.exists(output_file):
				shutil.rmtree(output_file)
			shutil.copytree(file, output_file)

def main(argv):
	cmdargs = CmdArgs('doxter', doxter.__version__)
	cmdargs.add_example('-f MyDoxterFile')
	cmdargs.add_argument('file'		,desc='specify non-standard Doxterfile', type=str)
	cmdargs.add_argument('server'	,desc='start server')
	cmdargs.add_argument('port'		,desc='specify server port (default port: 4000)', type=int)
	cmdargs.add_argument('version'	,desc='shows version information')
	cmdargs.add_argument('help'		,desc='shows help')

	try:
		args = cmdargs.parse(argv[1:])
	except CmdParseError, err:
		return cmdargs.show_error(err)

	if args.get_argument('version'):
		return cmdargs.show_version()

	if args.get_argument('help'):
		return cmdargs.show_help()

	doxterfile = args.get_argument('file', 'Doxterfile')
	if not os.path.exists(doxterfile):
		return cmdargs.show_error('%s does not exists.' % doxterfile)


# Path: doxter/cmdargs.py
# class CmdArgs:
# 	def __init__(self, name, version, **kwargs):
# 		self.name = name
# 		self.version = version
# 		self.desc= name.capitalize() + ' v%d.%d.%d' % version
# 		self.usage = 'usage: %s [options]' % name
# 		self.error = 'Invalid options. Run `%s --help` for assistance.' % name
# 		self.__dict__ = dict(self.__dict__, **kwargs)
# 
# 		self.arguments = []
# 		self.examples = []
# 
# 	def add_example(self, example):
# 		self.examples.append(example)
# 
# 	def add_argument(self, name, **kwargs):
# 		opts = {'name' : '--%s' % name, 'shortname' : '-%s' % name[0]}
# 		self.arguments.append((name, dict(opts, **kwargs)))
# 
# 	def get_argument(self, name):
# 		for arg in self.arguments:
# 			_name, opts = arg
# 			if opts['name'] == name:
# 				return arg
# 			if opts['shortname'] == name:
# 				return arg
# 
# 		return None, None
# 
# 	def parse(self, argv):
# 		_argv = []
# 		args = CmdArgsList()
# 
# 		for arg in argv:
# 			if not arg.startswith('-'):
# 				_argv.append(arg)
# 				continue
# 
# 			name, opts = self.get_argument(arg)
# 
# 			if name == None:
# 				raise InvalidArgument('Argument `%s` is not a valid option.' % arg)
# 			else:
# 				value = True
# 				if 'type' in opts:
# 					type = opts['type']
# 					i = argv.index(arg)
# 					if i+1 < len(argv):
# 						value = argv.pop(i+1)
# 
# 						if value.startswith('-'):
# 							raise MissingValue('Argument `%s` requires a value.' % arg)
# 
# 						try:
# 							value = type(value)
# 						except ValueError, err:
# 							raise InvalidValue('Value `%s` of `%s` is expected to be of type `%s`.' % (value, arg, type.__name__))
# 
# 						args.append((name, value))
# 					else:
# 						raise MissingValue('Argument `%s` requires a value.' % arg)
# 				else:
# 					args.append((name, value))
# 
# 		args.append(('argv', tuple(_argv)))
# 
# 		return args
# 
# 	def show_version(self):
# 		print('%d.%d.%d' % self.version)
# 		return 0
# 
# 	def show_help(self):
# 		print(self.desc)
# 		print
# 		print(self.usage)
# 		if len(self.examples) > 0:
# 			print
# 			print('Examples:')
# 			for example in self.examples:
# 				print('\t%s %s' % (self.name, example))
# 		print
# 		print('Options:')
# 		for arg in self.arguments:
# 			name, opts = arg
# 			print('\t%s, %s\t%s' % (opts['shortname'], opts['name'], opts['desc']))
# 		return -1
# 
# 	def show_error(self, error):
# 		print(error)
# 		print(self.error)
# 		return -1
# 
# class CmdParseError(Exception):
# 	pass


# Path: doxter/cmdline.py
import sys, os, glob, shutil, time
import doxter
	import _plugins as plugins
from doxter.cmdargs import CmdArgs, CmdParseError
from doxter.processors import *
	from _plugins import *
		from cmdserver import CmdServer

			shutil.copy(file, output_file)
		elif os.path.isdir(file):
			if os.path.exists(output_file):
				shutil.rmtree(output_file)
			shutil.copytree(file, output_file)

def main(argv):
	cmdargs = CmdArgs('doxter', doxter.__version__)
	cmdargs.add_example('-f MyDoxterFile')
	cmdargs.add_argument('file'		,desc='specify non-standard Doxterfile', type=str)
	cmdargs.add_argument('server'	,desc='start server')
	cmdargs.add_argument('port'		,desc='specify server port (default port: 4000)', type=int)
	cmdargs.add_argument('version'	,desc='shows version information')
	cmdargs.add_argument('help'		,desc='shows help')

	try:
		args = cmdargs.parse(argv[1:])
	except CmdParseError, err:
		return cmdargs.show_error(err)

	if args.get_argument('version'):
		return cmdargs.show_version()

	if args.get_argument('help'):
		return cmdargs.show_help()

	doxterfile = args.get_argument('file', 'Doxterfile')
	if not os.path.exists(doxterfile):
		return cmdargs.show_error('%s does not exists.' % doxterfile)


	doxter.set_config('template_dir', '_templates')