Skip to content

Add remote command-line client (python -m mytk --remote / mytk-remote)#94

Merged
dccote merged 1 commit into
mainfrom
add-remote-cli
Jul 7, 2026
Merged

Add remote command-line client (python -m mytk --remote / mytk-remote)#94
dccote merged 1 commit into
mainfrom
add-remote-cli

Conversation

@dccote

@dccote dccote commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

A command-line client for sending a single call to a running RemoteControllable app (from v1.6.0/1.6.1) and printing the result.

python -m mytk --remote "turn_on()"
python -m mytk --remote "set_power(2.5)" --port 9000
mytk-remote "add(2, 3)"                    # standalone console script
mytk-remote --app-name Acquisition "status()"
mytk-remote --list                         # show the exposed functions

Both entry points requested were added:

  • python -m mytk --remote ... — intercepted at the top of __main__.main() before the example-launcher argparse (which has its own -l/--list), so there's no flag collision.
  • mytk-remote — a [project.scripts] console script (mytk.remotecli:main).

Behavior

  • Runs the call and prints its return value (nothing printed for None).
  • --list prints each exposed function and signature (via remote_signatures()).
  • --host / --port / --app-name select and verify the target (--app-name uses connect()'s identity check → RemoteAppMismatch).
  • Exit codes: 0 success, 1 runtime error (unreachable server, remote fault), 2 usage/bad command/identity mismatch.

Safety of the command string

Parsed with ast, not eval — arguments must be Python literals (ast.literal_eval per arg), so no arbitrary code runs. A bare "turn_on" means turn_on(). Keyword arguments are rejected (XML-RPC carries positional args only).

Tests

New mytk/tests/testRemoteCLI.py (10 tests): call-string parsing (no-arg, bare name, literals, rejected kwargs/non-call/non-literal), end-to-end call over a real socket printing the result + asserting the state change, --list output, --app-name mismatch exit code, and connection-refused handling. Full suite: 533 passed, 8 skipped.

Targeted for release v1.7.0 (new feature → minor).

🤖 Generated with Claude Code

Add a CLI to call a function on a running RemoteControllable app and print
the result:

    python -m mytk --remote "turn_on()"
    mytk-remote "add(2, 3)" --port 9000
    mytk-remote --list

The call string is parsed with ast (arguments must be Python literals; no code
execution), a bare name means a no-argument call, and keyword arguments are
rejected since XML-RPC carries positional args only. --list prints the exposed
functions via remote_signatures(); --host/--port/--app-name select and verify
the target. Wired both as `python -m mytk --remote ...` (intercepted before the
example-launcher parser) and a `mytk-remote` console script.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dccote
dccote merged commit c3f9d25 into main Jul 7, 2026
11 checks passed
@dccote
dccote deleted the add-remote-cli branch July 7, 2026 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant