🔧 Enhanced setup with interactive Git configuration and user preferences

This commit is contained in:
Vijay Janapa Reddi
2025-08-01 14:16:26 -04:00
parent d0960141b9
commit 90229f24e4

221
binder
View File

@@ -715,9 +715,17 @@ class BookBinder:
if success:
console.print(f"[green] ✅ Fast build complete: build/{build_subdir}/[/green]")
# Automatically open the output file if HTML and requested
if format_type == "html" and output and open_browser:
# Automatically open the output file if HTML and requested
if format_type == "html" and output and open_browser:
# Check user preference for auto-open
preferences = self.get_user_preferences()
auto_open = preferences.get('auto_open', True)
if auto_open:
self.open_output_file(output)
else:
console.print(f"[blue]📄 Output ready: {output}[/blue]")
console.print("[dim]💡 Set auto-open preference with './binder setup'[/dim]")
else:
console.print("[red] ❌ Build failed[/red]")
@@ -1130,9 +1138,16 @@ class BookBinder:
# Ask about AI release notes
use_ai_notes = False
if create_release:
# Get user preference for AI
preferences = self.get_user_preferences()
ai_default = preferences.get('ai_default', True)
ai_default_text = "y" if ai_default else "n"
console.print("\n[blue]📝 Generate release notes with AI?[/blue]")
console.print("[bold]Use AI for release notes? (y/n): [/bold]", end="")
console.print(f"[bold]Use AI for release notes? (y/n) [{ai_default_text}]: [/bold]", end="")
ai_choice = input().strip().lower()
if not ai_choice:
ai_choice = ai_default_text
use_ai_notes = ai_choice in ['y', 'yes']
return {
@@ -1712,8 +1727,12 @@ Format as markdown with clear sections."""
console.print("\n[blue]📋 Step 3: Git Configuration[/blue]")
self._configure_git()
# Step 4: Test setup
console.print("\n[blue]📋 Step 4: Test Setup[/blue]")
# Step 4: Environment preferences
console.print("\n[blue]📋 Step 4: Environment Preferences[/blue]")
self._configure_preferences()
# Step 5: Test setup
console.print("\n[blue]📋 Step 5: Test Setup[/blue]")
self._test_setup()
console.print("\n[green]✅ Environment setup completed![/green]")
@@ -1778,29 +1797,193 @@ Format as markdown with clear sections."""
console.print("[green]✅ All required tools are available[/green]")
def _configure_git(self):
"""Configure Git settings"""
"""Configure Git settings interactively"""
console.print("[blue]🔧 Configuring Git...[/blue]")
# Check if Git is configured
# Check current Git configuration
current_name = None
current_email = None
try:
result = subprocess.run(['git', 'config', 'user.name'], capture_output=True, text=True)
if result.returncode != 0:
console.print("[yellow]⚠️ Git user.name not configured[/yellow]")
console.print("[blue]💡 Run: git config --global user.name 'Your Name'[/blue]")
else:
console.print(f"[green]✅ Git user.name: {result.stdout.strip()}[/green]")
if result.returncode == 0:
current_name = result.stdout.strip()
except:
console.print("[red]❌ Git not available[/red]")
pass
try:
result = subprocess.run(['git', 'config', 'user.email'], capture_output=True, text=True)
if result.returncode != 0:
console.print("[yellow]⚠️ Git user.email not configured[/yellow]")
console.print("[blue]💡 Run: git config --global user.email 'your.email@example.com'[/blue]")
else:
console.print(f"[green]✅ Git user.email: {result.stdout.strip()}[/green]")
if result.returncode == 0:
current_email = result.stdout.strip()
except:
console.print("[red]❌ Git not available[/red]")
pass
# Show current configuration
if current_name and current_email:
console.print(f"[green]✅ Current Git configuration:[/green]")
console.print(f" Name: {current_name}")
console.print(f" Email: {current_email}")
console.print("\n[blue]Would you like to update your Git configuration?[/blue]")
console.print("[bold]Update Git config? (y/n): [/bold]", end="")
update_choice = input().strip().lower()
if update_choice not in ['y', 'yes']:
console.print("[green]✅ Keeping current Git configuration[/green]")
return
else:
console.print("[yellow]⚠️ Git configuration incomplete[/yellow]")
# Get user information
console.print("\n[blue]📝 Please provide your information:[/blue]")
# Get name
if current_name:
console.print(f"[bold]Full name [{current_name}]: [/bold]", end="")
name_input = input().strip()
if not name_input:
name_input = current_name
else:
console.print("[bold]Full name: [/bold]", end="")
name_input = input().strip()
# Get email
if current_email:
console.print(f"[bold]Email [{current_email}]: [/bold]", end="")
email_input = input().strip()
if not email_input:
email_input = current_email
else:
console.print("[bold]Email: [/bold]", end="")
email_input = input().strip()
# Get GitHub username
console.print("[bold]GitHub username: [/bold]", end="")
github_username = input().strip()
# Configure Git
try:
if name_input:
subprocess.run(['git', 'config', '--global', 'user.name', name_input], check=True)
console.print(f"[green]✅ Set Git user.name: {name_input}[/green]")
if email_input:
subprocess.run(['git', 'config', '--global', 'user.email', email_input], check=True)
console.print(f"[green]✅ Set Git user.email: {email_input}[/green]")
# Store GitHub username for future use
if github_username:
subprocess.run(['git', 'config', '--global', 'user.github', github_username], check=True)
console.print(f"[green]✅ Set GitHub username: {github_username}[/green]")
console.print("[green]✅ Git configuration completed![/green]")
except subprocess.CalledProcessError as e:
console.print(f"[red]❌ Failed to configure Git: {e}[/red]")
console.print("[yellow]💡 You can configure Git manually:[/yellow]")
console.print(" git config --global user.name 'Your Name'")
console.print(" git config --global user.email 'your.email@example.com'")
except Exception as e:
console.print(f"[red]❌ Git configuration error: {e}[/red]")
def _configure_preferences(self):
"""Configure user preferences and environment settings"""
console.print("[blue]⚙️ Configuring preferences...[/blue]")
# Ask about default build format
console.print("\n[blue]📚 Build Preferences:[/blue]")
console.print(" • [dim]html[/dim] - Web format (faster, interactive)")
console.print(" • [dim]pdf[/dim] - Print format (slower, academic)")
console.print("[bold]Default build format (html/pdf) [html]: [/bold]", end="")
default_format = input().strip().lower()
if not default_format or default_format not in ['html', 'pdf']:
default_format = 'html'
# Store preference
try:
subprocess.run(['git', 'config', '--global', 'binder.default-format', default_format], check=True)
console.print(f"[green]✅ Set default format: {default_format}[/green]")
except:
console.print(f"[yellow]⚠️ Could not save format preference[/yellow]")
# Ask about auto-open browser
console.print("\n[blue]🌐 Browser Preferences:[/blue]")
console.print("[bold]Auto-open browser after builds? (y/n) [y]: [/bold]", end="")
auto_open = input().strip().lower()
if not auto_open:
auto_open = 'y'
auto_open_setting = 'true' if auto_open in ['y', 'yes'] else 'false'
try:
subprocess.run(['git', 'config', '--global', 'binder.auto-open', auto_open_setting], check=True)
console.print(f"[green]✅ Auto-open browser: {auto_open_setting}[/green]")
except:
console.print(f"[yellow]⚠️ Could not save browser preference[/yellow]")
# Ask about AI features
console.print("\n[blue]🤖 AI Features:[/blue]")
console.print("[bold]Use AI for release notes by default? (y/n) [y]: [/bold]", end="")
ai_default = input().strip().lower()
if not ai_default:
ai_default = 'y'
ai_setting = 'true' if ai_default in ['y', 'yes'] else 'false'
try:
subprocess.run(['git', 'config', '--global', 'binder.ai-default', ai_setting], check=True)
console.print(f"[green]✅ AI release notes: {ai_setting}[/green]")
except:
console.print(f"[yellow]⚠️ Could not save AI preference[/yellow]")
console.print("[green]✅ Preferences configured![/green]")
def get_user_preferences(self):
"""Get user preferences from Git config"""
preferences = {}
try:
# Get default format
result = subprocess.run(['git', 'config', '--global', 'binder.default-format'],
capture_output=True, text=True)
if result.returncode == 0:
preferences['default_format'] = result.stdout.strip()
else:
preferences['default_format'] = 'html'
# Get auto-open setting
result = subprocess.run(['git', 'config', '--global', 'binder.auto-open'],
capture_output=True, text=True)
if result.returncode == 0:
preferences['auto_open'] = result.stdout.strip() == 'true'
else:
preferences['auto_open'] = True
# Get AI default setting
result = subprocess.run(['git', 'config', '--global', 'binder.ai-default'],
capture_output=True, text=True)
if result.returncode == 0:
preferences['ai_default'] = result.stdout.strip() == 'true'
else:
preferences['ai_default'] = True
# Get GitHub username
result = subprocess.run(['git', 'config', '--global', 'user.github'],
capture_output=True, text=True)
if result.returncode == 0:
preferences['github_username'] = result.stdout.strip()
else:
preferences['github_username'] = None
except Exception:
# Return defaults if anything fails
preferences = {
'default_format': 'html',
'auto_open': True,
'ai_default': True,
'github_username': None
}
return preferences
def _test_setup(self):
"""Test the setup by building a simple chapter"""