feat: add support for environment variables in new-session command#208
feat: add support for environment variables in new-session command#208pbolduc wants to merge 1 commit into
Conversation
- Enhanced the `new-session` command to accept `-e VAR=value` flags for setting environment variables. - Implemented parsing for environment variable assignments and integrated them into the session environment. - Updated relevant functions to handle the new session environment variables, ensuring they are applied after loading the configuration. - Added tests for parsing and collecting environment variable arguments to ensure correctness. This feature allows users to define environment variables for new sessions directly from the command line, improving flexibility and usability.
|
Hey @pbolduc, really appreciate you taking the time to write this PR! Your code quality is genuinely impressive, especially for someone who says they do not normally code in Rust. I had already started working on a fix for #205 before I saw your PR (commit 38d7cfa), but after reviewing your approach I immediately saw several things you did better than my initial implementation: What I adopted from your PR (commit 9926b85):
One timing difference I kept from my implementation: Your PR applies env vars AFTER crate::config::populate_default_bindings(&mut app);
load_config(&mut app);
// new-session -e: apply after config so CLI overrides set-environment from config
crate::util::merge_session_env_into_app(&mut app, &session_env);The issue is that Your idea of "CLI overrides config" is a valid design choice though. Since we skip warm pane entirely when Since I have already merged the core ideas from your PR into master, I will close this PR. But seriously, thank you for the thorough contribution. The validation, utility functions, and tests made the implementation significantly better. Looking forward to more contributions from you! |
Incorporates the best ideas from @pbolduc's PR #208: - Added utility functions in util.rs: parse_env_assignment(), parse_new_session_e_value_token(), collect_server_session_env_args(), merge_session_env_into_app(), is_valid_env_var_name() - Switched from Vec<String> to Vec<(String, String)> for type safety - Added validation: rejects invalid env var names (123=x, bad-name=x) and missing values with clear error messages - Added comprehensive unit tests from PR #208 plus additional tests - Kept correct timing: env vars applied BEFORE spawn_warm_pane() so the first pane inherits them (PR #208 applied after, which would miss the warm pane) Ref: #205, PR #208
|
Completed by maintainer in another PR. |
Here is my attempt at adding this feature. I dont really code in Rust, so if there is any AI slop, please point it out. I didn't like these big blocks added to the
-eparsing in main.rs, commands.rs and connection.rs. Please advise of any changes you would like to see.new-sessioncommand to accept-e VAR=valueflags for setting environment variables.Fixes #205