Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SetupTool.cs « Mono.Addins.Setup « Mono.Addins.Setup - github.com/mono/mono-addins.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5f0caa8085db749781b8d071e06abec72205184d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
//
// mdsetup.cs
//
// Author:
//   Lluis Sanchez Gual
//
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//


using System;
using System.Xml;
using System.Collections;
using Mono.Addins;
using Mono.Addins.Setup.ProgressMonitoring;
using Mono.Addins.Setup;
using System.IO;
using Mono.Addins.Description;
using System.Linq;
using System.Collections.Generic;

namespace Mono.Addins.Setup
{
	/// <summary>
	/// A command line add-in manager.
	/// </summary>
	/// <remarks>
	/// This class can be used to provide an add-in management command line tool to applications.
	/// </remarks>
	public class SetupTool
	{
		Hashtable options = new Hashtable ();
		string[] arguments;
		string applicationName = "Mono";
		SetupService service;
		AddinRegistry registry;
		ArrayList commands = new ArrayList ();
		string setupAppName = "";
		int uniqueId = 0;
		
		int verbose = 1;
		
		/// <summary>
		/// Creates a new instance
		/// </summary>
		/// <param name="registry">
		/// Add-in registry to manage.
		/// </param>
		public SetupTool (AddinRegistry registry)
		{
			this.registry = registry;
			service = new SetupService (registry);
			CreateCommands ();
		}
		
		/// <summary>
		/// Display name of the host application
		/// </summary>
		public string ApplicationName {
			get { return applicationName; }
			set { applicationName = value; }
		}
		
		/// <summary>
		/// Default add-in namespace of the application (optional). If set, only add-ins that belong to that namespace
		/// will be shown in add-in lists.
		/// </summary>
		public string ApplicationNamespace {
			get { return service.ApplicationNamespace; }
			set { service.ApplicationNamespace = value; }
		}
		
		/// <summary>
		/// Enables or disables verbose output
		/// </summary>
		public bool VerboseOutput {
			get { return verbose > 1; }
			set { verbose = value ? 2 : 1; }
		}
		
		/// <summary>
		/// Sets or gets the verbose output level (0: normal output, 1:verbose, 2+:extra verbose)
		/// </summary>
		public int VerboseOutputLevel {
			get { return verbose; }
			set { verbose = value; }
		}

		/// <summary>
		/// Runs the command line tool.
		/// </summary>
		/// <param name="args">
		/// Array that contains the command line arguments
		/// </param>
		/// <param name="firstArgumentIndex">
		/// Index of the arguments array that has the first argument for the management tool
		/// </param>
		/// <returns>
		/// 0 if it succeeds. != 0 otherwise
		/// </returns>
		public int Run (string[] args, int firstArgumentIndex)
		{
			string[] aa = new string [args.Length - firstArgumentIndex];
			Array.Copy (args, firstArgumentIndex, aa, 0, aa.Length);
			return Run (aa);
		}
		
		/// <summary>
		/// Runs the command line tool.
		/// </summary>
		/// <param name="args">
		/// Command line arguments
		/// </param>
		/// <returns>
		/// 0 if it succeeds. != 0 otherwise
		/// </returns>
		public int Run (string[] args)
		{
			if (args.Length == 0) {
				PrintHelp ();
				return 0;
			}
			
			string[] parms = new string [args.Length - 1];
			Array.Copy (args, 1, parms, 0, args.Length - 1);
			
			try {
				ReadOptions (parms);
				if (HasOption ("v"))
					verbose++;
				return RunCommand (args [0], parms);
			} catch (InstallException ex) {
				Console.WriteLine (ex.Message);
				return -1;
			}
		}
		
		int RunCommand (string cmd, string[] parms)
		{
			SetupCommand cc = FindCommand (cmd);
			if (cc != null) {
				cc.Handler (parms);
				return 0;
			}
			else {
				Console.WriteLine ("Unknown command: " + cmd);
				return 1;
			}
		}
		
		void Install (string[] args)
		{
			bool prompt = !args.Any (a => a == "-y");
			var addins = args.Where (a => a != "-y");
			
			if (!addins.Any ()) {
				PrintHelp ("install");
				return;
			}
			
			PackageCollection packs = new PackageCollection ();
			foreach (string arg in addins) {
				if (File.Exists (arg)) { 
					packs.Add (AddinPackage.FromFile (arg));
				} else {
					string aname = Addin.GetIdName (GetFullId (arg));
					string aversion = Addin.GetIdVersion (arg);
					if (aversion.Length == 0) aversion = null;
					
					AddinRepositoryEntry[] ads = service.Repositories.GetAvailableAddin (aname, aversion);
					if (ads.Length == 0)
						throw new InstallException ("The addin '" + arg + "' is not available for install.");
					packs.Add (AddinPackage.FromRepository (ads[ads.Length-1]));
				}
			}
			Install (packs, prompt);
		}
		
		void CheckInstall (string[] args)
		{
			if (args.Length < 1) {
				PrintHelp ("check-install");
				return;
			}
			
			PackageCollection packs = new PackageCollection ();
			for (int n=0; n<args.Length; n++) {
				Addin addin = registry.GetAddin (GetFullId (args[n]));
				if (addin != null) {
					if (!addin.Enabled)
						addin.Enabled = true;
					continue;
				}
				string aname = Addin.GetIdName (GetFullId (args[n]));
				string aversion = Addin.GetIdVersion (args[n]);
				if (aversion.Length == 0) aversion = null;
				
				AddinRepositoryEntry[] ads = service.Repositories.GetAvailableAddin (aname, aversion);
				if (ads.Length == 0)
					throw new InstallException ("The addin '" + args[n] + "' is not available for install.");
				packs.Add (AddinPackage.FromRepository (ads[ads.Length-1]));
			}
			Install (packs, false);
		}
		
