1 // NAnt - A .NET build tool
2 // Copyright (C) 2001 Gerry Shaw
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // Gerry Shaw (gerry_shaw@yahoo.com)
20 namespace SourceForge
.NAnt
{
23 using System
.Diagnostics
;
25 using System
.Text
.RegularExpressions
;
28 public static int Main(string[] args
) {
33 Project project
= new Project();
35 const string buildfileOption
= "-buildfile:";
36 const string basedirOption
= "-basedir:";
37 const string setOption
= "-set:";
38 const string helpOption
= "-h"; // allow -h and -help
39 const string verboseOption
= "-verbose";
41 bool showHelp
= false;
43 foreach (string arg
in args
) {
44 if (arg
.StartsWith(buildfileOption
)) {
45 project
.BuildFileName
= arg
.Substring(buildfileOption
.Length
);
46 } else if (arg
.StartsWith(basedirOption
)) {
47 project
.BaseDirectory
= arg
.Substring(basedirOption
.Length
);
48 } else if (arg
.StartsWith(basedirOption
)) {
49 project
.BaseDirectory
= arg
.Substring(basedirOption
.Length
);
50 } else if (arg
.StartsWith(setOption
)) {
51 // TODO: implement user defined properties
52 // user defined properties from command line or file should be
53 // marked so that they cannot be overwritten by the build file
54 // ie, once set they are set for the rest of the build.
55 Match match
= Regex
.Match(arg
, @"-set:(\w+)=(\w*)");
57 string name
= match
.Groups
[1].Value
;
58 string value = match
.Groups
[2].Value
;
59 project
.Properties
.AddReadOnly(name
, value);
61 } else if (arg
.StartsWith(helpOption
)) {
63 } else if (arg
.StartsWith(verboseOption
)) {
64 project
.Verbose
= true;
65 } else if (arg
.Length
> 0) {
66 // must be a target (or mistake ;)
67 project
.BuildTargets
.Add(arg
);
71 // Get version information directly from assembly. This takes more
72 // work but prevents the version numbers from getting out of sync.
73 ProcessModule module
= Process
.GetCurrentProcess().MainModule
;
74 FileVersionInfo info
= FileVersionInfo
.GetVersionInfo(module
.FileName
);
75 string programName
= Path
.GetFileNameWithoutExtension(info
.FileName
); // in case the user has renamed the program
78 const int optionPadding
= 23;
80 Console
.WriteLine("NAnt Version {0} Copyright (C) 2001 Gerry Shaw", info
.FileMajorPart
+ "." + info
.FileMinorPart
+ "." + info
.FileBuildPart
);
81 Console
.WriteLine("http://nant.sourceforge.net/");
83 Console
.WriteLine("NAnt comes with ABSOLUTELY NO WARRANTY.");
84 Console
.WriteLine("This is free software, and you are welcome to redistribute it under certain");
85 Console
.WriteLine("conditions set out by the GNU General Public License. A copy of the license");
86 Console
.WriteLine("is available in the distribution package and from the NAnt web site.");
88 Console
.WriteLine("usage: {0} [options] [target]", programName
);
90 Console
.WriteLine("options:");
91 Console
.WriteLine(" {0} use given buildfile", (buildfileOption
+ "<file>").PadRight(optionPadding
));
92 Console
.WriteLine(" {0} set project base directory", (basedirOption
+ "<dir>").PadRight(optionPadding
));
93 Console
.WriteLine(" {0} use value for given property", (setOption
+ "<property>=<value>").PadRight(optionPadding
));
94 Console
.WriteLine(" {0} print this message", helpOption
.PadRight(optionPadding
));
96 Console
.WriteLine("If no buildfile is specified the first file ending in .build will be used.");
99 Console
.WriteLine("Try `{0} -help' for more information.", programName
);
100 returnCode
= 1; // set return code to indicate an error occurred