# Spaced arguments for Maximo tools

This Bash adapter converts legacy value-taking options from two arguments (`-m /tmp/file.xml`) into one (`-m/tmp/file.xml`). This allows normal shell path completion after the space while retaining the legacy Java argument format. Already-attached values continue to work.

The Downloads SMP inspected for this work contains `screen-upgrade/mxdiff.bat`, which invokes `psdi.webclient.upgrade.MXScreenDiff`; it does not contain `mxdiff.sh`. No IBM files have been modified. The examples below assume your own `mxdiff.sh` has a value-taking `-m` option as described. Confirm each tool's options from its help before adding them to the list; different tools reuse the same letters with different meanings.

## Inject into a Bash launcher

Copy `maximo-spaced-args.sh` alongside your launcher. Make the launcher's shebang `#!/usr/bin/env bash` and add this immediately after it, before the launcher consumes or shifts any arguments:

```bash
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) || exit 1
source "$SCRIPT_DIR/maximo-spaced-args.sh" || exit "$?"
maximo_normalize_args auto "$@" || exit "$?"
set -- "${MAXIMO_NORMALIZED_ARGS[@]}"
```

Automatic mode needs no option list. It joins single-dash names beginning with a letter and containing letters, digits or hyphens to a following non-empty, non-dash-leading value. It cannot distinguish boolean-plus-positional arguments or already-attached word values: `-v file` becomes `-vfile`, and `-tMAXDATA file` becomes `-tMAXDATAfile`. For those tools, replace `auto` with an explicit list such as `'-m -o'`, excluding boolean switches.

Keep arguments quoted when the launcher invokes Java:

```bash
"$JAVA" -classpath "$CLASSPATH" your.existing.JavaClass "$@"
```

That line illustrates argument forwarding: retain your launcher's actual Java executable, classpath, JVM flags and class name. Replace unquoted `$*`, `$@` or a fixed list such as `$1 $2 $3 $4` with `"$@"`. Existing scripts that consume arguments into separate variables also need their forwarding adapted. Merely normalizing before a launcher that later splits arguments cannot preserve spaces inside filenames.

Then use:

```bash
./mxdiff.sh -m /tmp/input.xml
./mxdiff.sh -m "/tmp/my input.xml"
./mxdiff.sh -m/tmp/input.xml
```

For completion, type `./mxdiff.sh -m /tmp/` and press Tab. Quoting or escaping is still necessary when the completed filename contains spaces. Invoke the launcher directly or with `bash`; `sh mxdiff.sh` ignores its Bash shebang.

## Use without sourcing

For an existing launcher that already preserves `"$@"`:

```bash
bash /path/to/maximo-spaced-args.sh auto ./mxdiff.sh -m /tmp/input.xml
```

This keeps the original launcher unchanged. The adapter uses `exec`, preserving its exit status and standard streams. Run from the directory your existing launcher expects. Bash is required for the adapter, but the wrapped launcher can use another shell.

## Explicit mode and shared limits

The following exact-match and missing-value rules apply to explicit option-list mode. Automatic mode passes missing, empty and dash-leading values through for the target tool to validate. Double-dash options are not converted. Universal correctness requires knowing each tool's option grammar.

- Only exact, case-sensitive options in the configured list consume the next argument. Unknown options, boolean switches, positional arguments and attached values pass through unchanged.
- Single-dash options with multiple characters are supported. Use only options whose target parser expects the value attached directly; this is not a general GNU-style argument parser.
- Missing and empty values return status 2 without starting the tool. A separate value beginning with `-` is rejected as ambiguous: use an attached value such as `-m-1`, or a path such as `./-filename`.
- `--` stops conversion and is forwarded unchanged. This does not add `--` support to a Java tool that lacks it.
- Paths, wildcard characters and shell metacharacters remain literal arguments. The helper never uses `eval` and never reconstructs a command string.
- When sourced, the result is stored in `MAXIMO_NORMALIZED_ARGS`. The helper does not change shell options or the caller's positional parameters until you run the shown `set --` line.
- Generated IBM launchers can be overwritten by an update. Keep custom integration changes reproducible and recheck them after upgrading.

## Verification

Run in Bash:

```bash
bash public/downloads/maximo-spaced-args/test.sh
```

The tests exercise normalization, quoted paths, literal metacharacters, flags, invalid values, executable mode, exit status and an injected launcher. They do not run Maximo, connect to a database or claim that every IBM Java parser accepts spaces inside filenames.
