Skip to content

feat: add multi-profile support for multiple Cookidoo accounts#13

Open
TheTrustedAdvisor wants to merge 1 commit intoLars147:mainfrom
TheTrustedAdvisor:feat/multi-profile
Open

feat: add multi-profile support for multiple Cookidoo accounts#13
TheTrustedAdvisor wants to merge 1 commit intoLars147:mainfrom
TheTrustedAdvisor:feat/multi-profile

Conversation

@TheTrustedAdvisor
Copy link
Copy Markdown

Summary

  • Adds tmx profile add/list/switch/remove/show commands to manage multiple named Cookidoo sessions
  • Adds tmx --profile <name> <command> global flag for per-command profile override without switching the active profile
  • Each profile gets its own cookies, config, and weekplan data stored under ~/.tmx-cli/profiles/<name>/; categories cache is shared
  • Fully backward compatible: users with no profiles configured continue to use the legacy SCRIPT_DIR-based file locations

Closes #12

Test plan

  • tmx profile add alice creates ~/.tmx-cli/profiles/alice/ and sets it as active (first profile)
  • tmx profile add bob creates a second profile without switching the active one
  • tmx profile list shows both profiles with login status and marks the active one with *
  • tmx profile switch bob changes the active profile; subsequent tmx status shows bob's data directory
  • tmx --profile alice login logs in as alice without changing the active profile
  • tmx profile show displays the active profile's directory, config, and login status
  • tmx profile remove alice prompts for confirmation, removes the directory, and switches active if needed
  • With no profiles configured, all existing commands behave exactly as before (files in SCRIPT_DIR)
  • Shell completions (bash, zsh, fish) complete profile subcommands correctly
  • python3 -m py_compile tmx_cli.py passes with no errors

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings April 18, 2026 09:24
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/-P flag 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 thread tmx_cli.py
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 thread tmx_cli.py
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)
Comment thread tmx_cli.py
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 thread tmx_cli.py
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 thread tmx_cli.py
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 thread tmx_cli.py
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=""
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.

feat: Multi-profile support for multiple Cookidoo accounts

2 participants