Skip to content

Refactor AnyGen CLI for better state management#187

Open
manucian-official wants to merge 1 commit intoHKUDS:mainfrom
manucian-official:patch-3
Open

Refactor AnyGen CLI for better state management#187
manucian-official wants to merge 1 commit intoHKUDS:mainfrom
manucian-official:patch-3

Conversation

@manucian-official
Copy link
Copy Markdown
Contributor

Refactor: CLI Architecture Optimization

Overview

This update delivers a focused internal refactor of the AnyGen CLI, improving structure, consistency, and maintainability without introducing any breaking changes.


Highlights

  • Centralized State Management
    Introduced AppContext as a single source of truth, replacing fragmented global variables.

  • Unified Output Layer
    Standardized all outputs via a single handler, ensuring consistency across CLI and JSON modes.

  • Normalized Error Handling
    Implemented a decorator-based approach for clean, predictable error reporting.

  • Lazy Initialization
    Deferred session loading to reduce unnecessary I/O and improve startup performance.

  • Reduced Duplication
    Abstracted repeated patterns, resulting in a leaner and more maintainable codebase.

  • Simplified CLI Structure
    Streamlined command definitions for improved readability and usability.


Design Principles

  • Separation of Concerns
  • Single Source of Truth
  • Consistency Over Convenience
  • Extensibility by Design

Compatibility

  • No breaking changes
  • All existing commands remain intact
  • Fully backward compatible

Summary

This refactor strengthens the internal architecture, delivering a cleaner, more scalable foundation for future development while remaining completely transparent to end users.

Refactor AnyGen CLI to use centralized AppContext for global state management and improve output handling.
@omerarslan0
Copy link
Copy Markdown
Collaborator

@manucian-official Same problem as #180. The AppContext dataclass is a fine idea (~10 lines), but the rest of the PR deletes 15 of ~20 commands with no replacement. That's not refactoring.

Keep all existing commands, fix the 4 bugs from #180 review, and submit only the state management change:

  1. Rename json parameter to use_json — it shadows import json
  2. Add @functools.wraps(func) to handle_error
  3. Mask API key in config set output
  4. Restore click.Choice validation on config set

Do not delete commands. Do not remove CLI options from task run. The AppContext refactor should be a zero-behavior-change commit.

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.

2 participants