49
55
string setupAppName = "";
61
/// Creates a new instance
63
/// <param name="registry">
64
/// Add-in registry to manage.
54
66
public SetupTool (AddinRegistry registry)
56
68
this.registry = registry;
74
/// Display name of the host application
61
76
public string ApplicationName {
62
77
get { return applicationName; }
63
78
set { applicationName = value; }
82
/// Default add-in namespace of the application (optional). If set, only add-ins that belong to that namespace
83
/// will be shown in add-in lists.
66
85
public string ApplicationNamespace {
67
86
get { return service.ApplicationNamespace; }
68
87
set { service.ApplicationNamespace = value; }
91
/// Enables or disables verbose output
71
93
public bool VerboseOutput {
94
get { return verbose > 1; }
95
set { verbose = value ? 2 : 1; }
99
/// Sets or gets the verbose output level (0: normal output, 1:verbose, 2+:extra verbose)
101
public int VerboseOutputLevel {
72
102
get { return verbose; }
73
103
set { verbose = value; }
107
/// Runs the command line tool.
109
/// <param name="args">
110
/// Array that contains the command line arguments
112
/// <param name="firstArgumentIndex">
113
/// Index of the arguments array that has the first argument for the management tool
116
/// 0 if it succeeds. != 0 otherwise
76
118
public int Run (string[] args, int firstArgumentIndex)
78
120
string[] aa = new string [args.Length - firstArgumentIndex];
333
385
service.Repositories.RegisterRepository (new ConsoleProgressStatus (verbose), rep);
388
string GetRepositoryUrl (string url)
390
AddinRepository[] reps = GetRepositoryList ();
392
if (int.TryParse (url, out nr)) {
393
if (nr < 0 || nr >= reps.Length)
394
throw new InstallException ("Invalid repository number.");
397
if (!service.Repositories.ContainsRepository (url))
398
throw new InstallException ("Repository not registered.");
336
403
void RemoveRepository (string[] args)
338
foreach (string rep in args)
339
service.Repositories.RemoveRepository (rep);
405
foreach (string rep in args) {
406
service.Repositories.RemoveRepository (GetRepositoryUrl (rep));
410
void EnableRepository (string[] args)
412
foreach (string rep in args)
413
service.Repositories.SetRepositoryEnabled (GetRepositoryUrl(rep), true);
416
void DisableRepository (string[] args)
418
foreach (string rep in args)
419
service.Repositories.SetRepositoryEnabled (GetRepositoryUrl(rep), false);
422
AddinRepository[] GetRepositoryList ()
424
AddinRepository[] reps = service.Repositories.GetRepositories ();
425
Array.Sort (reps, (r1,r2) => r1.Title.CompareTo(r2.Title));
342
429
void ListRepositories (string[] args)
344
AddinRepository[] reps = service.Repositories.GetRepositories ();
431
AddinRepository[] reps = GetRepositoryList ();
345
432
if (reps.Length == 0) {
346
433
Console.WriteLine ("No repositories have been registered.");
349
437
Console.WriteLine ("Registered repositories:");
350
438
foreach (RepositoryRecord rep in reps) {
351
Console.WriteLine (" - " + rep.Title);
439
string num = n.ToString ();
440
Console.Write (num + ") ");
442
Console.Write ("(Disabled) ");
443
Console.WriteLine (rep.Title);
444
if (rep.Title != rep.Url)
445
Console.WriteLine (new string (' ', num.Length + 2) + rep.Url);
367
462
service.BuildPackage (new ConsoleProgressStatus (verbose), GetOption ("d", "."), GetArguments ());
465
void PrintLibraries (string[] args)
467
if (GetArguments ().Length < 1)
468
throw new InstallException ("An add-in id is required.");
470
bool refFormat = HasOption ("r");
472
System.Text.StringBuilder sb = new System.Text.StringBuilder ();
473
foreach (string id in GetArguments ()) {
474
Addin addin = service.Registry.GetAddin (id);
476
foreach (string asm in addin.Description.MainModule.Assemblies) {
477
string file = Path.Combine (addin.Description.BasePath, asm);
486
Console.WriteLine (sb);
489
void PrintApplications (string[] args)
491
foreach (Application app in SetupService.GetExtensibleApplications ()) {
492
string line = app.Name;
493
if (!string.IsNullOrEmpty (app.Description))
494
line += " - " + app.Description;
495
Console.WriteLine (line);
370
499
void UpdateRegistry (string[] args)
372
501
registry.Update (new ConsoleProgressStatus (verbose));
728
857
arguments = (string[]) list.ToArray (typeof(string));
861
/// Adds a custom command to the add-in manager
863
/// <param name="category">
864
/// Category under which the command has to be shown in the help text
866
/// <param name="command">
867
/// Name of the command
869
/// <param name="shortName">
870
/// Short name of the command (it's an alias of the normal name)
872
/// <param name="arguments">
873
/// Formal description of the arguments that the command accepts. For example: "[addin-id|addin-file] [--xml] [--all] [--full] [--namespace <namespace>]"
875
/// <param name="description">
876
/// Short description of the command
878
/// <param name="longDescription">
879
/// Long description of the command
881
/// <param name="handler">
882
/// Delegate to be invoked to run the command
731
884
public void AddCommand (string category, string command, string shortName, string arguments, string description, string longDescription, SetupCommandHandler handler)
733
886
SetupCommand cmd = new SetupCommand (category, command, shortName, handler);
912
/// Prints help about the add-in management tool, or about a specific command
914
/// <param name="parms">
915
/// Optional command name and arguments
758
917
public void PrintHelp (params string[] parms)
760
919
if (parms.Length == 0) {
761
920
string lastCat = null;
762
921
foreach (SetupCommand cmd in commands) {
922
if (cmd.Command == "help")
763
924
if (lastCat != cmd.Category) {
764
925
Console.WriteLine ();
765
926
Console.WriteLine (cmd.Category + ":");
783
944
Console.WriteLine ();
784
945
Console.WriteLine ("Usage: {0}{1}", setupAppName, cmd.Usage);
785
946
Console.WriteLine ();
786
Console.WriteLine (cmd.LongDescription);
948
TextFormatter fm = new TextFormatter ();
949
fm.Wrap = WrappingType.Word;
950
fm.Append (cmd.LongDescription);
951
Console.WriteLine (fm.ToString ());
789
954
Console.WriteLine ("Unknown command: " + parms [0]);
801
966
cmd.Usage = "[package-name|package-file] ...";
802
967
cmd.AppendDesc ("Installs an add-in or set of addins. The command argument is a list");
803
968
cmd.AppendDesc ("of files and/or package names. If a package name is provided");
804
cmd.AppendDesc ("the package will be looked out in the registered repositories.");
969
cmd.AppendDesc ("the package will be looked up in the registered repositories.");
805
970
cmd.AppendDesc ("A specific add-in version can be specified by appending it to.");
806
971
cmd.AppendDesc ("the package name using '/' as a separator, like in this example:");
807
972
cmd.AppendDesc ("MonoDevelop.SourceEditor/0.9.1");
856
1021
cmd = new SetupCommand (cat, "rep-remove", "rr", new SetupCommandHandler (RemoveRepository));
857
1022
cmd.Description = "Unregisters repositories.";
858
cmd.Usage = "<url> ...";
1023
cmd.Usage = "<url or number> ...";
859
1024
cmd.AppendDesc ("Unregisters an add-in repository. Several URLs can be provided.");
1025
cmd.AppendDesc ("Instead of an url, a repository number can be used (repository numbers are");
1026
cmd.AppendDesc ("shown by the rep-list command.");
1029
cmd = new SetupCommand (cat, "rep-enable", "re", new SetupCommandHandler (EnableRepository));
1030
cmd.Description = "Enables repositories.";
1031
cmd.Usage = "<url or number> ...";
1032
cmd.AppendDesc ("Enables an add-in repository which has been disabled. Several URLs can be");
1033
cmd.AppendDesc ("provided. Instead of an url, a repository number can be used (repository");
1034
cmd.AppendDesc ("numbers are shown by the rep-list command.");
1037
cmd = new SetupCommand (cat, "rep-disable", "rd", new SetupCommandHandler (DisableRepository));
1038
cmd.Description = "Disables repositories.";
1039
cmd.Usage = "<url> ...";
1040
cmd.AppendDesc ("Disables an add-in repository. Several URLs can be provided");
1041
cmd.AppendDesc ("When a repository is disabled, it will be ignored when using the update and");
1042
cmd.AppendDesc ("install commands.");
1043
cmd.AppendDesc ("Instead of an url, a repository number can be used (repository numbers are");
1044
cmd.AppendDesc ("shown by the rep-list command.");
860
1045
commands.Add (cmd);
862
1047
cmd = new SetupCommand (cat, "rep-update", "ru", new SetupCommandHandler (UpdateAvailableAddins));
883
1068
commands.Add (cmd);
885
1070
cmd = new SetupCommand (cat, "info", null, new SetupCommandHandler (PrintAddinInfo));
886
cmd.Description = "Prints information about an add-in.";
887
cmd.AppendDesc ("Prints information about an add-in.");
1071
cmd.Usage = "[addin-id|addin-file] [--xml] [--all] [--full] [--namespace <namespace>]";
1072
cmd.Description = "Prints information about add-ins.";
1073
cmd.AppendDesc ("Prints information about add-ins. Options:\n");
1074
cmd.AppendDesc (" --xml: Dump the information using an XML format.\n");
1075
cmd.AppendDesc (" --all: Dump information from all add-ins.\n");
1076
cmd.AppendDesc (" --full: Include add-ins which don't define extension points.\n");
1077
cmd.AppendDesc (" --namespace ns: Include only add-ins from the specified 'ns' namespace.");
888
1078
commands.Add (cmd);
890
1080
cat = "Packaging Commands";
911
1101
cmd.Usage = "<command>";
912
1102
commands.Add (cmd);
1104
cat = "Build Commands";
1106
cmd = new SetupCommand (cat, "libraries", "libs", new SetupCommandHandler (PrintLibraries));
1107
cmd.Description = "Lists add-in assemblies.";
1108
cmd.Usage = "[-r] <addin-id> ...";
1109
cmd.AppendDesc ("Prints a list of assemblies exported by the add-in or add-ins provided");
1110
cmd.AppendDesc ("as arguments. This list of assemblies can be used as references for");
1111
cmd.AppendDesc ("building add-ins that depend on them. If the -r option is specified,");
1112
cmd.AppendDesc ("each assembly is prefixed with '-r:'.");
1115
cmd = new SetupCommand (cat, "applications", "apps", new SetupCommandHandler (PrintApplications));
1116
cmd.Description = "Lists extensible applications.";
1117
cmd.AppendDesc ("Prints a list of registered extensible applications.");
914
1120
cat = "Debug Commands";
916
1122
cmd = new SetupCommand (cat, "dump-file", null, new SetupCommandHandler (DumpRegistryFile));