		void Install (PackageCollection packs, bool prompt)
		{
			PackageCollection toUninstall;
			DependencyCollection unresolved;
			
			IProgressStatus m = new ConsoleProgressStatus (verbose);
			int n = packs.Count;
			if (!service.Store.ResolveDependencies (m, packs, out toUninstall, out unresolved))
				throw new InstallException ("Not all dependencies could be resolved.");

			bool ask = false;
			if (prompt && (packs.Count != n || toUninstall.Count != 0)) {
				Console.WriteLine ("The following packages will be installed:");
				foreach (Package p in packs)
					Console.WriteLine (" - " + p.Name);
				ask = true;
			}
			if (prompt && (toUninstall.Count != 0)) {
				Console.WriteLine ("The following packages need to be uninstalled:");
				foreach (Package p in toUninstall)
					Console.WriteLine (" - " + p.Name);
				ask = true;
			}
			if (ask) {
				Console.WriteLine ();
				Console.Write ("Are you sure you want to continue? (y/N): ");
				string res = Console.ReadLine ();
				if (res != "y" && res != "Y")
					return;
			}
			
			if (!service.Store.Install (m, packs)) {
				Console.WriteLine ("Install operation failed.");
			}
		}
		
		void Uninstall (string[] args)
		{
			bool prompt = !args.Any (a => a == "-y");
			var addins = args.Where (a => a != "-y");
			
			if (!addins.Any ())
				throw new InstallException ("The add-in id is required.");
			if (addins.Count () > 1)
				throw new InstallException ("Only one add-in id can be provided.");
			
			string id = addins.First ();
			Addin ads = registry.GetAddin (GetFullId (id));
			if (ads == null)
				throw new InstallException ("The add-in '" + id + "' is not installed.");
			if (!ads.Description.CanUninstall)
				throw new InstallException ("The add-in '" + id + "' is protected and can't be uninstalled.");
			
			if (prompt) {
				Console.WriteLine ("The following add-ins will be uninstalled:");
				Console.WriteLine (" - " + ads.Description.Name);
				foreach (Addin si in service.GetDependentAddins (id, true))
					Console.WriteLine (" - " + si.Description.Name);
				
				Console.WriteLine ();
				Console.Write ("Are you sure you want to continue? (y/N): ");
				string res = Console.ReadLine ();
				if (res != "y" && res != "Y")
					return;
			}
			service.Uninstall (new ConsoleProgressStatus (verbose), ads.Id);
		}
		
		bool IsHidden (Addin ainfo)
		{
			return service.ApplicationNamespace != null && !(ainfo.Namespace + ".").StartsWith (service.ApplicationNamespace + ".") || ainfo.Description.IsHidden;
		}
		
		bool IsHidden (AddinHeader ainfo)
		{
			return service.ApplicationNamespace != null && !(ainfo.Namespace + ".").StartsWith (service.ApplicationNamespace + ".");
		}
		
		string GetId (AddinHeader ainfo)
		{
			if (service.ApplicationNamespace != null && (ainfo.Namespace + ".").StartsWith (service.ApplicationNamespace + "."))
				return ainfo.Id.Substring (service.ApplicationNamespace.Length + 1);
			else
				return ainfo.Id;
		}
		
		string GetFullId (string id)
		{
			if (service.ApplicationNamespace != null)
				return service.ApplicationNamespace + "." + id;
			else
				return id;
		}
		
		void ListInstalled (string[] args)
		{
			IList alist = args;
			bool showAll = alist.Contains ("-a");
			Console.WriteLine ("Installed add-ins:");
			ArrayList list = new ArrayList ();
			list.AddRange (registry.GetAddins ());
			if (alist.Contains ("-r"))
				list.AddRange (registry.GetAddinRoots ());
			foreach (Addin addin in list) {
				if (!showAll && IsHidden (addin))
					continue;
				Console.WriteLine("[{0}] {1} {2} {3}", addin.Enabled ? "Enabled" : "Disabled", addin.Id, addin.Name, showAll ? $"({addin.AddinFile})": string.Empty);
			}
		}
		
		void ListAvailable (string[] args)
		{
			bool showAll = args.Length > 0 && args [0] == "-a";
			Console.WriteLine ("Available add-ins:");
			AddinRepositoryEntry[] addins = service.Repositories.GetAvailableAddins ();
			foreach (PackageRepositoryEntry addin in addins) {
				if (!showAll && IsHidden (addin.Addin))
					continue;
				Console.WriteLine (" - " + GetId (addin.Addin) + " (" + addin.Repository.Name + ")");
			}
		}
		
		void ListUpdates (string[] args)
		{
			bool showAll = args.Length > 0 && args [0] == "-a";
			
			Console.WriteLine ("Looking for updates...");
			service.Repositories.UpdateAllRepositories (null);
			Console.WriteLine ("Available add-in updates:");
			AddinRepositoryEntry[] addins = service.Repositories.GetAvailableAddins ();
			bool found = false;
			foreach (PackageRepositoryEntry addin in addins) {
				Addin sinfo = registry.GetAddin (addin.Addin.LocalId);
				if (sinfo != null && !showAll && IsHidden(sinfo))
					continue;
				if (sinfo != null && Addin.CompareVersions (sinfo.Version, addin.Addin.Version) == 1) {
					Console.WriteLine (" - " + addin.Addin.Id + " " + addin.Addin.Version + " (" + addin.Repository.Name + ")");
					found = true;
				}
			}
			if (!found)
				Console.WriteLine ("No updates found.");
		}
		
