Skip to content

Commit

Permalink
Improve how we invoke help > markdown
Browse files Browse the repository at this point in the history
Running with `dotnet run` started introducing control characters in the output (presumably from progress or other reporting?), so we instead just invoke directly the resulting tool, which should also make it faster.
  • Loading branch information
kzu committed Nov 13, 2024
1 parent 2e67eab commit ba9a65f
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/Cli/Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,30 @@
<ProjectProperty Include="PackageVersion" />
</ItemGroup>

<Target Name="RenderHelp" AfterTargets="Build" Condition="$(DesignTimeBuild) != 'true'">
<Target Name="RenderHelp" AfterTargets="Build" Condition="$(DesignTimeBuild) != 'true' and '$(OS)' == 'Windows_NT'">
<PropertyGroup>
<Cli>$(TargetDir)$(TargetName).exe</Cli>
<HelpCommand>"$(Cli)" --help --tos --unattended</HelpCommand>
<SyncCommand>"$(Cli)" sync --help --unattended</SyncCommand>
</PropertyGroup>

<WriteLinesToFile Lines="```shell" Overwrite="true" Encoding="UTF-8" File="help.md" />
<Exec Command="dotnet run --no-build -c:$(Configuration) -- --help --tos --unattended &gt;&gt; help.md" StdOutEncoding="UTF-8"
EnvironmentVariables="NO_COLOR=true" ContinueOnError="true">

<Exec Command="$(HelpCommand) &gt;&gt; help.md" StdOutEncoding="UTF-8" EnvironmentVariables="NO_COLOR=true" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<!-- Run again if it failed, but without the output redirect, for troubleshooting via build logs -->
<Exec Condition="$(MSBuildLastExitCode) != '0'"
Command="dotnet run --no-build -c:$(Configuration) -- --help --tos --unattended" StdOutEncoding="UTF-8"
EnvironmentVariables="NO_COLOR=true" />
<Exec Condition="$(MSBuildLastExitCode) != '0'" Command="$(HelpCommand)" StdOutEncoding="UTF-8" EnvironmentVariables="NO_COLOR=true" />
<Error Text="Failed to get help output." Condition="'$(MSBuildLastExitCode)' != '0'" />

<WriteLinesToFile Lines="```" Overwrite="false" Encoding="UTF-8" File="help.md" />

<WriteLinesToFile Lines="```shell" Overwrite="true" Encoding="UTF-8" File="sync.md" />
<Exec Command="dotnet run --no-build -c:$(Configuration) -- sync --help --unattended &gt;&gt; sync.md" StdOutEncoding="UTF-8"
EnvironmentVariables="NO_COLOR=true" ContinueOnError="true">
<Exec Command="$(SyncCommand) &gt;&gt; sync.md" StdOutEncoding="UTF-8" EnvironmentVariables="NO_COLOR=true" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<!-- Run again if it failed, but without the output redirect, for troubleshooting via build logs -->
<Exec Condition="$(MSBuildLastExitCode) != '0'"
Command="dotnet run --no-build -c:$(Configuration) -- sync --help --unattended" StdOutEncoding="UTF-8"
EnvironmentVariables="NO_COLOR=true" />
<Exec Condition="$(MSBuildLastExitCode) != '0'" Command="$(SyncCommand)" StdOutEncoding="UTF-8" EnvironmentVariables="NO_COLOR=true" />
<Error Text="Failed to get help output." Condition="'$(MSBuildLastExitCode)' != '0'" />
<WriteLinesToFile Lines="```" Overwrite="false" Encoding="UTF-8" File="sync.md" />
</Target>
Expand Down

0 comments on commit ba9a65f

Please sign in to comment.