Repository navigation
Forward prompt writes to the shell #273
grisuno
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I fixed the stale prompt after assign.
The mechanism was an asymmetry in the CommandSet base class. LazyOwnCommandSet
forwards unknown attribute reads to the bound shell, so migrated do_* methods
can reference shell state. It did not forward writes. When do_assign and
config_banner did self.custom_prompt = getprompt() and self.prompt = ..., the
values landed on the CommandSet while the shell, which cmd2 reads for the
prompt, kept the old string. The status bar hook recomputes from
shell.custom_prompt on every command, so the write side was the only gap.
I generalized the fix: the base class now forwards writes for exactly the two
prompt attributes, and LazyOwnShell owns refresh_prompt() so assign and
config_banner share one refresh path instead of duplicating the two-line
incantation.
The lesson: read forwarding without write forwarding breaks every migrated
method that assigns, silently and only at runtime. An asymmetry between
getattr and setattr is a bug waiting for the first write.
Validation: shell prompt contains the new rhost after assign, pytest 3627
passed, BDD 530 passed, mutation 12 of 12 runners, command audit 0 errors.
All reactions