		void Update (string [] args)
		{
			bool showAll = args.Length > 0 && args [0] == "-a";
			
			Console.WriteLine ("Looking for updates...");
			service.Repositories.UpdateAllRepositories (null);
			
			PackageCollection packs = new PackageCollection ();
			AddinRepositoryEntry[] addins = service.Repositories.GetAvailableAddins ();
			foreach (PackageRepositoryEntry addin in addins) {
				Addin sinfo = registry.GetAddin (addin.Addin.LocalId);
                if (sinfo != null && !showAll && IsHidden(sinfo))
					continue;
				if (sinfo != null && Addin.CompareVersions (sinfo.Version, addin.Addin.Version) == 1)
					packs.Add (AddinPackage.FromRepository (addin));
			}
			if (packs.Count > 0)
				Install (packs, true);
			else
				Console.WriteLine ("No updates found.");
		}
		
		void UpdateAvailableAddins (string[] args)
		{
			service.Repositories.UpdateAllRepositories (new ConsoleProgressStatus (verbose));
		}

		void EnableAddins (string[] args)
		{
			var addins = args.Where(a => a != "-y");
			foreach (string addinId in addins)
			{
				registry.EnableAddin (addinId);
			}
		}

		void DisableAddins(string[] args)
		{
			var addins = args.Where(a => a != "-y");
			foreach (string addinId in addins)
			{
				registry.DisableAddin(addinId);
			}
		}
		
		void AddRepository (string[] args)
		{
			foreach (string rep in args)
				service.Repositories.RegisterRepository (new ConsoleProgressStatus (verbose), rep);
		}
		
		string GetRepositoryUrl (string url)
		{
			AddinRepository[] reps = GetRepositoryList ();
			int nr;
			if (int.TryParse (url, out nr)) {
				if (nr < 0 || nr >= reps.Length)
					throw new InstallException ("Invalid repository number.");
				return reps[nr].Url;
			} else {
				if (!service.Repositories.ContainsRepository (url))
					throw new InstallException ("Repository not registered.");
				return url;
			}
		}
		
		void RemoveRepository (string[] args)
		{
			foreach (string rep in args) {
				service.Repositories.RemoveRepository (GetRepositoryUrl (rep));
			}
		}
		
		void EnableRepository (string[] args)
		{
			foreach (string rep in args)
				service.Repositories.SetRepositoryEnabled (GetRepositoryUrl(rep), true);
		}
		
		void DisableRepository (string[] args)
		{
			foreach (string rep in args)
				service.Repositories.SetRepositoryEnabled (GetRepositoryUrl(rep), false);
		}
		
		AddinRepository[] GetRepositoryList ()
		{
			AddinRepository[] reps = service.Repositories.GetRepositories ();
			Array.Sort (reps, (r1,r2) => r1.Title.CompareTo(r2.Title));
			return reps;
		}
		
		void ListRepositories (string[] args)
		{
			AddinRepository[] reps = GetRepositoryList ();
			if (reps.Length == 0) {
				Console.WriteLine ("No repositories have been registered.");
				return;
			}
			int n = 0;
			Console.WriteLine ("Registered repositories:");
			foreach (RepositoryRecord rep in reps) {
				string num = n.ToString ();
				Console.Write (num + ") ");
				if (!rep.Enabled)
					Console.Write ("(Disabled) ");
				Console.WriteLine (rep.Title);
				if (rep.Title != rep.Url)
					Console.WriteLine (new string (' ', num.Length + 2) + rep.Url);
				n++;
			}
		}
		
		void BuildRepository (string[] args)
		{
			if (args.Length < 1)
				throw new InstallException ("A directory name is required.");
			service.BuildRepository (new ConsoleProgressStatus (verbose), args[0]);
		}

		void BuildPackage (string [] args)
		{
			if (args.Length < 1)
				throw new InstallException ("A file name is required.");
			var formatString = GetOption ("format", "mpack");
			PackageFormat format;
			switch (formatString) {
			case "mpack":
				format = PackageFormat.Mpack;
				break;
			case "vsix":
				format = PackageFormat.Vsix;
				break;
			default:
				throw new ArgumentException ($"Unsupported package format \"{formatString}\", supported formats are mpack and vsix.");
			}
			service.BuildPackage (new ConsoleProgressStatus (verbose), bool.Parse (GetOption ("debugSymbols", "false")), GetOption ("d", "."), format, GetArguments ());
		}
		
		void PrintLibraries (string[] args)
		{
			if (GetArguments ().Length < 1)
				throw new InstallException ("An add-in id is required.");
			
			bool refFormat = HasOption ("r");
			
			System.Text.StringBuilder sb = new System.Text.StringBuilder ();
			foreach (string id in GetArguments ()) {
				Addin addin = service.Registry.GetAddin (id);
				if (addin != null) {
					foreach (string asm in addin.Description.MainModule.Assemblies) {
						string file = Path.Combine (addin.Description.BasePath, asm);
						if (sb.Length > 0)
							sb.Append (' ');
						if (refFormat)
							sb.Append ("-r:");
						sb.Append (file);
					}
				}
			}
			Console.WriteLine (sb);
		}
		
		void PrintApplications (string[] args)
		{
			foreach (Application app in SetupService.GetExtensibleApplications ()) {
				string line = app.Name;
				if (!string.IsNullOrEmpty (app.Description))
					line += " - " + app.Description;
				Console.WriteLine (line);
			}
		}
		
		void UpdateRegistry (string[] args)
		{
			registry.Update (new ConsoleProgressStatus (verbose));
		}
		
		void RepairRegistry (string[] args)
		{
			registry.Rebuild (new ConsoleProgressStatus (verbose));
		}
		
