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 "=".
53 """A simple framework for writing line-oriented command interpreters.
58 A Cmd instance or subclass instance is a line-oriented interpreter
77 """Instantiate a line-oriented interpreter framework.
81 not None and the readline module is available, command completion
101 the remainder of the line as argument.
122 line = self.cmdqueue.pop(0)
126 line = input(self.prompt)
128 line = 'EOF'
132 line = self.stdin.readline()
133 if not len(line):
134 line = 'EOF'
136 line = line.rstrip('\r\n')
137 line = self.precmd(line)
138 stop = self.onecmd(line)
139 stop = self.postcmd(stop, line)
150 def precmd(self, line): argument
151 """Hook method executed just before the command line is
155 return line
157 def postcmd(self, stop, line): argument
158 """Hook method executed just after a command dispatch is finished."""
172 def parseline(self, line): argument
173 """Parse the line into a command name and a string containing
174 the arguments. Returns a tuple containing (command, args, line).
175 'command' and 'args' may be None if the line couldn't be parsed.
177 line = line.strip()
178 if not line:
179 return None, None, line
180 elif line[0] == '?':
181 line = 'help ' + line[1:]
182 elif line[0] == '!':
184 line = 'shell ' + line[1:]
186 return None, None, line
187 i, n = 0, len(line)
188 while i < n and line[i] in self.identchars: i = i+1
189 cmd, arg = line[:i], line[i:].strip()
190 return cmd, arg, line
192 def onecmd(self, line): argument
202 cmd, arg, line = self.parseline(line)
203 if not line:
206 return self.default(line)
207 self.lastcmd = line
208 if line == 'EOF' :
211 return self.default(line)
216 return self.default(line)
220 """Called when an empty line is entered in response to the prompt.
223 command entered.
229 def default(self, line): argument
230 """Called on an input line when the command prefix is not recognized.
236 self.stdout.write('*** Unknown syntax: %s\n'%line)
239 """Method called to complete an input line when no command-specific
254 If a command has not been entered, then complete against command list.
255 Otherwise try to call complete_<command> to get list of completions.
260 line = origline.lstrip()
261 stripped = len(origline) - len(line)
262 begidx = readline.get_begidx() - stripped
263 endidx = readline.get_endidx() - stripped
265 cmd, args, foo = self.parseline(line)
275 self.completion_matches = compfunc(text, line, begidx, endidx)
343 self.columnize(cmds, maxcol-1)
367 ncols = (size+nrows-1) // nrows
369 totwidth = -2
397 while texts and not texts[-1]:
398 del texts[-1]