<commit_before>import sys, os, argparse

###

class _parser_base(argparse.ArgumentParser):

	argparser_kwargs = {}
	subparser_kwargs = {}

	def __init__(self, cnsapp):
		argparse.ArgumentParser.__init__(self, **self.argparser_kwargs)

		self.subparsers = self.add_subparsers(
			dest='subcommand',
			title='subcommands',
			parser_class=argparse.ArgumentParser,
		)
		
		# Adding sub-commands ...
		self.subcommands = {}
		for cmd in self.build_cmdlist():
			subparser = self.subparsers.add_parser(cmd.name, help=cmd.cmdhelp, **self.subparser_kwargs)
			cmd.init_parser(subparser)
			self.subcommands[cmd.name] = cmd

		#Iterate via application object to find 'tool' and 'proxy_tool' (decorated method)
		for mn in dir(cnsapp):
			fn = getattr(cnsapp, mn)
			if hasattr(fn, 'tool'):
				self.subparsers.add_parser(mn, help=fn.__doc__)
				self.subcommands[mn] = fn.im_func # Unbound method
			elif hasattr(fn, 'proxy_tool'):
				self.subparsers.add_parser(mn, help=fn.__doc__)
				# Not subcommand as proxy tools are handled prior argument parsing


	def build_cmdlist(self):
		from .cmd import start
		yield start

		from .cmd import stop
		yield stop

		from .cmd import restart
		yield restart

		from .cmd import status
		yield status

		from .cmd import help
		yield help

		from .cmd import tail
		yield tail

		if sys.platform == 'win32':
			from .cmd import wininstall
			yield wininstall

			from .cmd import winuninstall
			yield winuninstall


	def parse(self, argv):
		self.args = None # This is to allow re-entrant parsing
		self.args = self.parse_args(argv)
		

	def execute(self, cnsapp):
		if self.args.subcommand == 'help':
			# Help is given by special treatment as this is actually function of parser itself
			self.print_help()
			return

		cmdobj = self.subcommands[self.args.subcommand]

		if hasattr(cmdobj,'__call__'):
			return cmdobj(cnsapp)
		else:
			return cmdobj.main(cnsapp, self.args)

#

class argparser(_parser_base):

	def __init__(self, cnsapp):
		_parser_base.__init__(self, cnsapp)
<commit_msg>Help text (--help) now contains version of Ramona.<commit_after>import sys, os, argparse

###

class _parser_base(argparse.ArgumentParser):

	argparser_kwargs = None # To be overridden in final parser implementation class
	subparser_kwargs = None # To be overridden in final parser implementation class

	def __init__(self, cnsapp):

		# Build parser
		argparse.ArgumentParser.__init__(self, **self.argparser_kwargs)

		self.subparsers = self.add_subparsers(
			dest='subcommand',
			title='subcommands',
			parser_class=argparse.ArgumentParser,
		)
		
		# Adding sub-commands ...
		self.subcommands = {}
		for cmd in self.build_cmdlist():
			subparser = self.subparsers.add_parser(cmd.name, help=cmd.cmdhelp, **self.subparser_kwargs)
			cmd.init_parser(subparser)
			self.subcommands[cmd.name] = cmd

		#Iterate via application object to find 'tool' and 'proxy_tool' (decorated method)
		for mn in dir(cnsapp):
			fn = getattr(cnsapp, mn)
			if hasattr(fn, 'tool'):
				self.subparsers.add_parser(mn, help=fn.__doc__)
				self.subcommands[mn] = fn.im_func # Unbound method
			elif hasattr(fn, 'proxy_tool'):
				self.subparsers.add_parser(mn, help=fn.__doc__)
				# Not subcommand as proxy tools are handled prior argument parsing


	def build_cmdlist(self):
		from .cmd import start
		yield start

		from .cmd import stop
		yield stop

		from .cmd import restart
		yield restart

		from .cmd import status
		yield status

		from .cmd import help
		yield help

		from .cmd import tail
		yield tail

		if sys.platform == 'win32':
			from .cmd import wininstall
			yield wininstall

			from .cmd import winuninstall
			yield winuninstall


	def parse(self, argv):
		self.args = None # This is to allow re-entrant parsing
		self.args = self.parse_args(argv)
		

	def execute(self, cnsapp):
		if self.args.subcommand == 'help':
			# Help is given by special treatment as this is actually function of parser itself
			self.print_help()
			return

		cmdobj = self.subcommands[self.args.subcommand]

		if hasattr(cmdobj,'__call__'):
			return cmdobj(cnsapp)
		else:
			return cmdobj.main(cnsapp, self.args)

#

class argparser(_parser_base):

	argparser_kwargs = {}
	subparser_kwargs = {}

	def __init__(self, cnsapp):

		# Prepare description (with Ramona version)
		from .. import version as ramona_version
		self.argparser_kwargs['description'] = 'Powered by Ramona (version {0}).'.format(ramona_version)

		_parser_base.__init__(self, cnsapp)

{'fraction_non_alphanumeric': 0.09812248547161377, 'fraction_numerical': 0.001117568171658471, 'mean_word_length': 3.9175824175824174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3709694', 'n_tokens_mistral': 1675, 'n_tokens_neox': 1440, 'n_words': 403}