Skip to content

Commit 6110c57

Browse files
committed
Add ordered options by updating MatthiWare.CommandLineParser to v0.5.0
1 parent 6986728 commit 6110c57

File tree

5 files changed

+31
-23
lines changed

5 files changed

+31
-23
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,34 @@ Original repo [Metric/VCDiff](https://github.com/Metric/VCDiff)
1717

1818
## Requirements
1919
- .NET Standard 2.0+ _(code)_
20-
- .NET Core 2.1 _(CLI)_
20+
- .NET Core 3.1 _(CLI)_
2121

2222
# CLI
2323

2424
Using the CLI for creating delta patches and applying delta
2525

2626
### Create delta patch
2727

28-
`dotnet .\VCDiff.Core.Cli create -o .\original.exe -n .\updated.exe -d .\delta -b 8`
28+
To encode/create delta patch you need to specify `create -o [original] -n [updated] -d [output] -b [window size]`.
2929

30-
or
30+
`dotnet .\VCDiff.Core.Cli create .\original.exe .\updated.exe .\delta -b 8`
3131

32-
`dotnet .\VCDiff.Core.Cli create --old .\original.exe --new .\updated.exe --delta .\delta --buffer 8`
32+
`dotnet .\VCDiff.Core.Cli create -o .\original.exe -n .\updated.exe -d .\delta -b 8`
3333

34-
To encode/create delta patch you need to specify `create -o [original] -n [updated] -d [output] -b [window size]`.
34+
`dotnet .\VCDiff.Core.Cli create --old .\original.exe --new .\updated.exe --delta .\delta --buffer 8`
3535

3636
_[Window size]: The maximum buffer size for window chunking (in megabytes)._
3737

3838
### Apply delta patch
3939

40-
`dotnet .\VCDiff.Core.Cli patch -o .\original.exe -d .\delta -n .\updated.exe`
40+
To apply delta patch you need to specify `patch [original] [delta] [output]`.
4141

42-
or
42+
`dotnet .\VCDiff.Core.Cli patch .\original.exe .\delta .\updated.exe`
43+
44+
`dotnet .\VCDiff.Core.Cli patch -o .\original.exe -d .\delta -n .\updated.exe`
4345

4446
`dotnet .\VCDiff.Core.Cli patch --old .\original.exe --delta .\delta --new .\updated.exe`
4547

46-
To apply delta patch you need to specify `apply -o [original] -d [delta] -o [output]`.
4748

4849
### Verify hashes in PowerShell
4950

VCDiff.Core.Cli/Options/CreateOptions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ namespace MatthiWare.Compression.VCDiff.Cli.Options
44
{
55
public class CreateOptions
66
{
7-
[Required, Name("o", "old"), Description("Path to the old version of the file")]
7+
[Required, Name("o", "old"), OptionOrder(1), Description("Path to the old version of the file")]
88
public string OldFile { get; set; }
99

10-
[Required, Name("n", "new"), Description("Path to the new version of the file")]
10+
[Required, Name("n", "new"), OptionOrder(2), Description("Path to the new version of the file")]
1111
public string NewFile { get; set; }
1212

13-
[Required, Name("d", "delta"), Description("Output path of the delta patch file")]
13+
[Required, Name("d", "delta"), OptionOrder(2), Description("Output path of the delta patch file")]
1414
public string DeltaFile { get; set; }
1515

1616
[Name("b", "buffer"), Description("Optional buffer size to use"), DefaultValue(1)]

VCDiff.Core.Cli/Options/PatchOptions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ namespace MatthiWare.Compression.VCDiff.Cli.Options
44
{
55
public class PatchOptions
66
{
7-
[Required, Name("o", "old"), Description("Path to the old version of the file")]
7+
[Required, Name("o", "old"), OptionOrder(1), Description("Path to the old version of the file")]
88
public string OldFile { get; set; }
99

10-
[Required, Name("n", "new"), Description("Output path of the patched file")]
11-
public string NewFile { get; set; }
12-
13-
[Required, Name("d", "delta"), Description("Path of the delta patch file")]
10+
[Required, Name("d", "delta"), OptionOrder(2), Description("Path of the delta patch file")]
1411
public string DeltaFile { get; set; }
12+
13+
[Required, Name("n", "new"), OptionOrder(3), Description("Output path of the patched file")]
14+
public string NewFile { get; set; }
1515
}
1616
}

VCDiff.Core.Cli/Program.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using MatthiWare.Compression.VCDiff.Includes;
66
using System;
77
using System.IO;
8+
using System.Linq;
89

910
namespace MatthiWare.Compression.VCDiff.Cli
1011
{
@@ -36,24 +37,24 @@ static int Main(string[] args)
3637
var parserResult = parser.Parse(args);
3738

3839
if (parserResult.HasErrors && !parserResult.HelpRequested)
40+
{
3941
result = VCDiffResult.Error;
42+
}
4043

4144
switch (result)
4245
{
4346
case VCDiffResult.NOOP:
4447
parser.Printer.PrintUsage();
4548
break;
46-
case VCDiffResult.Succes:
47-
default:
48-
break;
4949
case VCDiffResult.Error:
5050
Console.Error.WriteLine("Unexpected error occured");
51-
5251
return -1;
5352
case VCDiffResult.EOD:
5453
Console.Error.WriteLine("Unexpected end of data");
55-
5654
return -2;
55+
case VCDiffResult.Succes:
56+
default:
57+
break;
5758
}
5859

5960
return 0;
@@ -64,15 +65,19 @@ private static VCDiffResult Patch(PatchOptions opt)
6465
using (var sold = File.OpenRead(opt.OldFile)) // old file
6566
using (var snew = File.OpenRead(opt.DeltaFile)) // delta file
6667
using (var sout = File.OpenWrite(opt.NewFile)) // out file
68+
{
6769
return Decode(sold, snew, sout);
70+
}
6871
}
6972

7073
private static VCDiffResult Create(CreateOptions opt)
7174
{
7275
using (var sold = File.OpenRead(opt.OldFile)) // old file
7376
using (var snew = File.OpenRead(opt.NewFile)) // new file
7477
using (var sout = File.OpenWrite(opt.DeltaFile)) // delta file
78+
{
7579
return Encode(sold, snew, sout, opt.BufferSize);
80+
}
7681
}
7782

7883
private static VCDiffResult Encode(Stream sold, Stream snew, Stream sout, int bufferSize)
@@ -89,7 +94,9 @@ private static VCDiffResult Decode(Stream sold, Stream sdelta, Stream sout)
8994
var result = decoder.Start();
9095

9196
if (result != VCDiffResult.Succes)
97+
{
9298
return result;
99+
}
93100

94101
return decoder.Decode(out _);
95102
}

VCDiff.Core.Cli/VCDiff.Core.Cli.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp2.1</TargetFramework>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
66
<Company>MatthiWare</Company>
77
<Authors>Matthias Beerens</Authors>
88
<Version>0.1.0</Version>
@@ -17,7 +17,7 @@
1717
</PropertyGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="MatthiWare.CommandLineParser" Version="0.2.4" />
20+
<PackageReference Include="MatthiWare.CommandLineParser" Version="0.5.0" />
2121
</ItemGroup>
2222

2323
<ItemGroup>

0 commit comments

Comments
 (0)