22from jinja2 import Environment , FileSystemLoader
33import os
44import sys
5+ import argparse
56
6- print "Generate files new EbbRT application in the currect working \
7- directory."
8- var = raw_input ("Enter a name for the application \
9- (one word, no spaces):\n > " ).lower ()
7+ parser = argparse .ArgumentParser (description = 'Generate EbbRT application' ,
8+ prog = sys .argv [0 ], usage = '%(prog)s [options]' )
9+ parser .add_argument ('-n' , metavar = "NAME" , default = "app" , help = 'new application name' )
10+ parser .add_argument ('-t' , default = "default" , choices = ['default' , 'native' ], help = 'application template' )
11+ args = parser .parse_args ()
1012
11- # Capture our current directory
12- THIS_DIR = os .path .dirname (os .path .abspath (__file__ ))
13- CONTEXT = { "title" : var , "CAP_TITLE" : var .upper () }
14- target_path = os .path .join (os .getcwd (), var )
15- source_path = os .path .join (THIS_DIR , "template/helloworld" )
13+ template = args .t
14+ appname = args .n
15+
16+ # Capture the script (source) directory
17+ source_path = os .path .join (os .path .dirname (os .path .abspath (__file__ )), "template/" + template )
18+ target_path = os .getcwd ()
19+ CONTEXT = { "title" : appname , "CAP_TITLE" : appname .upper () }
1620
1721def apply_template (source , target ):
1822 if not os .path .exists (target ):
1923 os .makedirs (target )
20- else :
21- print "Error, target directory already exists: " + target
22- sys .exit ()
2324 print "Building new application: " + target
2425 #print "Using template: "+source
2526 for path ,sd ,files in os .walk (source ):
@@ -34,7 +35,7 @@ def apply_template(source, target):
3435 relative_path = os .path .join (relative_root , name )
3536 full_source_path = os .path .join (path , name )
3637 if name == "title.cc" :
37- full_target_path = os .path .join (target_root , var + ".cc" )
38+ full_target_path = os .path .join (target_root , appname + ".cc" )
3839 else :
3940 full_target_path = os .path .join (target_root , name )
4041 print "writing " + full_target_path
@@ -49,4 +50,4 @@ def render_template(fs, filename, context):
4950
5051if __name__ == '__main__' :
5152 apply_template (source_path , target_path )
52- print "Build finished. "
53+ print "New EbbRT application (" + appname + ") generated in current working directory "
0 commit comments