mirror of
https://github.com/yarlson/lnk.git
synced 2025-08-30 17:59:47 +02:00
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:
29
cmd/init.go
29
cmd/init.go
@@ -14,6 +14,7 @@ func newInitCmd() *cobra.Command {
|
||||
SilenceErrors: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
remote, _ := cmd.Flags().GetString("remote")
|
||||
noBootstrap, _ := cmd.Flags().GetBool("no-bootstrap")
|
||||
|
||||
lnk := core.NewLnk()
|
||||
if err := lnk.InitWithRemote(remote); err != nil {
|
||||
@@ -24,6 +25,33 @@ func newInitCmd() *cobra.Command {
|
||||
printf(cmd, "🎯 \033[1mInitialized lnk repository\033[0m\n")
|
||||
printf(cmd, " 📦 Cloned from: \033[36m%s\033[0m\n", remote)
|
||||
printf(cmd, " 📁 Location: \033[90m~/.config/lnk\033[0m\n")
|
||||
|
||||
// Try to run bootstrap script if not disabled
|
||||
if !noBootstrap {
|
||||
printf(cmd, "\n🔍 \033[1mLooking for bootstrap script...\033[0m\n")
|
||||
|
||||
scriptPath, err := lnk.FindBootstrapScript()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if scriptPath != "" {
|
||||
printf(cmd, " ✅ Found bootstrap script: \033[36m%s\033[0m\n", scriptPath)
|
||||
printf(cmd, "\n🚀 \033[1mRunning bootstrap script...\033[0m\n")
|
||||
printf(cmd, "\n")
|
||||
|
||||
if err := lnk.RunBootstrapScript(scriptPath); err != nil {
|
||||
printf(cmd, "\n⚠️ \033[33mBootstrap script failed, but repository was initialized successfully\033[0m\n")
|
||||
printf(cmd, " 💡 You can run it manually with: \033[1mlnk bootstrap\033[0m\n")
|
||||
printf(cmd, " 🔧 Error: %v\n", err)
|
||||
} else {
|
||||
printf(cmd, "\n✅ \033[1;32mBootstrap completed successfully!\033[0m\n")
|
||||
}
|
||||
} else {
|
||||
printf(cmd, " 💡 No bootstrap script found\n")
|
||||
}
|
||||
}
|
||||
|
||||
printf(cmd, "\n💡 \033[33mNext steps:\033[0m\n")
|
||||
printf(cmd, " • Run \033[1mlnk pull\033[0m to restore symlinks\n")
|
||||
printf(cmd, " • Use \033[1mlnk add <file>\033[0m to manage new files\n")
|
||||
@@ -40,5 +68,6 @@ func newInitCmd() *cobra.Command {
|
||||
}
|
||||
|
||||
cmd.Flags().StringP("remote", "r", "", "Clone from remote URL instead of creating empty repository")
|
||||
cmd.Flags().Bool("no-bootstrap", false, "Skip automatic execution of bootstrap script after cloning")
|
||||
return cmd
|
||||
}
|
||||
|
Reference in New Issue
Block a user