		void GenerateAddinScanDataFiles (string[] args)
		{
			bool recursive = false;
			int i = 0;
			if (args.Length > 0 && args [0] == "-r") {
				recursive = true;
				i = 1;
			}
			if (i >= args.Length)
				registry.GenerateAddinScanDataFiles (new ConsoleProgressStatus (verbose), recursive:recursive);
			else
				registry.GenerateAddinScanDataFiles (new ConsoleProgressStatus (verbose), args[0], recursive);
		}
		
		void DumpRegistryFile (string[] args)
		{
			if (args.Length < 1)
				throw new InstallException ("A file name is required.");
			registry.DumpFile (args[0]);
		}
		
		void PrintAddinInfo (string[] args)
		{
			bool generateXml = false;
			bool pickNamespace = false;
			bool extensionModel = true;
			
			ArrayList addins = new ArrayList ();
			ArrayList namespaces = new ArrayList ();

			bool generateAll = args [0] == "--all";
			if (!generateAll) {
				AddinDescription desc = null;
				if (File.Exists (args [0]))
					desc = registry.GetAddinDescription (new ConsoleProgressStatus (verbose), args [0]);
				else {
					Addin addin = registry.GetAddin (args [0]);
					if (addin != null)
						desc = addin.Description;
				}
				if (desc == null)
					throw new InstallException (string.Format ("Add-in '{0}' not found.", args [0]));
				if (desc != null)
					addins.Add (desc);
			}
			
			for (int i = 1; i < args.Length; i++) {
				string a = args [i];

				if (a == "--all")
					throw new InstallException (string.Format ("--all needs to be the first parameter"));

				if (pickNamespace) {
					namespaces.Add (a);
					pickNamespace = false;
					continue;
				}
				if (a == "--xml") {
					generateXml = true;
					continue;
				}
				if (a == "--namespace" || a == "-n") {
					pickNamespace = true;
					continue;
				}
				if (a == "--full") {
					extensionModel = false;
					continue;
				}
			}
			
			if (generateAll) {
				ArrayList list = new ArrayList ();
				list.AddRange (registry.GetAddinRoots ());
				list.AddRange (registry.GetAddins ());
				foreach (Addin addin in list) {
					if (namespaces.Count > 0) {
						foreach (string ns in namespaces) {
							if (addin.Id.StartsWith (ns + ".")) {
								addins.Add (addin.Description);
								break;
							}
						}
					} else {
						addins.Add (addin.Description);
					}
				}
			}
			
			if (addins.Count == 0)
				throw new InstallException ("A file name or add-in ID is required.");
			
			
			if (generateXml) {
				XmlTextWriter tw = new XmlTextWriter (Console.Out);
				tw.Formatting = Formatting.Indented;
				tw.WriteStartElement ("Addins");
				foreach (AddinDescription desc in addins) {
					if (extensionModel && desc.ExtensionPoints.Count == 0)
						continue;
					PrintAddinXml (tw, desc);
				}
				tw.Close ();
			}
			else {
				foreach (AddinDescription des in addins)
					PrintAddin (des);
			}
		}
		
		void PrintAddinXml (XmlWriter tw, AddinDescription desc)
		{
			tw.WriteStartElement ("Addin");
			tw.WriteAttributeString ("name", desc.Name);
			tw.WriteAttributeString ("addinId", desc.LocalId);
			tw.WriteAttributeString ("fullId", desc.AddinId);
			tw.WriteAttributeString ("id", "addin_" + uniqueId);
			uniqueId++;
			if (desc.Namespace.Length > 0)
				tw.WriteAttributeString ("namespace", desc.Namespace);
			tw.WriteAttributeString ("isroot", desc.IsRoot.ToString ());

			tw.WriteAttributeString ("version", desc.Version);
			if (desc.CompatVersion.Length > 0)
				tw.WriteAttributeString ("compatVersion", desc.CompatVersion);
			
			if (desc.Author.Length > 0)
				tw.WriteAttributeString ("author", desc.Author);
			if (desc.Category.Length > 0)
				tw.WriteAttributeString ("category", desc.Category);
			if (desc.Copyright.Length > 0)
				tw.WriteAttributeString ("copyright", desc.Copyright);
			if (desc.Url.Length > 0)
				tw.WriteAttributeString ("url", desc.Url);

			if (desc.Description.Length > 0)
				tw.WriteElementString ("Description", desc.Description);
			
			if (desc.ExtensionPoints.Count > 0) {
				ArrayList list = new ArrayList ();
				Hashtable visited = new Hashtable ();
				foreach (ExtensionPoint ep in desc.ExtensionPoints) {
					tw.WriteStartElement ("ExtensionPoint");
					tw.WriteAttributeString ("path", ep.Path);
					if (ep.Name.Length > 0)
						tw.WriteAttributeString ("name", ep.Name);
					else
						tw.WriteAttributeString ("name", ep.Path);
					if (ep.Description.Length > 0)
						tw.WriteElementString ("Description", ep.Description);
					PrintExtensionNodeSetXml (tw, desc, ep.NodeSet, list, visited);
					tw.WriteEndElement ();
				}
				
				for (int n=0; n<list.Count; n++) {
					
					ExtensionNodeType nt = (ExtensionNodeType) list [n];
					
					tw.WriteStartElement ("ExtensionNodeType");
					tw.WriteAttributeString ("name", nt.Id);
					tw.WriteAttributeString ("id", visited [nt.Id + " " + nt.TypeName].ToString ());
					
					if (nt.Description.Length > 0)
						tw.WriteElementString ("Description", nt.Description);
					
					if (nt.Attributes.Count > 0) {
						tw.WriteStartElement ("Attributes");
						foreach (NodeTypeAttribute att in nt.Attributes) {
							tw.WriteStartElement ("Attribute");
							tw.WriteAttributeString ("name", att.Name);
							tw.WriteAttributeString ("type", att.Type);
							tw.WriteAttributeString ("required", att.Required.ToString ());
							tw.WriteAttributeString ("localizable", att.Localizable.ToString ());
							if (att.Description.Length > 0)
								tw.WriteElementString ("Description", att.Description);
							tw.WriteEndElement ();
						}
						tw.WriteEndElement ();
					}
					
					if (nt.NodeTypes.Count > 0 || nt.NodeSets.Count > 0) {
						tw.WriteStartElement ("ChildNodes");
						PrintExtensionNodeSetXml (tw, desc, nt, list, visited);
						tw.WriteEndElement ();
					}
					tw.WriteEndElement ();
				}
			}
			tw.WriteEndElement ();
		}
		
