feat(bootstrap): add automatic environment setup with bootstrap scripts

Implement bootstrap functionality for streamlined dotfiles setup:
- Add 'bootstrap' command to run setup scripts manually
- Auto-execute bootstrap on 'init' with remote (--no-bootstrap to skip)
- Update README with bootstrap usage and examples
- Extend tests to cover bootstrap scenarios
This commit is contained in:
Yar Kravtsov
2025-06-03 08:33:59 +03:00
parent 1e2c9704f3
commit ae9cc175ce
7 changed files with 441 additions and 15 deletions

45
cmd/bootstrap.go Normal file
View File

@@ -0,0 +1,45 @@
package cmd
import (
"github.com/spf13/cobra"
"github.com/yarlson/lnk/internal/core"
)
func newBootstrapCmd() *cobra.Command {
return &cobra.Command{
Use: "bootstrap",
Short: "🚀 Run the bootstrap script to set up your environment",
Long: "Executes the bootstrap script from your dotfiles repository to install dependencies and configure your system.",
SilenceUsage: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
lnk := core.NewLnk()
scriptPath, err := lnk.FindBootstrapScript()
if err != nil {
return err
}
if scriptPath == "" {
printf(cmd, "💡 \033[33mNo bootstrap script found\033[0m\n")
printf(cmd, " 📝 Create a \033[1mbootstrap.sh\033[0m file in your dotfiles repository:\n")
printf(cmd, " \033[90m#!/bin/bash\033[0m\n")
printf(cmd, " \033[90mecho \"Setting up environment...\"\033[0m\n")
printf(cmd, " \033[90m# Your setup commands here\033[0m\n")
return nil
}
printf(cmd, "🚀 \033[1mRunning bootstrap script\033[0m\n")
printf(cmd, " 📄 Script: \033[36m%s\033[0m\n", scriptPath)
printf(cmd, "\n")
if err := lnk.RunBootstrapScript(scriptPath); err != nil {
return err
}
printf(cmd, "\n✅ \033[1;32mBootstrap completed successfully!\033[0m\n")
printf(cmd, " 🎉 Your environment is ready to use\n")
return nil
},
}
}