Edit online

Providing Arguments to Comparison Scripts via a Configuration File

The arguments/options required to run comparison scripts (Compare Directories and Compare Files) can be provided through configuration files (argument files) if their structure follows a few simple rules, as detailed below:

  • The basic format of the configuration file is XML, but JSON or YAML formatted files are also supported, being converted to XML.
  • The name of the root does not matter.
  • Any child of the root (also, the name of the child does not matter) is a candidate element for describing a script argument, if it meets the following 2 mandatory conditions:

    • It has a sub-element <id>argument_id</id> (argument_id must be present for it to be mapped to the argument_value).
    • It has a sub-element <value>argument_value</value> (if argument_value is missing, the mapping is completed programmatically to a default value based on argument_id).
  • Additionally:

    • If <id> denotes an argument ID of the type 'file path' and an alias is also desired, then a sub-element <alias>path_alias</alias> must be added. However, an alias also makes sense as a distinct argument ID, meaning for example, the sub-element structure <id>spa</id><value>directory-2</value> will correctly associate the alias directory-2 with sp ('sp' stands for 'second path', 'spa' stands for 'second path alias').
    • An optional sub-element <descr>argument_description</descr> can be useful when editing/modifying the XML file, providing explanations about the ID of the current argument (which is most often quite cryptic).
  • If there are non-mandatory script arguments without counterparts among the child elements of the root of the parsed XML file, default values associated with the IDs of the respective arguments are provided later programmatically.

Below are some examples of configuration files that can be used to read the script arguments from:

XML File
<?xml version="1.0" encoding="UTF-8"?>
<args>
    <arg>
        <id>fp</id>
        <value>D:/workspace/oxygen-blog/blog-branch-01</value>
        <alias>DIR-1</alias>
        <descr>1st path</descr>
    </arg>
    <arg>
        <id>sp</id>
        <value>D:/workspace/oxygen-blog/blog-branch-02</value>
        <alias>DIR-2</alias>
        <descr>2nd path</descr>
    </arg>
    <arg>
        <id>bp</id>
        <value>D:/workspace/oxygen-blog/blog-main</value>
        <descr>base path</descr>
    </arg>
    <arg>
	<descr>base path alias</descr>
        <id>bpa</id>
        <value>BASE</value>        
    </arg>    
    <arg>
        <id>ia</id>
        <value>false</value>
        <descr>look inside archives</descr>
    </arg>
    <arg>
        <id>ed</id>
        <value>git*</value>        
        <descr>exclude folders filter</descr>
    </arg>
	
	...................................
	
<args>
JSON File
{
    "options": {
        "option": [
            {
                "id": "fp",                
                "value": "D:/workspace/oxygen-blog/blog-branch-01",
                "alias": "DIR-1",
		"descr": "first path"
            },
            {
                "id": "sp",                
                "value": "D:/workspace/oxygen-blog/blog-branch-02",
                "alias": "DIR-2",
		"descr": "second path"
            },
	    {
                "id": "ed",
                "descr": "exclude folders filter",
                "value": "git*"
            }
	    {
                "id": "ia",
                "descr": "look inside archives",
                "value": false
            },
			
			........................
			
	]
    }
}
YAML File
---
arguments:
  argument:
  - id: fp
    descr: 1st path
    value: D:/workspace/oxygen-blog/blog-branch-01
    alias: DIR-1
  - id: sp
    descr: 2nd path
    value: D:/workspace/oxygen-blog/blog-branch-02
    alias: DIR-2
  - id: bp
    descr: base path
    value: D:/workspace/oxygen-blog/blog-main
    alias: BASE
  - id: ia	
    value: false
    descr: include archives	
  - id: ed	
    value: git*
    descr: exclude folders filter
	
.........................................