Skip to content

Commit

Permalink
Add the global tool project. (#1)
Browse files Browse the repository at this point in the history
* Add the global tool project.
* Add NuGet package information.
* Fix the Exit Status when the -R option is specified.
* Fix to build NuGet package.
  • Loading branch information
maroontress-tomohisa authored Apr 29, 2019
1 parent ad78897 commit 99b0afb
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 13 deletions.
48 changes: 48 additions & 0 deletions BomSweeper.GlobalTool/BomSweeper.GlobalTool.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<PackAsTool>true</PackAsTool>
<ToolCommandName>bomsweeper</ToolCommandName>
</PropertyGroup>

<PropertyGroup>
<PackageId>BomSweeper.GlobalTool</PackageId>
<PackageVersion>$(Version)</PackageVersion>
<Authors>Tomohisa Tanaka</Authors>
<PackageProjectUrl>https://maroontress.github.io/BomSweeper-CSharp/</PackageProjectUrl>
<RepositoryUrl>https://github.com/maroontress/BomSweeper.CSharp</RepositoryUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Description>BomSweeper is a command line tool that finds the files starting with a UTF-8 Byte Order Mark (BOM) in the directory tree and removes a BOM from those files.</Description>
<PackageReleaseNotes>See https://maroontress.github.io/BomSweeper-CSharp/releasenotes.html</PackageReleaseNotes>
<Copyright>Copyright (c) 2019 Maroontress Fast Software</Copyright>
<PackageTags>csharp, dotnet-core, global-tool, bomsweeper</PackageTags>
<NoPackageAnalysis>true</NoPackageAnalysis>
<Version>1.0.0.0</Version>
<RepositoryType />
<Company>Maroontress Fast Software</Company>
<PackageLicenseFile>COPYRIGHT.txt</PackageLicenseFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<Content Include="nuget\readme.txt">
<Pack>true</Pack>
<PackagePath>\</PackagePath>
</Content>
<Content Include="nuget\COPYRIGHT.txt">
<Pack>true</Pack>
<PackagePath>\</PackagePath>
</Content>
<Content Include="nuget\LEGAL_NOTICES.txt">
<Pack>true</Pack>
<PackagePath>\</PackagePath>
</Content>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BomSweeper\BomSweeper.csproj" />
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions BomSweeper.GlobalTool/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace BomSweeper.GlobalTool
{
class Program
{
static void Main(string[] args)
{
BomSweeper.Program.Main(args);
}
}
}
23 changes: 23 additions & 0 deletions BomSweeper.GlobalTool/nuget/COPYRIGHT.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright (c) 2019 Maroontress Fast Software. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the
distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 4 additions & 0 deletions BomSweeper.GlobalTool/nuget/LEGAL_NOTICES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Acknowledgments:

Portions of this software may utilize the following copyrighted materials,
the use of which is hereby acknowledged.
3 changes: 3 additions & 0 deletions BomSweeper.GlobalTool/nuget/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BomSweeper.GlobalTool NuGet README

See https://maroontress.github.io/BomSweeper-CSharp/
8 changes: 7 additions & 1 deletion BomSweeper.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ VisualStudioVersion = 16.0.28714.193
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BomSweeper", "BomSweeper\BomSweeper.csproj", "{386704BF-4824-4B19-9907-60DB16D434B0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BomSweeper.Test", "BomSweeper.Test\BomSweeper.Test.csproj", "{A393C43C-2C38-4921-89E2-2B87F62D56DE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BomSweeper.Test", "BomSweeper.Test\BomSweeper.Test.csproj", "{A393C43C-2C38-4921-89E2-2B87F62D56DE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BomSweeper.GlobalTool", "BomSweeper.GlobalTool\BomSweeper.GlobalTool.csproj", "{3661017B-C54A-4DBD-BB74-6B35FFB97458}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -20,6 +22,10 @@ Global
{A393C43C-2C38-4921-89E2-2B87F62D56DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A393C43C-2C38-4921-89E2-2B87F62D56DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A393C43C-2C38-4921-89E2-2B87F62D56DE}.Release|Any CPU.Build.0 = Release|Any CPU
{3661017B-C54A-4DBD-BB74-6B35FFB97458}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3661017B-C54A-4DBD-BB74-6B35FFB97458}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3661017B-C54A-4DBD-BB74-6B35FFB97458}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3661017B-C54A-4DBD-BB74-6B35FFB97458}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
55 changes: 48 additions & 7 deletions BomSweeper/BomSweeper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class Program
{
private Action<Action> doIfVerbose = a => { };
private Action chdirAction = () => { };
private Action<string> bomFileConsumer;
private Strategy strategy = FindStategy;
private int maxDepth = PathFinder.DefaultMaxDepth;

/// <summary>
Expand All @@ -28,8 +28,6 @@ var maxDepthDescription
= "The maximum number of directory levels to search.\n"
+ $"(Default: '{maxDepth}')";

bomFileConsumer = PrintBomFilename;

static int ParseMaxDepth(ValueOption o)
{
var s = o.Value;
Expand All @@ -52,7 +50,7 @@ void ShowUsageAndExit(Option o)
.Add(
"remove",
'R',
o => bomFileConsumer = BomKit.RemoveBom,
o => strategy = RemoveStategy,
"Remove a BOM")
.Add(
"directory",
Expand Down Expand Up @@ -86,6 +84,12 @@ void ShowUsageAndExit(Option o)
}
}

private static Strategy FindStategy { get; }
= new Strategy(PrintBomFilename, b => b ? 1 : 0);

private static Strategy RemoveStategy { get; }
= new Strategy(BomKit.RemoveBom, b => 0);

/// <summary>
/// Gets the setting of the command-line options.
/// </summary>
Expand Down Expand Up @@ -174,7 +178,7 @@ private static void Usage(OptionSchema schema)
}
}

