Skip to content

Commit 50aa71f

Browse files
committed
docs(readme): update version to 0.2.24 and modify command line options description
refactor(XMLDiff, XMLPatch): enable ignoring unknown arguments and improve help output refactor(XMLDiff): --only-full-path option replaced by --anywhere-is-allowed. And default behavior is to use full path.
1 parent fc4d3e3 commit 50aa71f

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ If the `diff.xsd` file if it located in the "current" folder it will be used aut
2323
There is a command line help for the `XMLDiff` tool:
2424

2525
```shell
26-
XMLDiff 0.2.18
26+
XMLDiff 0.2.24
2727
Developed by Chem O`Dun
2828
2929
-o, --original_xml Required. Path to the original XML file or directory.
@@ -38,7 +38,7 @@ Developed by Chem O`Dun
3838
3939
-a, --append-to-log (Default: false) Append logs to the existing log file.
4040
41-
--only-full-path (Default: false) Generate only full path.
41+
--anywhere-is-allowed (Default: false) Generate a path using the anywhere '//' construction, if possible. Instead of full path.
4242
4343
--use-all-attributes (Default: false) Use all attributes in XPath.
4444
@@ -278,7 +278,9 @@ Please be aware - each release archive has an appropriate link to the [VirusTota
278278
- XMLDiff: XPath generation when the element has child elements, which can unique identify it.
279279
280280
- Changed:
281+
- XMLDiff: --only-full-path option replaced by --anywhere-is-allowed. And default behavior is to use full path.
281282
- Both utilities: log level of console will not be more detailed than for the log file.
283+
- Both utilities: the unknown options will be ignored.
282284
283285
- Fixed:
284286
- XMLDiff: doubling the first attribute in XPath for the elements, if more than one attribute is used.

XMLDiff/Program.cs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,18 @@ class XMLDiff
1616

1717
static void Main(string[] args)
1818
{
19-
Parser
20-
.Default.ParseArguments<Options>(args)
19+
if (args.Length == 0)
20+
args = new[] { "--help" };
21+
var parser = new Parser(config =>
22+
{
23+
config.IgnoreUnknownArguments = true; // Enable ignoring unknown arguments
24+
config.AutoHelp = true; // Enable auto help
25+
config.AutoVersion = true; // Enable auto version
26+
config.CaseSensitive = true; // Enable case sensitivity
27+
config.HelpWriter = Console.Out; // Set HelpWriter to Console.Out
28+
});
29+
parser
30+
.ParseArguments<Options>(args)
2131
.WithParsed<Options>(opts => RunOptionsAndReturnExitCode(opts))
2232
.WithNotParsed<Options>((errs) => HandleParseError(errs));
2333
}
@@ -39,7 +49,7 @@ private static void RunOptionsAndReturnExitCode(Options opts)
3949
var modifiedXmlPath = opts.ModifiedXml;
4050
var diffXmlPath = opts.DiffXml;
4151
var diffXsdPath = opts.Xsd ?? "diff.xsd";
42-
var pathOptions = new PathOptions { OnlyFullPath = opts.OnlyFullPath, UseAllAttributes = opts.UseAllAttributes };
52+
var pathOptions = new PathOptions { AnywhereIsAllowed = opts.AnywhereIsAllowed, UseAllAttributes = opts.UseAllAttributes };
4353

4454
bool originalIsDir = Directory.Exists(originalXmlPath);
4555
bool modifiedIsDir = Directory.Exists(modifiedXmlPath);
@@ -90,7 +100,7 @@ public class Options
90100
private string? diffXml;
91101
private string? xsd;
92102
private string? logToFile;
93-
private bool onlyFullPath;
103+
private bool anywhereIsAllowed;
94104
private bool useAllAttributes;
95105
private bool appendToLog;
96106

@@ -145,11 +155,16 @@ public bool AppendToLog
145155
set => appendToLog = value;
146156
}
147157

148-
[Option("only-full-path", Required = false, HelpText = "Generate only full path.", Default = false)]
149-
public bool OnlyFullPath
158+
[Option(
159+
"anywhere-is-allowed",
160+
Required = false,
161+
HelpText = "Generate a path using the anywhere '//' construction, if possible. Instead of full path.",
162+
Default = false
163+
)]
164+
public bool AnywhereIsAllowed
150165
{
151-
get => onlyFullPath;
152-
set => onlyFullPath = value;
166+
get => anywhereIsAllowed;
167+
set => anywhereIsAllowed = value;
153168
}
154169

155170
[Option("use-all-attributes", Required = false, HelpText = "Use all attributes in XPath.", Default = false)]
@@ -870,7 +885,7 @@ private static string GenerateXPath(XElement element, PathOptions pathOptions)
870885
if (root == null)
871886
return string.Empty;
872887
XDocument? doc = null;
873-
if (!pathOptions.OnlyFullPath)
888+
if (pathOptions.AnywhereIsAllowed)
874889
{
875890
doc = element.Document;
876891
}
@@ -1057,7 +1072,7 @@ private static bool ValidateXsdPath(string? xsdPath)
10571072

10581073
public class PathOptions
10591074
{
1060-
public bool OnlyFullPath { get; set; }
1075+
public bool AnywhereIsAllowed { get; set; }
10611076
public bool UseAllAttributes { get; set; }
10621077
}
10631078
}

XMLPatch/Program.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,18 @@ class XMLPatch
1818
static void Main(string[] args)
1919
{
2020
var program = new XMLPatch();
21-
Parser
22-
.Default.ParseArguments<Options>(args)
21+
if (args.Length == 0)
22+
args = new[] { "--help" };
23+
var parser = new Parser(config =>
24+
{
25+
config.IgnoreUnknownArguments = true; // Enable ignoring unknown arguments
26+
config.AutoHelp = true; // Enable auto help
27+
config.AutoVersion = true; // Enable auto version
28+
config.CaseSensitive = true; // Enable case sensitivity
29+
config.HelpWriter = Console.Out; // Set HelpWriter to Console.Out
30+
});
31+
parser
32+
.ParseArguments<Options>(args)
2333
.WithParsed<Options>(opts => program.RunOptionsAndReturnExitCode(opts))
2434
.WithNotParsed<Options>((errs) => HandleParseError(errs));
2535
}

0 commit comments

Comments
 (0)