		void PrintExtensionNodeSetXml (XmlWriter tw, AddinDescription desc, ExtensionNodeSet nset, ArrayList list, Hashtable visited)
		{
			foreach (ExtensionNodeType nt in nset.GetAllowedNodeTypes ()) {
				tw.WriteStartElement ("ExtensionNode");
				tw.WriteAttributeString ("name", nt.Id);
				string id = RegisterNodeXml (nt, list, visited);
				tw.WriteAttributeString ("id", id.ToString ());
				if (nt.Description.Length > 0)
					tw.WriteElementString ("Description", nt.Description);
				tw.WriteEndElement ();
			}
		}
		
		string RegisterNodeXml (ExtensionNodeType nt, ArrayList list, Hashtable visited)
		{
			string key = nt.Id + " " + nt.TypeName;
			if (visited.Contains (key))
				return (string) visited [key];
			string k = "ntype_" + uniqueId;
			uniqueId++;
			visited [key] = k;
			list.Add (nt);
			return k;
		}
		
		void PrintAddin (AddinDescription desc)
		{
			Console.WriteLine ();
			Console.WriteLine ("Addin Header");
			Console.WriteLine ("------------");
			Console.WriteLine ();
			Console.WriteLine ("Name:      " + desc.Name);
			Console.WriteLine ("Id:        " + desc.LocalId);
			if (desc.Namespace.Length > 0)
				Console.WriteLine ("Namespace: " + desc.Namespace);

			Console.Write ("Version:   " + desc.Version);
			if (desc.CompatVersion.Length > 0)
				Console.WriteLine (" (compatible with: " + desc.CompatVersion + ")");
			else
				Console.WriteLine ();
			
			if (desc.AddinFile.Length > 0)
				Console.WriteLine ("File:      " + desc.AddinFile);
			if (desc.Author.Length > 0)
				Console.WriteLine ("Author:    " + desc.Author);
			if (desc.Category.Length > 0)
				Console.WriteLine ("Category:  " + desc.Category);
			if (desc.Copyright.Length > 0)
				Console.WriteLine ("Copyright: " + desc.Copyright);
			if (desc.Url.Length > 0)
				Console.WriteLine ("Url:       " + desc.Url);

			if (desc.Description.Length > 0) {
				Console.WriteLine ();
				Console.WriteLine ("Description: \n" + desc.Description);
			}
			
			if (desc.ExtensionPoints.Count > 0) {
				Console.WriteLine ();
				Console.WriteLine ("Extenstion Points");
				Console.WriteLine ("-----------------");
				foreach (ExtensionPoint ep in desc.ExtensionPoints)
					PrintExtensionPoint (desc, ep);
			}
		}
		
		void PrintExtensionPoint (AddinDescription desc, ExtensionPoint ep)
		{
			Console.WriteLine ();
			Console.WriteLine ("* Extension Point: " + ep.Path);
			if (ep.Description.Length > 0)
				Console.WriteLine (ep.Description);
			
			var list = new List<ExtensionNodeType> ();
			Hashtable visited = new Hashtable ();
			
			Console.WriteLine ();
			Console.WriteLine ("  Extension nodes:");
			GetNodes (desc, ep.NodeSet, list, new Hashtable ());
			
			foreach (ExtensionNodeType nt in list)
				Console.WriteLine ("   - " + nt.Id + ": " + nt.Description);
			
			Console.WriteLine ();
			Console.WriteLine ("  Node description:");
			
			string sind = "    ";
			
			for (int n=0; n<list.Count; n++) {
				
				ExtensionNodeType nt = (ExtensionNodeType) list [n];
				if (visited.Contains (nt.Id + " " + nt.TypeName))
					continue;
				
				visited.Add (nt.Id + " " + nt.TypeName, nt);
				Console.WriteLine ();
				
				Console.WriteLine (sind + "- " + nt.Id + ": " + nt.Description);
				string nsind = sind + "    ";
				if (nt.Attributes.Count > 0) {
					Console.WriteLine (nsind + "Attributes:");
					foreach (NodeTypeAttribute att in nt.Attributes) {
						string req = att.Required ? " (required)" : "";
						Console.WriteLine (nsind + "  " + att.Name + " (" + att.Type + "): " + att.Description + req);
					}
				}
				
				if (nt.NodeTypes.Count > 0 || nt.NodeSets.Count > 0) {
					Console.WriteLine (nsind + "Child nodes:");
					var newList = new List<ExtensionNodeType> ();
					GetNodes (desc, nt, newList, new Hashtable ());
					list.AddRange (newList);
					foreach (ExtensionNodeType cnt in newList)
						Console.WriteLine ("          " + cnt.Id + ": " + cnt.Description);
				}
			}
			Console.WriteLine ();
		}
		
