这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 32 additions & 25 deletions MLS.Agent/CommandLine/CommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ public static Parser Create(
services = services ??
new ServiceCollection();

var dirArgument = new Argument<DirectoryInfo>
{
Arity = ArgumentArity.ZeroOrOne,
Name = nameof(StartupOptions.Dir).ToLower(),
Description = "Specify the path to the root directory for your documentation"
}.ExistingOnly();

var rootCommand = StartInTryMode();

rootCommand.AddCommand(StartInHostedMode());
Expand All @@ -121,19 +128,16 @@ public static Parser Create(
})
.Build();


RootCommand StartInTryMode()
{
var command = new RootCommand
{
Name = "dotnet-try",
Description = ".NET interactive documentation in your browser",
Argument = new Argument<DirectoryInfo>
{
Arity = ArgumentArity.ZeroOrOne,
Name = nameof(StartupOptions.Dir).ToLower(),
Description = "Specify the path to the root directory for your documentation"
}.ExistingOnly()
Description = "Interactive documentation in your browser"
};

command.AddArgument(dirArgument);

command.AddOption(new Option(
"--add-package-source",
Expand Down Expand Up @@ -184,11 +188,11 @@ RootCommand StartInTryMode()

var portArgument = new Argument<ushort>();

portArgument.AddValidator(symbolResult =>{
if(symbolResult.Tokens
.Select(t => t.Value)
.Where(value => !ushort.TryParse(value, out ushort result)).Count() >0)
portArgument.AddValidator(symbolResult =>
{
if (symbolResult.Tokens
.Select(t => t.Value)
.Count(value => !ushort.TryParse(value, out _)) > 0)
{
return "Invalid argument for --port option";
}
Expand Down Expand Up @@ -301,13 +305,15 @@ Command GitHub()

Command Jupyter()
{
var jupyterCommand = new Command("jupyter", "Starts dotnet try as a Jupyter kernel");
jupyterCommand.IsHidden = true;
var jupyterCommand = new Command("jupyter", "Starts dotnet try as a Jupyter kernel")
{
IsHidden = true
};
var connectionFileArgument = new Argument<FileInfo>
{
Name = "ConnectionFile"
}.ExistingOnly();
jupyterCommand.Argument = connectionFileArgument;
jupyterCommand.AddArgument(connectionFileArgument);

jupyterCommand.Handler = CommandHandler.Create<JupyterOptions, IConsole, InvocationContext>((options, console, context) =>
{
Expand Down Expand Up @@ -335,8 +341,10 @@ Command Pack()
{
var packCommand = new Command("pack", "Create a Try .NET package");
packCommand.IsHidden = true;
packCommand.Argument = new Argument<DirectoryInfo>();
packCommand.Argument.Name = nameof(PackOptions.PackTarget);
packCommand.AddArgument(new Argument<DirectoryInfo>
{
Name = nameof(PackOptions.PackTarget)
});

packCommand.AddOption(new Option("--version",
"The version of the Try .NET package",
Expand All @@ -356,8 +364,10 @@ Command Pack()
Command Install()
{
var installCommand = new Command("install", "Install a Try .NET package");
installCommand.Argument = new Argument<string>();
installCommand.Argument.Name = nameof(InstallOptions.PackageName);
installCommand.AddArgument(new Argument<string>
{
Name = nameof(InstallOptions.PackageName)
});
installCommand.IsHidden = true;

var option = new Option("--add-source",
Expand All @@ -374,14 +384,11 @@ Command Verify()
{
var verifyCommand = new Command("verify", "Verify Markdown files in the target directory and its children.")
{
Argument = new Argument<DirectoryInfo>(() => new DirectoryInfo(Directory.GetCurrentDirectory()))
{
Name = nameof(VerifyOptions.Dir).ToLower(),
Description = "Specify the path to the root directory"
}.ExistingOnly()
dirArgument
};

verifyCommand.Handler = CommandHandler.Create<VerifyOptions, IConsole, StartupOptions>((options, console, startupOptions) =>
verifyCommand.Handler = CommandHandler.Create<VerifyOptions, IConsole, StartupOptions>(
(options, console, startupOptions) =>
{
return verify(options, console, startupOptions);
});
Expand Down
22 changes: 4 additions & 18 deletions MLS.Agent/MLS.Agent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="system.commandline.experimental" Version="0.2.0-alpha.19261.1" />
<PackageReference Include="system.commandline.experimental" Version="0.3.0-alpha.19312.1" />
<PackageReference Include="System.Reactive" Version="4.1.3" />
<PackageReference Include="TaskExtensions" Version="0.1.8580001">
<PrivateAssets>all</PrivateAssets>
Expand Down Expand Up @@ -126,11 +126,7 @@
</EmbeddedResource>
</ItemGroup>

<Target Name="BuildCss"
Inputs="$(MSBuildThisFileDirectory)..\Microsoft.DotNet.Try.Styles\sass\trydotnet.scss"
Outputs="$(MSBuildThisFileDirectory)wwwroot\css\trydotnet.css"
BeforeTargets="BeforeBuild"
Condition="'$(NCrunch)' != '1'">
<Target Name="BuildCss" Inputs="$(MSBuildThisFileDirectory)..\Microsoft.DotNet.Try.Styles\sass\trydotnet.scss" Outputs="$(MSBuildThisFileDirectory)wwwroot\css\trydotnet.css" BeforeTargets="BeforeBuild" Condition="'$(NCrunch)' != '1'">

<PropertyGroup>
<_TryDotNetCssExists Condition="Exists('$(MSBuildThisFileDirectory)wwwroot\css\trydotnet.css')">true</_TryDotNetCssExists>
Expand Down Expand Up @@ -164,12 +160,7 @@
</ItemGroup>
</Target>

<Target Name="BuildTryDotNetJs"
Inputs="@(TryDotNetJsInput)"
Outputs="$(TryDotNetJsFile);$(TryDotNetJsMap)"
DependsOnTargets="GatherInputs"
BeforeTargets="BeforeBuild"
Condition="'$(NCrunch)' != '1'">
<Target Name="BuildTryDotNetJs" Inputs="@(TryDotNetJsInput)" Outputs="$(TryDotNetJsFile);$(TryDotNetJsMap)" DependsOnTargets="GatherInputs" BeforeTargets="BeforeBuild" Condition="'$(NCrunch)' != '1'">
<PropertyGroup>
<_TryDotNetMinJsExists Condition="Exists('$(TryDotNetJsFile)')">true</_TryDotNetMinJsExists>
</PropertyGroup>
Expand All @@ -187,12 +178,7 @@
</ItemGroup>
</Target>

<Target Name="BuildClient"
Inputs="@(ClientInputFiles)"
Outputs="$(ClientOutputFile)"
DependsOnTargets="GatherInputs"
BeforeTargets="BeforeBuild"
Condition="'$(NCrunch)' != '1'">
<Target Name="BuildClient" Inputs="@(ClientInputFiles)" Outputs="$(ClientOutputFile)" DependsOnTargets="GatherInputs" BeforeTargets="BeforeBuild" Condition="'$(NCrunch)' != '1'">

<PropertyGroup>
<_TryDotNetClientExists Condition="Exists('$(ClientOutputFile)')">true</_TryDotNetClientExists>
Expand Down
58 changes: 33 additions & 25 deletions MLS.Agent/Markdown/LocalCodeFenceAnnotationsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,25 @@ protected override ModelBinder CreateModelBinder()
private static void AddSourceFileOption(Command command)
{
var sourceFileArg = new Argument<RelativeFilePath>(
result =>
{
var filename = result.Tokens.Select(t => t.Value).SingleOrDefault();

if (filename == null)
{
return ArgumentResult.Success(null);
}

if (RelativeFilePath.TryParse(filename, out var relativeFilePath))
{
return ArgumentResult.Success(relativeFilePath);
}

return ArgumentResult.Failure($"Error parsing the filename: {filename}");
})
(SymbolResult result, out RelativeFilePath relativeFilePath) =>
{
var filename = result.Tokens.Select(t => t.Value).SingleOrDefault();

if (filename == null)
{
relativeFilePath = null;
return true;
}

if (RelativeFilePath.TryParse(filename, out relativeFilePath))
{
return true;
}

result.ErrorMessage = $"Error parsing the filename: {filename}";

return false;
})
{
Name = "SourceFile",
Arity = ArgumentArity.ZeroOrOne
Expand Down Expand Up @@ -112,17 +115,22 @@ private static void AddProjectOption(
IDirectoryAccessor directoryAccessor,
string projectFileExtension)
{
var projectOptionArgument = new Argument<FileInfo>(result =>
{
var projectPath = new RelativeFilePath(result.Tokens.Select(t => t.Value).Single());

if (directoryAccessor.FileExists(projectPath))
var projectOptionArgument = new Argument<FileInfo>(
(SymbolResult result, out FileInfo projectFile) =>
{
return ArgumentResult.Success(directoryAccessor.GetFullyQualifiedPath(projectPath));
}
var projectPath = new RelativeFilePath(result.Tokens.Select(t => t.Value).Single());

return ArgumentResult.Failure($"Project not found: {projectPath.Value}");
})
if (directoryAccessor.FileExists(projectPath))
{
projectFile = directoryAccessor.GetFullyQualifiedFilePath(projectPath);

return true;
}

result.ErrorMessage = $"Project not found: {projectPath.Value}";
projectFile = null;
return false;
})
{
Name = "project",
Arity = ArgumentArity.ExactlyOne
Expand Down
2 changes: 1 addition & 1 deletion MLS.PackageTool/MLS.PackageTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="system.commandline.experimental" Version="0.2.0-alpha.19261.1" />
<PackageReference Include="system.commandline.experimental" Version="0.3.0-alpha.19312.1" />
</ItemGroup>

</Project>
Loading