private void PrintBomFilename(string file)
private static void PrintBomFilename(string file)
{
Console.WriteLine($"{file}: Starts with a BOM.");
}
Expand Down Expand Up @@ -218,10 +222,47 @@ static Regex NewRegex(string p)
var bomFiles = files.Where(BomKit.StartsWithBom);
foreach (var f in bomFiles)
{
bomFileConsumer(f);
strategy.ConsumeBomFile(f);
}

throw new TerminateProgramException(
strategy.SupplyStatusCode(bomFiles.Any()));
}

private sealed class Strategy
{
/// <summary>
/// Initializes a new instance of the <see cref="Strategy"/> class.
/// </summary>
/// <param name="consumeBomFile">
/// The action that consumes the file path, which matches the
/// specified pattern.
/// </param>
/// <param name="supplyStatusCode">
/// The function that consumes a boolean value and returns the
/// status code.
/// </param>
public Strategy(
Action<string> consumeBomFile,
Func<bool, int> supplyStatusCode)
{
ConsumeBomFile = consumeBomFile;
SupplyStatusCode = supplyStatusCode;
}

throw new TerminateProgramException(bomFiles.Any() ? 1 : 0);
/// <summary>
/// Gets the action that consumes the file path, which matches the
/// specified pattern.
/// </summary>
public Action<string> ConsumeBomFile { get; }

/// <summary>
/// Gets the function that consumes a boolean value and returns the
/// status code. When the boolean value is <c>true</c>, it
/// represents that one or more files starting with a BOM are
/// found.
/// </summary>
public Func<bool, int> SupplyStatusCode { get; }
}
}
}
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,21 @@ Options are as follows:
| `-h`, `--help` | Show help message and exit |
| `-v`, `--verbose` | Be verbose |

## Exit status
### Exit status

BomSweeper exits 0 if no files starting with a UTF-8 BOM are found,
and &gt;0 if one or more files are found or if an error occurs.

## Example
When `-R` or `--remove` option is specified,
it exits 0 on success, and &gt;0 if an error occurs.

### Example

```bash
dotnet BomSweeper.dll '**/*.cs'
```

Find `.cs` files in the current directory and subdirectories.
Find `.cs` files starting with a UTF-8 BOM in the current directory and subdirectories.

```bash
dotnet BomSweeper.dll -R '**/*.cs'
Expand All @@ -81,7 +84,7 @@ and remove a UTF-8 BOM from the files if any.
- Visual Studio 2019 Version 16.0
or [.NET Core 2.2 SDK (SDK 2.2.203)][dotnet-core-sdk]

### How to get started
### Get started

```bash
git clone URL
Expand All @@ -90,7 +93,7 @@ dotnet restore
dotnet build
```

### How to get test coverage report with Coverlet
### Get test coverage report with Coverlet

```bash
dotnet test -p:CollectCoverage=true -p:CoverletOutputFormat=opencover \
Expand All @@ -100,6 +103,14 @@ dotnet ANYWHERE/reportgenerator.dll \
--targetdir:Coverlet-html
```

### Install BomSweeper as a Global Tool

```bash
cd BomSweeper.GlobalTool
dotnet pack
dotnet tool install --global --add-source bin/Debug BomSweeper.GlobalTool
```

[dotnet-core-sdk]:
https://dotnet.microsoft.com/download/dotnet-core/2.2
[dotnet-core-runtime]:
Expand Down

0 comments on commit 99b0afb

Please sign in to comment.