Lines Matching +full:command +full:- +full:line
1 """A generic class to build line-oriented command interpreters.
5 1. End of file on input is processed as the command 'EOF'.
6 2. A command is parsed out of each line by collecting the prefix composed
8 3. A command `foo' is dispatched to a method 'do_foo()'; the do_ method
9 is passed a single argument consisting of the remainder of the line.
10 4. Typing an empty line repeats the last command. (Actually, it calls the
13 calls the command `help_topic'. With no arguments, it lists all topics
16 6. The command '?' is a synonym for `help'. The command '!' is a synonym
20 arguments text, line, begidx, endidx. text is string we are matching
21 against, all returned matches must begin with it. line is the current
22 input line (lstripped), begidx and endidx are the beginning and end
33 in the help messages. If empty, no ruler line is drawn. It defaults to "=".
45 they automatically support Emacs-like command history and editing features.
56 """A simple framework for writing line-oriented command interpreters.
61 A Cmd instance or subclass instance is a line-oriented interpreter
80 """Instantiate a line-oriented interpreter framework.
84 not None and the readline module is available, command completion
105 the remainder of the line as argument.
126 line = self.cmdqueue.pop(0)
130 line = raw_input(self.prompt)
132 line = 'EOF'
136 line = self.stdin.readline()
137 if not len(line):
138 line = 'EOF'
140 line = line.rstrip('\r\n')
141 line = self.precmd(line)
142 stop = self.onecmd(line)
143 stop = self.postcmd(stop, line)
154 def precmd(self, line): argument
155 """Hook method executed just before the command line is
159 return line
161 def postcmd(self, stop, line): argument
162 """Hook method executed just after a command dispatch is finished."""
176 def parseline(self, line): argument
177 """Parse the line into a command name and a string containing
178 the arguments. Returns a tuple containing (command, args, line).
179 'command' and 'args' may be None if the line couldn't be parsed.
181 line = line.strip()
182 if not line:
183 return None, None, line
184 elif line[0] == '?':
185 line = 'help ' + line[1:]
186 elif line[0] == '!':
188 line = 'shell ' + line[1:]
190 return None, None, line
191 i, n = 0, len(line)
192 while i < n and line[i] in self.identchars: i = i+1
193 cmd, arg = line[:i], line[i:].strip()
194 return cmd, arg, line
196 def onecmd(self, line): argument
206 cmd, arg, line = self.parseline(line)
207 if not line:
210 return self.default(line)
211 self.lastcmd = line
212 if line == 'EOF' :
215 return self.default(line)
220 return self.default(line)
224 """Called when an empty line is entered in response to the prompt.
227 command entered.
233 def default(self, line): argument
234 """Called on an input line when the command prefix is not recognized.
240 self.stdout.write('*** Unknown syntax: %s\n'%line)
243 """Method called to complete an input line when no command-specific
258 If a command has not been entered, then complete against command list.
259 Otherwise try to call complete_<command> to get list of completions.
264 line = origline.lstrip()
265 stripped = len(origline) - len(line)
266 begidx = readline.get_begidx() - stripped
267 endidx = readline.get_endidx() - stripped
269 cmd, args, foo = self.parseline(line)
279 self.completion_matches = compfunc(text, line, begidx, endidx)
347 self.columnize(cmds, maxcol-1)
370 ncols = (size+nrows-1) // nrows
372 totwidth = -2
400 while texts and not texts[-1]:
401 del texts[-1]