Skip to content

Commit 8ae330b

Browse files
authored
Merge pull request #91 from sunnamed434/feature/cli-arguments
Feature/cli arguments
2 parents 562a908 + 00600dc commit 8ae330b

File tree

9 files changed

+89
-8
lines changed

9 files changed

+89
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| Versions: |
22
| - |
3+
| [v0.10.0-alpha](#v0100-alpha19) |
34
| [v0.9.0-alpha](#v090-alpha18) |
45
| [v0.8.0-alpha](#v080-alpha17) |
56
| [v0.7.0-alpha](#v070-alpha16) |
@@ -20,6 +21,11 @@
2021
| [v0.1.0](#v010) |
2122

2223
---
24+
### v0.10.0-alpha.19:
25+
2023-02-013
26+
#### Added:
27+
* Command line arguments [#82](https://github.com/sunnamed434/BitMono/issues/82)
28+
2329
### v0.9.0-alpha.18:
2430
2023-02-09
2531
#### Changed:

props/SharedProjectProps.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<PackageLicenseExpression>MIT</PackageLicenseExpression>
77
<PackageProjectUrl>https://github.com/sunnamed434/BitMono</PackageProjectUrl>
88
<PackageOwners>sunnamed434</PackageOwners>
9-
<PackageVersion>0.9.0-alpha.18</PackageVersion>
9+
<PackageVersion>0.10.0-alpha.19</PackageVersion>
1010
<RepositoryUrl>https://github.com/sunnamed434/BitMono</RepositoryUrl>
1111
<RepositoryType>git</RepositoryType>
1212
<Authors>sunnamed434</Authors>
13-
<Version>0.9.0-alpha.18</Version>
14-
<InformationalVersion>0.9.0-alpha.18</InformationalVersion>
13+
<Version>0.10.0-alpha.19</Version>
14+
<InformationalVersion>0.10.0-alpha.19</InformationalVersion>
1515
<Company>BitMono</Company>
1616
<Copyright>sunnamed434</Copyright>
1717
<LangVersion>10</LangVersion>

src/BitMono.CLI/BitMono.CLI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<Import Project="$(MSBuildThisFileDirectory)..\..\props\SharedProjectProps.props" />
1010

1111
<ItemGroup>
12+
<PackageReference Include="CommandLineParser" Version="2.9.1" />
1213
<PackageReference Include="Costura.Fody" Version="5.7.0">
1314
<PrivateAssets>all</PrivateAssets>
1415
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

src/BitMono.CLI/GlobalUsings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
global using System;
1111
global using System.Collections.Generic;
1212
global using System.Diagnostics;
13+
global using System.Diagnostics.CodeAnalysis;
1314
global using System.IO;
1415
global using System.Linq;
1516
global using System.Threading;
1617
global using System.Threading.Tasks;
1718
global using BitMono.Core.Extensions;
1819
global using BitMono.Host.Extensions;
1920
global using BitMono.Shared.Models;
21+
global using CommandLine;
2022
global using Microsoft.Extensions.Options;
2123
global using Pocket.Extensions;
2224
global using Serilog;

src/BitMono.CLI/Modules/CLIObfuscationNeedsFactory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace BitMono.CLI.Modules;
22

3+
[SuppressMessage("ReSharper", "InconsistentNaming")]
34
public class CLIObfuscationNeedsFactory : IObfuscationNeedsFactory
45
{
56
private readonly string[] m_Args;
@@ -87,9 +88,7 @@ public ObfuscationNeeds Create()
8788

8889
return new ObfuscationNeeds
8990
{
90-
#pragma warning disable CS8601
9191
FileName = fileName,
92-
#pragma warning restore CS8601
9392
FileBaseDirectory = fileBaseDirectory,
9493
DependenciesDirectoryName = dependenciesDirectoryName,
9594
OutputDirectoryName = outputDirectoryName
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace BitMono.CLI.Modules;
2+
3+
[SuppressMessage("ReSharper", "InconsistentNaming")]
4+
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")]
5+
public class CLIOptions
6+
{
7+
[Option('f', "file", Required = true, HelpText = "Set file path.")]
8+
public string? File { get; set; }
9+
10+
[Option('l', "libraries", Required = false, HelpText = "Set libraries path.")]
11+
public string? Libraries { get; set; }
12+
13+
[Option('o', "output", Required = false, HelpText = "Set output path.")]
14+
public string? Output { get; set; }
15+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#pragma warning disable CS8604
2+
namespace BitMono.CLI.Modules;
3+
4+
[SuppressMessage("ReSharper", "InconsistentNaming")]
5+
public class CLIOptionsObfuscationNeedsFactory : IObfuscationNeedsFactory
6+
{
7+
private readonly string[] m_Args;
8+
9+
public CLIOptionsObfuscationNeedsFactory(string[] args)
10+
{
11+
m_Args = args;
12+
}
13+
14+
[SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")]
15+
public ObfuscationNeeds? Create()
16+
{
17+
var parser = new Parser(with =>
18+
{
19+
with.EnableDashDash = true;
20+
with.HelpWriter = Console.Error;
21+
});
22+
var parserResult = parser.ParseArguments<CLIOptions>(m_Args);
23+
if (parserResult.Errors.IsEmpty() == false)
24+
{
25+
return null;
26+
}
27+
var options = parserResult.Value;
28+
if (File.Exists(options.File) == false)
29+
{
30+
Console.WriteLine("File cannot be found, please, try again!");
31+
return null;
32+
}
33+
var fileBaseDirectory = Path.GetDirectoryName(options.File);
34+
var needs = new ObfuscationNeeds
35+
{
36+
FileName = options.File,
37+
FileBaseDirectory = fileBaseDirectory,
38+
DependenciesDirectoryName = options.Libraries.IsNullOrEmpty() == false
39+
? options.Libraries
40+
: Path.Combine(fileBaseDirectory, "libs"),
41+
OutputDirectoryName = options.Output.IsNullOrEmpty() == false
42+
? options.Output
43+
: Path.Combine(fileBaseDirectory, "output")
44+
};
45+
46+
Directory.CreateDirectory(needs.OutputDirectoryName);
47+
Directory.CreateDirectory(needs.DependenciesDirectoryName);
48+
return needs;
49+
}
50+
}

src/BitMono.CLI/Program.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ private static async Task Main(string[] args)
77
{
88
try
99
{
10-
var needs = new CLIObfuscationNeedsFactory(args).Create();
10+
ObfuscationNeeds? needs = null;
11+
needs = args.IsEmpty()
12+
? new CLIObfuscationNeedsFactory(args).Create()
13+
: new CLIOptionsObfuscationNeedsFactory(args).Create();
14+
if (needs == null)
15+
{
16+
return;
17+
}
18+
1119
Console.Clear();
1220
Console.WriteLine("File: {0}", needs.FileName);
1321
Console.WriteLine("Dependencies (libs): {0}", needs.DependenciesDirectoryName);
14-
Console.WriteLine("Everything is seems to be good, starting obfuscation..");
22+
Console.WriteLine("Everything is seems to be ok, starting obfuscation..");
1523

1624
var module = new BitMonoModule(
1725
configureContainer => configureContainer.AddProtections(),

src/BitMono.Obfuscation.API/IObfuscationNeedsFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
public interface IObfuscationNeedsFactory
44
{
5-
ObfuscationNeeds Create();
5+
ObfuscationNeeds? Create();
66
}

0 commit comments

Comments
 (0)