Moved data handling to a separate class.
[piranha.git] / PiranhaCLI.py
blob8dfefa75c12c95f19b2d042955b3ee6b9dc0a8c7
1 #!/usr/bin/env python
3 import os, sys, getopt, re
4 import Piranha
6 def main():
7 print "Piranha CLI"
8 try:
9 opts, args = getopt.gnu_getopt( sys.argv[1:], "v" )
10 except getopt.GetoptError:
11 sys.exit(2)
13 for ( opt, arg ) in opts:
14 if opt == "-v":
15 print "Pirhanna! Version " + Piranha.version()
16 sys.exit(0)
18 piranha = Piranha.Piranha()
20 more = True
21 while more:
22 try:
23 line = raw_input( "P> " )
24 except EOFError:
25 print "\nGoodbye."
26 more = False
27 continue
29 command = parse( line )
30 if command == None:
31 print "Unrecognized input."
32 continue
33 if command[0] == "quit":
34 more = False
35 continue
36 elif command[0] == "list":
37 print command
38 else:
39 print "Invalid command."
40 print command
42 def parse( line ):
43 parser = re.compile( "^([a-zA-Z]+)( [a-zA-Z0-9:]+)*" )
44 matches = parser.search( line )
45 command = []
47 if matches.lastindex == None:
48 return None
50 print matches
51 for i in range( 1, matches.lastindex+1 ):
52 command.append(matches.group(i))
54 return command
56 if __name__ == "__main__":
57 main()