		void GetNodes (AddinDescription desc, ExtensionNodeSet nset, List<ExtensionNodeType> list, Hashtable visited)
		{
			if (visited.Contains (nset))
				return;
			visited.Add (nset, nset);

			foreach (ExtensionNodeType nt in nset.NodeTypes) {
				if (!visited.Contains (nt.Id + " " + nt.TypeName)) {
					list.Add (nt);
					visited.Add (nt.Id + " " + nt.TypeName, nt);
				}
			}
			
			foreach (string nsid in nset.NodeSets) {
				ExtensionNodeSet rset = desc.ExtensionNodeSets [nsid];
				if (rset != null)
					GetNodes (desc, rset, list, visited);
			}
		}
		
		string[] GetArguments ()
		{
			return arguments;
		}
		
		bool HasOption (string key)
		{
			return options.Contains (key);
		}
		
		string GetOption (string key, string defValue)
		{
			object val = options [key];
			if (val == null || val == (object) this)
				return defValue;
			else
				return (string) val;
		}
		
		void ReadOptions (string[] args)
		{
			options = new Hashtable ();
			ArrayList list = new ArrayList ();
			
			foreach (string arg in args) {
				if (arg.StartsWith ("-")) {
					int i = arg.IndexOf (':');
					if (i == -1)
						options [arg.Substring (1)] = this;
					else
						options [arg.Substring (1, i-1)] = arg.Substring (i+1);
				} else
					list.Add (arg);
			}
			
			arguments = (string[]) list.ToArray (typeof(string));
		}
		
		/// <summary>
		/// Adds a custom command to the add-in manager
		/// </summary>
		/// <param name="category">
		/// Category under which the command has to be shown in the help text
		/// </param>
		/// <param name="command">
		/// Name of the command
		/// </param>
		/// <param name="shortName">
		/// Short name of the command (it's an alias of the normal name)
		/// </param>
		/// <param name="arguments">
		/// Formal description of the arguments that the command accepts. For example: "[addin-id|addin-file] [--xml] [--all] [--full] [--namespace &lt;namespace&gt;]"
		/// </param>
		/// <param name="description">
		/// Short description of the command
		/// </param>
		/// <param name="longDescription">
		/// Long description of the command
		/// </param>
		/// <param name="handler">
		/// Delegate to be invoked to run the command
		/// </param>
		public void AddCommand (string category, string command, string shortName, string arguments, string description, string longDescription, SetupCommandHandler handler)
		{
			SetupCommand cmd = new SetupCommand (category, command, shortName, handler);
			cmd.Usage = arguments;
			cmd.Description = description;
			cmd.LongDescription = longDescription;
			
			int lastCatPos = -1;
			for (int n=0; n<commands.Count; n++) {
				SetupCommand ec = (SetupCommand) commands [n];
				if (ec.Category == category)
					lastCatPos = n;
			}
			if (lastCatPos == -1)
				commands.Add (cmd);
			else
				commands.Insert (lastCatPos+1, cmd);
		}
		
		SetupCommand FindCommand (string id)
		{
			foreach (SetupCommand cmd in commands)
				if (cmd.Command == id || cmd.ShortCommand == id)
					return cmd;
			return null;
		}

		/// <summary>
		/// Prints help about the add-in management tool, or about a specific command
		/// </summary>
		/// <param name="parms">
		/// Optional command name and arguments
		/// </param>
		public void PrintHelp (params string[] parms)
		{
			if (parms.Length == 0) {
				string lastCat = null;
				foreach (SetupCommand cmd in commands) {
					if (cmd.Command == "help")
						continue;
					if (lastCat != cmd.Category) {
						Console.WriteLine ();
						Console.WriteLine (cmd.Category + ":");
						lastCat = cmd.Category;
					}
					string cc = cmd.CommandDesc;
					if (cc.Length < 16)
						cc += new string (' ', 16 - cc.Length);
					Console.WriteLine ("  " + cc + " " + cmd.Description);
				}
				Console.WriteLine ();
				Console.WriteLine ("Run '" + setupAppName + "help <command>' to get help about a specific command.");
				Console.WriteLine ();
				return;
			}
			else {
				Console.WriteLine ();
				SetupCommand cmd = FindCommand (parms [0]);
				if (cmd != null) {
					Console.WriteLine ("{0}: {1}", cmd.CommandDesc, cmd.Description);
					Console.WriteLine ();
					Console.WriteLine ("Usage: {0}{1}", setupAppName, cmd.Usage);
					Console.WriteLine ();
					
					TextFormatter fm = new TextFormatter ();
					fm.Wrap = WrappingType.Word;
					fm.Append (cmd.LongDescription);
					Console.WriteLine (fm.ToString ());
				}
				else
					Console.WriteLine ("Unknown command: " + parms [0]);
				Console.WriteLine ();
			}
		}
			
