1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Generator
18 using System
.Reflection
;
19 using System
.Collections
;
20 using System
.Collections
.Specialized
;
22 using Castle
.MonoRail
.Generator
.Generators
;
28 public abstract class App
30 public static void Main()
32 IGenerator
[] generators
= CreateGenerators();
36 String
[] args
= Environment
.GetCommandLineArgs();
45 IDictionary dic
= BuildDictionary(args
);
46 // bool found = false;
48 foreach(IGenerator generator
in generators
)
50 if (generator
.Accept(args
[1], dic
, Console
.Out
))
53 generator
.Execute(dic
, Console
.Out
);
60 // Console.Out.WriteLine("No generator found for '{0}'", args[1]);
65 private static IDictionary
BuildDictionary(String
[] args
)
67 HybridDictionary dic
= new HybridDictionary(true);
69 for(int i
=1; i
< args
.Length
; i
++)
72 String
value = String
.Empty
;
74 int index
= key
.IndexOf(':');
78 key
= args
[i
].Substring(0, index
);
79 value = args
[i
].Substring(index
+1);
80 value = NormalizeValue(value);
89 private static void ShowUsage()
91 Console
.WriteLine("Usage: generator action options");
92 Console
.WriteLine("");
93 Console
.WriteLine("Actions:");
94 Console
.WriteLine(" project");
95 Console
.WriteLine(" controller");
96 Console
.WriteLine("");
97 Console
.WriteLine("Try 'generator action' for more information about the action");
100 private static void ShowHeader()
102 Console
.WriteLine("MonoRail Generator - " + Assembly
.GetExecutingAssembly().GetName().Version
.ToString() );
103 Console
.WriteLine("Released under Apache Software License 2.0");
104 Console
.WriteLine("Copyright (c) 2004-2008 the original author/authors");
105 Console
.WriteLine("http://www.castleproject.org/");
106 Console
.WriteLine("");
107 Console
.WriteLine("");
110 private static IGenerator
[] CreateGenerators()
112 return new IGenerator
[] { new ProjectGenerator(), new ControllerGenerator() }
;
115 private static string NormalizeValue(string value)
117 // TODO: remove quotes if present