Repository navigation
Add a WinRM CLI and standalone executable JAR #112
Description
Goal
Add a command-line interface for running WQL queries and remote commands, and update pom.xml so every build also produces a self-contained executable JAR.
The existing regular library JAR must remain unchanged/available. The executable should be an additional artifact, for example:
winrm-java-<version>-standalone.jar
invoked with:
java -jar winrm-java-<version>-standalone.jar [options] wql <query>
java -jar winrm-java-<version>-standalone.jar [options] command <command line...>cmd, exec, and run must be aliases for command.
CLI syntax
winrm-java [connection/authentication options] wql <query>
winrm-java [connection/authentication options] command|cmd|exec|run <command line...>
Required connection options
--hostname,-h— target hostname or IP address.--username,-u— username, including forms such asDOMAIN\userorHOST\localuser.
Credential options
--password,-p— password supplied directly.--password-file,-pf— read the password from a file.
--password and --password-file must be mutually exclusive. Passwords must never be printed in diagnostics, usage errors, or logs. The password-file behavior must be documented, including treatment of its final CR/LF. Clear mutable password buffers when practical.
Direct --password use should carry a documentation warning that command-line arguments can be visible to other local processes; --password-file is preferred for automation.
Authentication options
--ntlm— use NTLM authentication.--kerberos— use Kerberos authentication.
Document the default when neither is supplied (currently NTLM). If both flags are accepted for fallback, define and test their ordering; otherwise report a clear mutual-exclusion error.
Transport and timeout options
--https— use HTTPS instead of HTTP.--https-permissive, — allow self-signed certificates (you can modify the option name if you find something more accurate and descriptive)--port,-P— target port.--timeout,-t— operation timeout in milliseconds.
-p was requested for both password and port, which is ambiguous. Reserve lowercase -p for password and use uppercase -P for port. The default port should follow the transport: 5985 for HTTP and 5986 for HTTPS.
Command behavior
WQL
java -jar winrm-java-<version>-standalone.jar \
-h server.example.net -u 'DOMAIN\user' -pf password.txt --ntlm \
wql 'SELECT Name,State FROM Win32_Service'- Execute the complete query following the
wqlsubcommand. - Write rows to stdout in a documented, stable format suitable for both humans and shell pipelines.
- Write diagnostics to stderr.
- Integrate with the streaming WQL API from Streaming APIs (phase 2): stream()/start() terminal methods on the fluent WinRMClient #111 when available so large enumerations do not have to be fully buffered.
Command execution
java -jar winrm-java-<version>-standalone.jar \
--hostname server.example.net --username Administrator --password-file password.txt --https \
exec ipconfig /all- Treat every remaining argument after
command|cmd|exec|runas part of the remote command line, preserving spaces and quoting as predictably as possible. - Forward remote stdout to local stdout and remote stderr to local stderr.
- Stream output as it arrives using Streaming APIs (phase 2): stream()/start() terminal methods on the fluent WinRMClient #111 when available.
- Propagate the remote command exit status when it can be represented as a process exit code.
Executable JAR
Update pom.xml to produce an attached standalone executable artifact, preferably with maven-shade-plugin:
- keep the normal library JAR;
- attach a
standaloneclassifier rather than replacing the main artifact; - include all runtime dependencies;
- set the manifest
Main-Classto the CLI entry point; - merge any required service resources correctly;
- avoid publishing dependency-reduced POM changes that break consumers;
- retain reproducible-build behavior.
No CXF-specific packaging is required; the CLI targets the lightweight client only.
Exit codes
Define and document stable exit behavior, including at least:
0: successful WQL query or remote command with exit code 0;- remote command exit code: propagated where possible;
- distinct non-zero handling for CLI usage errors versus connection, authentication, timeout, and WinRM protocol failures.
Acceptance criteria
mvn packageproduces both the normal library JAR and an executable standalone JAR.java -jar ...-standalone.jar --helpprints usage and exits successfully.--versionprints the project version.- All long and short options listed above are supported, with
-pfor password and-Pfor port. wqlexecutes WQL and emits results to stdout.command,cmd,exec, andrunexecute remote commands and forward stdout/stderr appropriately.- HTTP/HTTPS default ports and explicit port overrides work.
- NTLM and Kerberos selection works according to documented defaults and conflict/fallback rules.
- Password-file input works without leaking secrets.
- Invalid/missing/conflicting options produce concise errors and a non-zero usage exit code.
- Unit tests cover argument parsing, aliases, defaults, conflicts, password files, exit-code mapping, and command-line reconstruction.
- An end-to-end test verifies the manifest and launches the built JAR in a separate JVM.
- README/Javadocs document installation, examples, authentication, certificate trust for HTTPS, password security, output formats, and exit codes.
Activity