Repository navigation
🚀 Hybrid CLI+TUI Pattern: Cobra + Phoenix Integration #8
kolkov
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.
Tags: #tutorial #cobra #patterns #best-practices
🎯 The Problem
Modern CLI tools face a dilemma:
--name "John") for automationMost tools force you to choose one approach. What if you could have both?
💡 The Solution: Hybrid CLI+TUI Pattern
One tool, two modes:
Same tool, different UX depending on usage!
🏗️ How It Works
1. Use Cobra for CLI Structure
Cobra is the industry-standard CLI framework (used by kubectl, gh, docker, hugo):
2. Use Phoenix for TUI Mode
Phoenix provides production-ready TUI components:
📦 Full Working Example
I've created a complete example showing this pattern:
Location:
examples/cobra-cli/Features
✅ CLI Mode - Scriptable, automation-friendly
✅ TUI Mode - Beautiful, guided, interactive
./cobra-cli # No flags → launches TUI✅ Tab Navigation - Move between fields with Tab/Shift+Tab
✅ Real-time Validation - Immediate feedback on input
✅ Beautiful Styling - Colors, borders, emojis 🎨
✅ Cross-platform - Works on Linux, macOS, Windows
Try It Yourself
🎨 Why Phoenix Over Charm?
This pattern works with Charm too (Huh + Lipgloss), but Phoenix offers critical advantages:
The Unicode Problem
Real impact: If your users have names with emojis, CJK characters, or combining marks → Charm breaks, Phoenix works.
🌍 Real-World Use Cases
This pattern is perfect for:
1. DevOps Tools
2. Database Tools
3. Configuration Tools
4. Monitoring Tools
📚 Documentation
Full example with detailed README:
examples/cobra-cli/main.go(300+ lines with comments)examples/cobra-cli/README.md(comprehensive guide)🔧 Extending the Pattern
Add More Components (Phoenix v0.2.0+)
Add Subcommands
🎓 Lessons Learned
1. Always Validate in Both Modes
2. Auto-detect CI Environments
3. Consistent Output Format
🚀 What's Next?
Phoenix v0.2.0 will add more form components inspired by Huh:
Select- Dropdown selectionMultiSelect- Multiple choiceConfirm- Yes/No dialogsForm- Grouped inputs with validationBut with Phoenix advantages:
💬 Discussion
Questions:
Show us your projects! If you build something with Phoenix + Cobra, share it here! 🙌
📎 Links
examples/cobra-cli/in Phoenix repoBuilt with 🔥 Phoenix TUI Framework v0.1.0-beta.6
Inspired by: Habr article on Go TUI utilities
Let's build the future of Go CLI tools together! 🚀
All reactions