Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / MonoRail / NewGenerator / Castle.NewGenerator.CLI / Program.cs
blobbadf5e2554e3b3b04e2402b9ddf6d72b9be63548
1 namespace Castle.NewGenerator.CLI
3 using System;
4 using System.ComponentModel;
5 using System.Reflection;
6 using Castle.Components.Common.TemplateEngine;
7 using Castle.Components.Common.TemplateEngine.NVelocityTemplateEngine;
8 using Castle.NewGenerator.Core.MR;
9 using Core;
10 using Mono.GetOptions;
12 public class GeneratorDriver
14 static void Main(string[] args)
16 AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
18 MainOptions opts = new MainOptions();
19 opts.ProcessArgs(args);
21 if (args.Length == 0 || args[0].StartsWith("-"))
23 ShowUsage();
26 Console.WriteLine("Processing {0} {1}", args[0], opts.verbose);
28 IGenerator generator = null;
30 if (args[0] == "controller")
32 generator = new NewController();
34 else if (args[0] == "project")
36 generator = new NewProject();
38 else
40 Console.Error.WriteLine("Not supported");
41 return;
44 Configure(generator, args);
46 string workingDir = AppDomain.CurrentDomain.BaseDirectory;
47 string templateDir = @"C:\dev\DotNet\castle\svn\trunk\MonoRail\NewGenerator\GeneratorTemplates\";
49 GeneratorContext context = new GeneratorContext(workingDir, templateDir);
51 ITemplateEngine engine = new NVelocityTemplateEngine(templateDir);
53 if (engine is ISupportInitialize)
55 ((ISupportInitialize)engine).BeginInit();
58 generator.Generate(context, new DefaultGeneratorService(context, engine));
61 static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
63 // C:\dev\castle\svn\trunk\build\net-2.0\debug
64 return Assembly.LoadFile(@"C:\dev\DotNet\castle\svn\trunk\build\net-2.0\debug\" + args.Name);
67 private static void ShowUsage()
69 Console.WriteLine("CastleGen project|controller -property name=value");
72 private static void Configure(IGenerator generator, string[] args)
74 Type type = generator.GetType();
76 object[] attrs = type.GetCustomAttributes(typeof(GeneratorOptionsAttribute), false);
78 if (attrs.Length == 1)
80 GeneratorOptionsAttribute attr = (GeneratorOptionsAttribute) attrs[0];
82 Type configurerType = typeof(GeneratorConfigurer<>).MakeGenericType(type);
84 object configurer = Activator.CreateInstance(attr.OptionClass);
86 MethodInfo method = configurerType.GetMethod("Configure", BindingFlags.Instance | BindingFlags.Public);
88 method.Invoke(configurer, new object[] { generator, args });
92 public class MainOptions : Options
94 [Option(1, "Verbose", 'v')]
95 public bool verbose;