feat: add multi-profile support for multiple Cookidoo accounts#13
Open
TheTrustedAdvisor wants to merge 1 commit intoLars147:mainfrom
Open
feat: add multi-profile support for multiple Cookidoo accounts#13TheTrustedAdvisor wants to merge 1 commit intoLars147:mainfrom
TheTrustedAdvisor wants to merge 1 commit intoLars147:mainfrom
Conversation
Allows managing separate Cookidoo sessions for different users: - tmx profile add/list/switch/remove/show - tmx --profile <name> <command> for per-command override - Per-profile cookies, config, cache, and weekplan data - Fully backward compatible (no profiles = legacy behavior) Closes Lars147#12 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR introduces multi-profile support to tmx_cli.py so multiple Cookidoo account sessions can be managed independently, while keeping legacy single-profile behavior when no profiles are configured.
Changes:
- Adds profile-aware path resolution for cookies, config, weekplan, search token, and shared categories cache.
- Introduces
tmx profile {add,list,switch,remove,show}commands for profile management. - Adds a global
--profile/-Pflag to override the active profile for a single command, plus updates shell completion command lists.
Comments suppressed due to low confidence (1)
tmx_cli.py:1472
- In
cmd_setup, the truncation fallback hard-codes~/.tmx_config.json, which becomes incorrect when using profile-scoped configs (e.g.,~/.tmx-cli/profiles/<name>/config.json). If the line is too long, consider truncating the actual resolved path (or using a~-prefixed abbreviated form) rather than switching to the legacy path.
config_path_line = f"║ 📁 {_get_config_file()}"
# Truncate path if too long
if len(config_path_line) > 50:
config_path_line = f"║ 📁 ~/.tmx_config.json"
print(config_path_line + " " * (51 - len(config_path_line)) + "║")
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+60
to
+80
| def _get_active_profile() -> Optional[str]: | ||
| """Get the active profile name, or None if no profiles configured.""" | ||
| if _profile_override: | ||
| return _profile_override | ||
| active_file = TMX_DIR / "active_profile" | ||
| if active_file.exists(): | ||
| name = active_file.read_text(encoding="utf-8").strip() | ||
| if name and (TMX_DIR / "profiles" / name).exists(): | ||
| return name | ||
| return None | ||
|
|
||
|
|
||
| def _get_data_dir() -> Path: | ||
| """Get the data directory for the current profile (or legacy SCRIPT_DIR).""" | ||
| profile = _get_active_profile() | ||
| if profile: | ||
| d = TMX_DIR / "profiles" / profile | ||
| d.mkdir(parents=True, exist_ok=True) | ||
| return d | ||
| # Legacy: use script directory (backward compatible) | ||
| return SCRIPT_DIR |
Comment on lines
3316
to
+3327
| def main(): | ||
| parser = build_parser() | ||
| args = parser.parse_args() | ||
|
|
||
| # Handle --profile override | ||
| if getattr(args, 'profile', None): | ||
| profile_dir = TMX_DIR / "profiles" / args.profile | ||
| if not profile_dir.exists(): | ||
| print(f"❌ Profil '{args.profile}' nicht gefunden.") | ||
| print("Verfügbare Profile: tmx profile list") | ||
| sys.exit(1) | ||
| _set_profile_override(args.profile) |
| cookies_raw = json.load(f) | ||
| cookies = {c["name"]: c["value"] for c in cookies_raw if c.get("name")} | ||
| status = "eingeloggt" if is_authenticated(cookies) else "nicht eingeloggt" | ||
| except (json.JSONDecodeError, KeyError): |
Comment on lines
+2265
to
+2270
| cookies = {c["name"]: c["value"] for c in cookies_raw if c.get("name")} | ||
| if is_authenticated(cookies): | ||
| print(f" ✅ Eingeloggt ({len(cookies)} Cookies)") | ||
| else: | ||
| print(" ❌ Nicht eingeloggt") | ||
| except (json.JSONDecodeError, OSError): |
Comment on lines
+2172
to
+2177
| print(f"✅ Profil '{name}' erstellt und als aktiv gesetzt.") | ||
| else: | ||
| print(f"✅ Profil '{name}' erstellt.") | ||
|
|
||
| print(f" Jetzt einloggen: tmx --profile {name} login") | ||
| print() |
Comment on lines
2764
to
2776
| local cur prev words cword | ||
| _init_completion || return | ||
|
|
||
| local commands="plan search recipe categories favorites today shopping status cache login setup completion" | ||
| local commands="plan search recipe categories favorites today shopping status cache login setup completion profile" | ||
| local plan_cmds="show sync add remove move" | ||
| local shopping_cmds="show add add-item from-plan remove clear export" | ||
| local cache_cmds="clear" | ||
| local categories_cmds="show sync" | ||
| local favorites_cmds="show add remove" | ||
| local profile_cmds="list add switch remove show" | ||
|
|
||
| # Get the main command and subcommand | ||
| local cmd="" subcmd="" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tmx profile add/list/switch/remove/showcommands to manage multiple named Cookidoo sessionstmx --profile <name> <command>global flag for per-command profile override without switching the active profile~/.tmx-cli/profiles/<name>/; categories cache is sharedSCRIPT_DIR-based file locationsCloses #12
Test plan
tmx profile add alicecreates~/.tmx-cli/profiles/alice/and sets it as active (first profile)tmx profile add bobcreates a second profile without switching the active onetmx profile listshows both profiles with login status and marks the active one with*tmx profile switch bobchanges the active profile; subsequenttmx statusshows bob's data directorytmx --profile alice loginlogs in as alice without changing the active profiletmx profile showdisplays the active profile's directory, config, and login statustmx profile remove aliceprompts for confirmation, removes the directory, and switches active if neededSCRIPT_DIR)bash,zsh,fish) completeprofilesubcommands correctlypython3 -m py_compile tmx_cli.pypasses with no errors🤖 Generated with Claude Code