@@ -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}
0 commit comments