		void CreateCommands ()
		{
			SetupCommand cmd;
			string cat = "Add-in commands";
			
			cmd = new SetupCommand (cat, "install", "i", new SetupCommandHandler (Install));
			cmd.Description = "Installs add-ins.";
			cmd.Usage = "[-y] [package-name|package-file] ...";
			cmd.AppendDesc ("Installs an add-in or set of addins. The command argument is a list");
			cmd.AppendDesc ("of files and/or package names. If a package name is provided");
			cmd.AppendDesc ("the package will be looked up in the registered repositories.");
			cmd.AppendDesc ("A specific add-in version can be specified by appending it to.");
			cmd.AppendDesc ("the package name using '/' as a separator, like in this example:");
			cmd.AppendDesc ("MonoDevelop.SourceEditor/0.9.1\n");
			cmd.AppendDesc ("-y: Don't ask for confirmation.");
			commands.Add (cmd);
			
			cmd = new SetupCommand (cat, "uninstall", "u", new SetupCommandHandler (Uninstall));
			cmd.Description = "Uninstalls add-ins.";
			cmd.Usage = "[-y] <package-name>";
			cmd.AppendDesc ("Uninstalls an add-in. The command argument is the name");
			cmd.AppendDesc ("of the add-in to uninstall.\n");
			cmd.AppendDesc ("-y: Don't ask for confirmation.");
			commands.Add (cmd);
			
			cmd = new SetupCommand (cat, "check-install", "ci", new SetupCommandHandler (CheckInstall));
			cmd.Description = "Checks installed add-ins.";
			cmd.Usage = "[package-name|package-file] ...";
			cmd.AppendDesc ("Checks if a package is installed. If it is not, it looks for");
			cmd.AppendDesc ("the package in the registered repositories, and if found");
			cmd.AppendDesc ("the package is downloaded and installed, including all");
			cmd.AppendDesc ("needed dependencies.");
			commands.Add (cmd);
			
			
			cmd = new SetupCommand (cat, "update", "up", new SetupCommandHandler (Update));
			cmd.Description = "Updates installed add-ins.";
			cmd.AppendDesc ("Downloads and installs available updates for installed add-ins.");
			commands.Add (cmd);
			
			cmd = new SetupCommand (cat, "list", "l", new SetupCommandHandler (ListInstalled));
			cmd.Description = "Lists installed add-ins.";
			cmd.AppendDesc ("Prints a list of all installed add-ins.");
			commands.Add (cmd);
					
			cmd = new SetupCommand (cat, "list-av", "la", new SetupCommandHandler (ListAvailable));
			cmd.Description = "Lists add-ins available in registered repositories.";
			cmd.AppendDesc ("Prints a list of add-ins available to install in the");
			cmd.AppendDesc ("registered repositories.");
			commands.Add (cmd);
					
			cmd = new SetupCommand (cat, "list-update", "lu", new SetupCommandHandler (ListUpdates));
			cmd.Description = "Lists available add-in updates.";
			cmd.AppendDesc ("Prints a list of available add-in updates in the registered repositories.");
			commands.Add (cmd);

			cmd = new SetupCommand(cat, "enable", "e", new SetupCommandHandler (EnableAddins));
			cmd.Description = "Enables addins.";
			cmd.Usage = "<id> ...";
			cmd.AppendDesc("Enables an add-in which has been disabled");
			commands.Add(cmd);

			cmd = new SetupCommand(cat, "disable", "d", new SetupCommandHandler(DisableAddins));
			cmd.Description = "Disables addins.";
			cmd.Usage = "<id> ...";
			cmd.AppendDesc("Disables an add-in which has been enabled");
			commands.Add(cmd);
			
			cat = "Repository Commands";

			cmd = new SetupCommand (cat, "rep-add", "ra", new SetupCommandHandler (AddRepository));
			cmd.Description = "Registers repositories.";
			cmd.Usage = "<url> ...";
			cmd.AppendDesc ("Registers an add-in repository. Several URLs can be provided.");
			commands.Add (cmd);

			cmd = new SetupCommand (cat, "rep-remove", "rr", new SetupCommandHandler (RemoveRepository));
			cmd.Description = "Unregisters repositories.";
			cmd.Usage = "<url or number> ...";
			cmd.AppendDesc ("Unregisters an add-in repository. Several URLs can be provided.");
			cmd.AppendDesc ("Instead of an url, a repository number can be used (repository numbers are");
			cmd.AppendDesc ("shown by the rep-list command.");
			commands.Add (cmd);

			cmd = new SetupCommand (cat, "rep-enable", "re", new SetupCommandHandler (EnableRepository));
			cmd.Description = "Enables repositories.";
			cmd.Usage = "<url or number> ...";
			cmd.AppendDesc ("Enables an add-in repository which has been disabled. Several URLs can be");
			cmd.AppendDesc ("provided. Instead of an url, a repository number can be used (repository");
			cmd.AppendDesc ("numbers are shown by the rep-list command.");
			commands.Add (cmd);

			cmd = new SetupCommand (cat, "rep-disable", "rd", new SetupCommandHandler (DisableRepository));
			cmd.Description = "Disables repositories.";
			cmd.Usage = "<url> ...";
			cmd.AppendDesc ("Disables an add-in repository. Several URLs can be provided");
			cmd.AppendDesc ("When a repository is disabled, it will be ignored when using the update and");
			cmd.AppendDesc ("install commands.");
			cmd.AppendDesc ("Instead of an url, a repository number can be used (repository numbers are");
			cmd.AppendDesc ("shown by the rep-list command.");
			commands.Add (cmd);

			cmd = new SetupCommand (cat, "rep-update", "ru", new SetupCommandHandler (UpdateAvailableAddins));
			cmd.Description = "Updates the lists of available addins.";
			cmd.AppendDesc ("Updates the lists of addins available in all registered repositories.");
			commands.Add (cmd);

			cmd = new SetupCommand (cat, "rep-list", "rl", new SetupCommandHandler (ListRepositories));
			cmd.Description = "Lists registered repositories.";
			cmd.AppendDesc ("Shows a list of all registered repositories.");
			commands.Add (cmd);

			cat = "Add-in Registry Commands";

			cmd = new SetupCommand (cat, "reg-update", "rgu", new SetupCommandHandler (UpdateRegistry));
			cmd.Description = "Updates the add-in registry.";
			cmd.AppendDesc ("Looks for changes in add-in directories and updates the registry.");
			cmd.AppendDesc ("New add-ins will be added and deleted add-ins will be removed.");
			commands.Add (cmd);

			cmd = new SetupCommand (cat, "reg-build", "rgb", new SetupCommandHandler (RepairRegistry));
			cmd.Description = "Rebuilds the add-in registry.";
			cmd.AppendDesc ("Regenerates the add-in registry.");
			commands.Add (cmd);

			cmd = new SetupCommand (cat, "reg-gen-data", "rgd", new SetupCommandHandler (GenerateAddinScanDataFiles));
			cmd.Usage = "[-r] <path>";
			cmd.Description = "Generates add-in scan data files.";
			cmd.AppendDesc ("Generates binary add-in scan data files next to each");
			cmd.AppendDesc ("add-in file. When such a file is present for an");
			cmd.AppendDesc ("add-in, the add-in scanner will load the information");
			cmd.AppendDesc ("from the data file instead of doing a full scan.");
			cmd.AppendDesc ("Data files will be generated only add-ins located");
			cmd.AppendDesc ("in the provided folder.");
			cmd.AppendDesc ("Options:");
			cmd.AppendDesc ("-r: Recursively look in subdirectories.");
			commands.Add (cmd);

			cmd = new SetupCommand (cat, "info", null, new SetupCommandHandler (PrintAddinInfo));
			cmd.Usage = "[addin-id|addin-file|--all] [--xml] [--full] [--namespace <namespace>]";
			cmd.Description = "Prints information about add-ins.";
			cmd.AppendDesc ("Prints information about add-ins. Options:\n");
			cmd.AppendDesc (" --xml: Dump the information using an XML format.\n");
			cmd.AppendDesc (" --full: Include add-ins which don't define extension points.\n");
			cmd.AppendDesc (" --namespace ns: Include only add-ins from the specified 'ns' namespace.");
			commands.Add (cmd);

			cat = "Packaging Commands";

			cmd = new SetupCommand (cat, "rep-build", "rb", new SetupCommandHandler (BuildRepository));
			cmd.Description = "Creates a repository index file for a directory structure.";
			cmd.Usage = "<path>";
			cmd.AppendDesc ("Scans the provided directory and generates a set of index files with entries");
			cmd.AppendDesc ("for all add-in packages found in the directory tree. The resulting file");
			cmd.AppendDesc ("structure is an add-in repository that can be published in a web site or a");
			cmd.AppendDesc ("shared directory.");
			commands.Add (cmd);
	
			cmd = new SetupCommand (cat, "pack", "p", new SetupCommandHandler (BuildPackage));
			cmd.Description = "Creates a package from an add-in configuration file.";
			cmd.Usage = "<file-path> [-d:output-directory] [-format:(mpack|vsix)] [-debugSymbols:(true|false)]";
			cmd.AppendDesc ("Creates an add-in package (.mpack or .vsix file) which includes all files ");
			cmd.AppendDesc ("needed to deploy an add-in. The command parameter is the path to");
			cmd.AppendDesc ("the add-in's configuration file. If 'debugSymbols' is set to true");
			cmd.AppendDesc ("then pdb or mdb debug symbols will automatically be included in the");
			cmd.AppendDesc ("final package.");
			commands.Add (cmd);
	
			cmd = new SetupCommand (cat, "help", "h", new SetupCommandHandler (PrintHelp));
			cmd.Description = "Shows help about a command.";
			cmd.Usage = "<command>";
			commands.Add (cmd);

			cat = "Build Commands";

			cmd = new SetupCommand (cat, "libraries", "libs", new SetupCommandHandler (PrintLibraries));
			cmd.Description = "Lists add-in assemblies.";
			cmd.Usage = "[-r] <addin-id> ...";
			cmd.AppendDesc ("Prints a list of assemblies exported by the add-in or add-ins provided");
			cmd.AppendDesc ("as arguments. This list of assemblies can be used as references for");
			cmd.AppendDesc ("building add-ins that depend on them. If the -r option is specified,");
			cmd.AppendDesc ("each assembly is prefixed with '-r:'.");
			commands.Add (cmd);

			cmd = new SetupCommand (cat, "applications", "apps", new SetupCommandHandler (PrintApplications));
			cmd.Description = "Lists extensible applications.";
			cmd.AppendDesc ("Prints a list of registered extensible applications.");
			commands.Add (cmd);
			
			cat = "Debug Commands";

			cmd = new SetupCommand (cat, "dump-file", null, new SetupCommandHandler (DumpRegistryFile));
			cmd.Description = "Prints the contents of a registry file.";
			cmd.Usage = "<file-path>";
			cmd.AppendDesc ("Prints the contents of a registry file for debugging.");
			commands.Add (cmd);
		}
	}
	
	class SetupCommand
	{
		string usage;
		
		public SetupCommand (string cat, string cmd, string shortCmd, SetupCommandHandler handler)
		{
			Category = cat;
			Command = cmd;
			ShortCommand = shortCmd;
			Handler = handler;
		}
		
		public void AppendDesc (string s)
		{
			LongDescription += s + " ";
		}
		
		public string Category;
		public string Command;
		public string ShortCommand;
		public SetupCommandHandler Handler; 
		
		public string Usage {
			get { return usage != null ? Command + " " + usage : Command; }
			set { usage = value; }
		}
			
		public string CommandDesc {
			get {
				if (ShortCommand != null && ShortCommand.Length > 0)
					return Command + " (" + ShortCommand + ")";
				else
					return Command;
			}
		}
		
		public string Description = "";
		public string LongDescription = "";
	}
	
	/// <summary>
	/// A command handler
	/// </summary>
	public delegate void SetupCommandHandler (string[] args);
}