Browse Source

Switch to --newinstance

pull/3205/head
Christoph Wille 1 year ago
parent
commit
d0c443cae1
  1. 13
      ILSpy.Tests/CommandLineArgumentsTests.cs
  2. 31
      ILSpy/CommandLineArguments.cs
  3. 71
      doc/Command Line.txt

13
ILSpy.Tests/CommandLineArgumentsTests.cs

@ -22,19 +22,12 @@ namespace ICSharpCode.ILSpy.Tests
} }
[Test] [Test]
public void VerifySeparateOption() public void VerifyForceNewInstanceOption()
{ {
var cmdLineArgs = new CommandLineArguments(new string[] { "--instancing", "Multi" }); var cmdLineArgs = new CommandLineArguments(new string[] { "--newinstance" });
cmdLineArgs.SingleInstance.Should().BeFalse(); cmdLineArgs.SingleInstance.Should().BeFalse();
} }
[Test]
public void VerifySingleInstanceOption()
{
var cmdLineArgs = new CommandLineArguments(new string[] { "--instancing", "Single" });
cmdLineArgs.SingleInstance.Should().BeTrue();
}
[Test] [Test]
public void VerifyNavigateToOption() public void VerifyNavigateToOption()
{ {
@ -86,7 +79,7 @@ namespace ICSharpCode.ILSpy.Tests
{ {
string filepath = System.IO.Path.GetTempFileName(); string filepath = System.IO.Path.GetTempFileName();
System.IO.File.WriteAllText(filepath, "assembly1 assembly2 assembly3 --instancing multi --noactivate"); System.IO.File.WriteAllText(filepath, "assembly1 assembly2 assembly3 --newinstance --noactivate");
var cmdLineArgs = new CommandLineArguments(new string[] { $"@{filepath}" }); var cmdLineArgs = new CommandLineArguments(new string[] { $"@{filepath}" });

31
ILSpy/CommandLineArguments.cs

@ -18,18 +18,11 @@
using McMaster.Extensions.CommandLineUtils; using McMaster.Extensions.CommandLineUtils;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace ICSharpCode.ILSpy namespace ICSharpCode.ILSpy
{ {
internal enum InstancingMode
{
Single,
Multi
}
sealed class CommandLineArguments sealed class CommandLineArguments
{ {
// see /doc/Command Line.txt for details // see /doc/Command Line.txt for details
@ -44,12 +37,13 @@ namespace ICSharpCode.ILSpy
public CommandLineArguments(IEnumerable<string> arguments) public CommandLineArguments(IEnumerable<string> arguments)
{ {
var app = new CommandLineApplication() { var app = new CommandLineApplication() {
// https://natemcmaster.github.io/CommandLineUtils/docs/response-file-parsing.html?tabs=using-attributes
ResponseFileHandling = ResponseFileHandling.ParseArgsAsSpaceSeparated, ResponseFileHandling = ResponseFileHandling.ParseArgsAsSpaceSeparated,
}; };
var oInstancing = app.Option("-i|--instancing <single/multi>", var oForceNewInstance = app.Option("--newinstance",
"Single or multi instance", "Start a new instance of ILSpy even if the user configuration is set to single-instance",
CommandOptionType.SingleValue); CommandOptionType.NoValue);
var oNavigateTo = app.Option<string>("-n|--navigateto <TYPENAME>", var oNavigateTo = app.Option<string>("-n|--navigateto <TYPENAME>",
"Navigates to the member specified by the given ID string.\r\nThe member is searched for only in the assemblies specified on the command line.\r\nExample: 'ILSpy ILSpy.exe --navigateTo:T:ICSharpCode.ILSpy.CommandLineArguments'", "Navigates to the member specified by the given ID string.\r\nThe member is searched for only in the assemblies specified on the command line.\r\nExample: 'ILSpy ILSpy.exe --navigateTo:T:ICSharpCode.ILSpy.CommandLineArguments'",
@ -79,26 +73,11 @@ namespace ICSharpCode.ILSpy
// To enable this, MultipleValues must be set to true, and the argument must be the last one specified. // To enable this, MultipleValues must be set to true, and the argument must be the last one specified.
var files = app.Argument("Assemblies", "Assemblies to load", multipleValues: true); var files = app.Argument("Assemblies", "Assemblies to load", multipleValues: true);
// string helptext = app.GetHelpText(); // string helptext = app.GetHelpText();
app.Parse(arguments.ToArray()); app.Parse(arguments.ToArray());
if (oInstancing.Value != null) if (oForceNewInstance.HasValue())
{
if (Enum.TryParse<InstancingMode>(oInstancing.Value(), true, out var mode))
{
switch (mode)
{
case InstancingMode.Single:
SingleInstance = true;
break;
case InstancingMode.Multi:
SingleInstance = false; SingleInstance = false;
break;
}
}
}
NavigateTo = oNavigateTo.ParsedValue; NavigateTo = oNavigateTo.ParsedValue;
Search = oSearch.ParsedValue; Search = oSearch.ParsedValue;

71
doc/Command Line.txt

@ -1,54 +1,27 @@
ILSpy Command Line Arguments ILSpy Command Line Arguments
Command line arguments can be either options or file names. Usage: <Assemblies> [options]
If an argument is a file name, the file will be opened as assembly and added to the current assembly list. @ResponseFile.rsp
Available options: Arguments:
/singleInstance If ILSpy is already running, activates the existing instance Assemblies Assemblies to load
and passes command line arguments to that instance.
This is the default value if /list is not used.
/separate Start up a separate ILSpy instance even if it is already running. Options:
--newinstance Start a new instance of ILSpy even if the user configuration is set to single-instance
/noActivate Do not activate the existing ILSpy instance. This option has no effect -n|--navigateto <TYPENAME> Navigates to the member specified by the given ID string.
if a new ILSpy instance is being started.
/list:listname Specifies the name of the assembly list that is loaded initially.
When this option is not specified, ILSpy loads the previously opened list.
Specify "/list" (without value) to open the default list.
When this option is used, ILSpy will activate an existing instance
only if it uses the same list as specified.
[Note: Assembly Lists are not yet implemented]
/clearList Clears the assembly list before loading the specified assemblies.
[Note: Assembly Lists are not yet implemented]
/navigateTo:tag Navigates to the member specified by the given ID string.
The member is searched for only in the assemblies specified on the command line. The member is searched for only in the assemblies specified on the command line.
Example: 'ILSpy ILSpy.exe /navigateTo:T:ICSharpCode.ILSpy.CommandLineArguments' Example: 'ILSpy ILSpy.exe --navigateTo:T:ICSharpCode.ILSpy.CommandLineArguments'
-s|--search <SEARCHTERM> Search for t:TypeName, m:Member or c:Constant; use exact match (=term),
The syntax of ID strings is described in appendix A of the C# language specification. 'should not contain' (-term) or 'must contain' (+term); use
/reg(ular)?Ex(pressions)?/ or both - t:/Type(Name)?/...
/language:name Selects the specified language. -l|--language <LANGUAGEIDENTIFIER> Selects the specified language.
Example: 'ILSpy /language:C#' or 'ILSpy /language:IL' Example: 'ILSpy --language:C#' or 'ILSpy --language:IL'
-c|--config <CONFIGFILENAME> Provide a specific configuration file.
WM_COPYDATA (SendMessage API): Example: 'ILSpy --config:myconfig.xml'
ILSpy can be controlled by other programs that send a WM_COPYDATA message to its main window. --noactivate Do not activate the existing ILSpy instance.
The message data must be an Unicode (UTF-16) string starting with "ILSpy:\r\n". This option has no effect if a new ILSpy instance is being started.
All lines except the first ("ILSpy:") in that string are handled as command-line arguments.
There must be exactly one argument per line. Note on @ResponseFile.rsp:
That is, by sending this message: * The response file should contain the arguments as if they were passed on the command line (space-separated).
ILSpy: * Use it when the list of assemblies is too long to fit on the command line.
C:\Assembly.dll
/navigateTo:T:Type
The target ILSpy instance will open C:\Assembly.dll and navigate to the specified type.
ILSpy will return TRUE (1) if it handles the message, and FALSE (0) otherwise.
The /separate option will be ignored; WM_COPYDATA will never start up a new instance.
The /noActivate option has no effect, sending WM_COPYDATA will never activate the window.
Instead, the calling process should use SetForegroundWindow().
If you use /list with WM_COPYDATA, you need to specify /singleInstance as well, otherwise
ILSpy will not handle the message if it has opened a different assembly list.
Loading…
Cancel
Save