Revision 489a1047

b/kamaki/cli/command_shell.py
40 40
from .argument import _arguments
41 41
from .utils import magenta, print_dict
42 42
from sys import stdout
43
from .history import History
43 44

  
44 45
def _fix_arguments():
45 46
	_arguments.pop('version', None)
......
51 52
	_prefix = '['
52 53
	_suffix = ']:'
53 54
	cmd_tree = None
55
	_history = None
54 56

  
55 57
	def greet(self, version):
56 58
		print('kamaki v%s - Interactive Shell\n\t(exit or ^D to exit)\n'%version)
......
77 79
	def _register_method(self, method, name):
78 80
		self.__dict__[name]=method
79 81

  
82
	def _roll_command(self, cmd_path):
83
		for subname in self.cmd_tree.get_subnames(cmd_path):
84
			try:
85
				self.__dict__.pop('do_%s'%subname)
86
				self.__dict__.pop('complete_%s'%subname)
87
				self.__dict__.pop('help_%s'%subname)
88
			except KeyError:
89
				pass
90

  
80 91
	@classmethod 
81 92
	def _backup(self):
82 93
		return dict(self.__dict__)
......
87 98
	def _push_in_command(self, cmd_path):
88 99
		cmd = self.cmd_tree.get_command(cmd_path)
89 100
		_cmd_tree = self.cmd_tree
101
		_history = self._history
90 102

  
91 103
		def do_method(self, line):
92 104
			""" Template for all cmd.Cmd methods of the form do_<cmd name>
......
94 106
				<cmd> <term> <term> <args> is always parsed to the most specific cmd path
95 107
				even if cmd_term_term is not a terminal path
96 108
			"""
109
			if _history:
110
				_history.add(' '.join([cmd.path.replace('_',' '), line]))
97 111
			subcmd, cmd_args = cmd.parse_out(line.split())
98 112
			active_terms = [cmd.name]+subcmd.path.split('_')[len(cmd.path.split('_')):]
99 113
			subname = '_'.join(active_terms)
......
144 158
			subcmd, cmd_args = cmd.parse_out(line.split()[1:])
145 159
			if subcmd.is_command:
146 160
				cls = subcmd.get_class()
147
				instance = cls(_arguments)
161
				instance = cls({})
148 162
				empty, sep, subname = subcmd.path.partition(cmd.path)
149 163
				cmd_name = '%s %s'%(cmd.name,subname.replace('_',' '))
150 164
				print('\n%s\nSyntax:\t%s %s'%(cls.description,cmd_name,cls.syntax))
......
157 171
		self._register_method(complete_method, 'complete_%s'%cmd.name)
158 172

  
159 173
	def run(self, path=''):
174
		self._history = History(_arguments['config'].get('history', 'file'))
160 175
		if len(path):
161 176
			cmd = self.cmd_tree.get_command(path)
162 177
			intro = cmd.path.replace('_', ' ')

Also available in: Unified diff