Command-Line Usage
DFRefactor and its unit-test runner both support unattended operation from the command line. This enables scripted batch refactoring and continuous-integration use, where no user interaction is possible.
Which executable
This help describes the FlexTron program, DFRefactorFT64.exe, and the examples below use that name. The classic program is DFRefactorx64.exe. It accepts the same flags, except /scan (the CI scan), which is available only in DFRefactorFT64.exe.
You rarely type either. Export to ini-file writes the name of the program that produced the file into the ini-file and into the generated PowerShell wrapper, so an exported pair already points at the right executable.
DFRefactor command-line parameters
Syntax rules
- A flag and its value form a pair separated by a space (for example /sws "C:\Proj\My.sws").
- Parameters may be supplied in any order.
- Paths must be enclosed in single or double quotes.
- Flag spelling is case-insensitive.
- Each flag must be prefixed with a forward slash (/) or a dash (-).
- Only the parameters relevant to the run need to be supplied.
Flags
|
Flag(s) |
Value |
Meaning |
|
/h, /help, /?, ? |
— |
Display the parameter help, then exit. Takes precedence over /debug. |
|
/debug |
— |
Echo every parameter that was received, then exit without refactoring. |
|
/sws |
"path.sws" |
The workspace file. Mandatory unless /bm supplies an ini-file that names the workspace. |
|
/f, /file |
"path" |
A single source file (full path). Takes precedence over /sws. |
|
/d, /dirs, /folders |
A;B;C |
A semicolon-separated list of folder names. These are added to the folders already saved for the workspace, not a replacement. Use together with /sws. |
|
/bm, /batch_mode |
"path.ini" |
The usual way to run headless. Run the settings held in an ini-file. A bare file name is looked for in DFRefactor's own Programs folder; otherwise pass a full path. |
|
/scan |
"path.ini" |
Runs the CI scan (DFRefactorFT64.exe only). Analyze Source checks the workspace that the ini-file specifies, without changing any files, and the findings are compared with a baseline. See The CI scan below. |
|
/baseline |
— |
Used together with /scan. Saves the current findings as the baseline, and exits with code 0. |
|
/b, /batch |
— |
Run the settings already stored for the workspace, with no ini-file. The UI is visible while the run proceeds, but no interaction is required; actions and errors are logged, not shown. |
|
/c, -c, --console |
"path.ini" |
Superseded by /bm. Still accepted so existing scripts keep running, but no longer the documented form. |
Precedence
- A single source file (/f) takes precedence over a workspace (/sws).
- An ini-file already names the workspace, folders, filters and functions, so /sws is not needed alongside /bm.
- If neither /bm nor /batch is given, the program starts, shows the parameters it was passed, and waits — it does not begin refactoring automatically.
Examples
Run all previously selected functions across two folders of a workspace, silently:
DFRefactorFT64.exe /sws "C:\DataFlex 26.0 Examples\Order Entry\Order Entry.sws" /d AppSrc;DDSrc /batch
Run a single file:
DFRefactorFT64.exe /f "C:\Proj\AppSrc\Customer.vw" /batch
Run from a saved ini-file (recommended — see below):
DFRefactorFT64.exe /bm "DFRefactor_Order_Entry.ini"
Using an ini-file
Instead of specifying the workspace, folders, and file filter as individual flags, the entire configuration can be supplied as an ini-file via /bm.
Export to ini-file offers DFRefactor_<Workspace>.ini in DFRefactor's own Programs folder — not the folder of the workspace being refactored. Every workspace you export lands in that one place, which is why the workspace name is spliced into the file name: two workspaces exported side by side cannot overwrite each other. It is also the folder /bm searches when given a bare file name, so an exported ini-file can be run by name alone. Any other name and location will do; supply the full path if you move it. Spaces in a workspace name become underscores, because the path ends up on a command line where an unquoted space is two arguments.
The ini-file has five sections, plus a sixth for build use:
[SWS File Section]
SWS File Name=C:\Proj\My.sws
[User Name Section]
User Name=rdcto
[Folder Section]
Folder Name1=C:\Proj\AppSrc
Folder Name2=C:\Proj\DDSrc
[File Filter Section]
File Filters=*.src;*.vw;*.sl;*.dg;*.rv;*.pkg;*.cl;*.wo;*.dd;*.bp;*.inc;*.nui;*.utl;*.mn;*.mnu
[Functions Section]
Function Name1=ChangeCalcToMoveStatement
Function Name2=ChangeCurrent_ObjectToSelf
Function Name3=ChangeLegacyOperators
[Result Section]
Result File Name=...\Programs\DFRefactor_Order_Entry_RESULT.txt
Notes:
- [Folder Section] entries are numbered (Folder Name1, Folder Name2, …) and are added to the folders already saved for the workspace.
- [Functions Section] entries are numbered (Function Name1, …) and must use the exact function names shown on the Refactoring Functions pages.
- [File Filter Section] uses a single semicolon-separated File Filters value.
- If the ini-file has no [Functions Section], the run uses the functions that are currently selected in the program. If it has no [File Filter Section], the run uses the current file filter.
- [Result Section] is optional in a hand-written ini-file, but the export always fills it in, naming <ini name>_RESULT.txt beside the ini-file. See How a build tells whether the run worked.
Exporting settings to an ini-file
Writing an ini-file by hand is error-prone. Instead, configure the workspace, folders, file filter, and function selection interactively, then select Tools > Export to a Batch-mode INI File... from the menu. This writes a ready-to-use ini-file reflecting the current configuration, which can then be passed to /bm and committed to source control for repeatable runs.
Which functions are exported. When Export Selection of Refactoring Functions is checked, the ini-file contains the functions that are selected in the program. If you also check Export all Modernization functions, not only my selection, the ini-file contains all Modernization functions instead. This is useful when the ini-file will be used on another copy of the source code, which may need functions that your own copy no longer needs. A function that finds nothing to change does not change anything.
The following functions are not included: the Tidy Up functions (the editor and removal functions), report functions that you have not selected, and functions on your never-pick list. To include the 64-bit and Unicode migration functions as well, check Include the Unicode64 functions. Only do this for a workspace that is being moved to 64-bit or Unicode.
Exporting does not change the functions selected in the program. Each function is exported with the parameter value set for it in Select Functions.
The export also writes a PowerShell wrapper. Beside the ini-file you get <ini name>_RUN.ps1 — for DFRefactor_Order_Entry.ini, that is DFRefactor_Order_Entry_RUN.ps1. It is named after the ini-file rather than fixed, so a folder holding several ini-files gets a wrapper for each instead of them overwriting one another.
The wrapper is pre-filled for that ini-file and ready to drop into a build. It deletes any stale result file, starts DFRefactor headless with a watchdog timeout (30 minutes by default), kills the process tree if that expires, then reads the result back and reports. Its parameters — $Exe, $Ini, $ResultFile, $TimeoutSeconds — can all be overridden; set $Exe to a full path if the executable is not on the PATH. Re-export to refresh it.
For a workspace, DFRefactorFT64.exe also writes two more files beside the ini-file:
- <ini name>_SCAN.ps1 starts the CI scan (/scan); see The CI scan below. Use the -Baseline switch to save the current findings as the baseline. Use -WorkspaceRoot when the workspace is in a different folder on the computer that runs the scan, for example a build server.
- <ini name>_CI-SAMPLE.yml is a sample GitHub Actions workflow that you can copy and adapt. It compiles the workspace with df-cli, runs a DFUnit test program, runs the CI scan, and uploads the findings to GitHub code scanning. It requires a self-hosted Windows runner with DataFlex and DFRefactor installed. The comments at the top of the file list the files to commit with it.
How a build tells whether the run worked
A headless run reports its outcome two ways, and a careful build checks both:
- The result file named in [Result Section]. The run writes STATUS=SUCCESS or STATUS=FAILED to it. A missing file is itself the answer — the run crashed, hung, or never finished — which is why the wrapper deletes it first.
- The process exit code: 0 on success, 1 on failure.
The generated wrapper treats the result file as the source of truth and the exit code as the cross-check, exiting 0 when both agree on success, 1 when either says otherwise, and 2 when the ini-file it was pointed at does not exist.
The CI scan
DFRefactorFT64.exe /scan "DFRefactor_Order_Entry.ini" runs Analyze Source on the workspace, folders and file filter that the ini-file specifies. The scan does not change any files, and the program closes when the scan is finished.
The findings are saved beside the ini-file in two files: <ini name>.findings.json and <ini name>.findings.sarif. SARIF is a standard format that GitHub can display on a pull request. The findings are compared with a baseline file, <ini name>.baseline.json. Each finding is identified by its rule, its file and the text of its source line, not by its line number. A finding that has only moved to another line therefore still matches the baseline.
The exit code tells the build what was found:
- 0 — there are no findings that are missing from the baseline.
- 1 — there are new findings. The result file lists the first ones; the JSON and SARIF files list all of them.
- 2 — the scan could not run, for example because the workspace or a folder does not exist, or no source files were found.
Run the scan once with /scan "...ini" /baseline to save the current findings as the baseline. After that, the scan fails only when there are new findings. If there is no baseline file, every finding counts as new.
The names of the three files can be changed in the ini-file's [Scan Section] with the keys Baseline File, Json File and Sarif File. The result is written to the file named in [Result Section], the same as for /bm.
Batch-mode behavior
When a run is started with /bm or /batch:
- The program UI is shown on screen, but no user interaction is required or expected.
- All actions, and any errors, are written to the log files rather than displayed in dialogs. See Tools > Logs in Menus and Toolbars.
- With /bm, the functions and the file filter in the ini-file are used for that run only. When the run ends, the program restores your selected functions, your file filter, the function parameters and the folder selections.
- Nothing waits for a click — a prompt that would block instead writes STATUS=FAILED and exits non-zero.
- The program exits automatically when the run completes.
Running the unit-test runner headless
UnitTests64.exe, compiled from UnitTests.src, runs DFRefactor's own test suite, and supports a console mode for automated and CI use:
UnitTests64.exe -c -o "results.xml"
Its flags:
- -c, --console — run the full suite unattended, write the results to the console, and exit the process with 0 when all tests pass or -1 when any test fails.
- -o, --output "path" — additionally write a JUnit-style XML report. This is the file a CI system reads to show per-test results rather than a single pass/fail. A missing or unusable path exits -1 immediately.
- -g, --gui — force the interactive UI.
- -n, --no-autorun — start without running the suite.
- -h, --help — print the DFUnit version banner and exit 0.
In console mode the runner never returns to a UI; the process terminates as soon as the suite finishes. Without -c / --console it starts in interactive UI mode.
Caution — overlapping flag names. -c and --console mean different things in the two programs: for DFRefactorFT64.exe they are the superseded way to select a configuration ini-file and require a path argument; for UnitTests64.exe they select console / CI mode and take no argument. They are separate programs with independent argument handling.
Example: continuous-integration pipeline
A typical CI sequence:
- Once, interactively: configure the workspace and function selection, then Export to ini-file. Commit the ini-file and its _RUN.ps1 to source control.
- In the CI job, run the wrapper — it already knows the ini-file, the result file and the timeout:
powershell -File DFRefactor_Order_Entry_RUN.ps1
Or call the executable directly and check the result yourself:
DFRefactorFT64.exe /bm "DFRefactor_Order_Entry.ini"
- Run the unit tests and gate the build on the exit code:
UnitTests64.exe -c -o "results.xml"
A non-zero exit code fails the build.
- Run the CI scan. It fails the build only when there are new findings:
powershell -File DFRefactor_Order_Entry_SCAN.ps1
The _CI-SAMPLE.yml file that the export writes runs these steps in GitHub Actions. It also uploads the scan's SARIF file, so that the findings are shown on the pull request.
See also: How to use the Program, Program Settings, Overview.