Skip to content

Commit 21efdca

Browse files
authored
Show warning when cloning into $HOME (#48)
1 parent c2c096b commit 21efdca

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

trainings/init.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,26 @@ func hasGo() bool {
495495
}
496496

497497
func (h *Handlers) showTrainingStartPrompt(trainingDir string) error {
498+
homeDir, _ := os.UserHomeDir()
499+
if homeDir != "" {
500+
absTrainingDir, err := filepath.Abs(trainingDir)
501+
if err == nil && absTrainingDir == homeDir {
502+
if !internal.IsStdinTerminal() {
503+
return fmt.Errorf("refusing to init in home directory %s — create a subdirectory first", homeDir)
504+
}
505+
506+
fmt.Println()
507+
fmt.Println(color.YellowString(" ⚠ Warning: you are about to clone training files directly into your home directory (%s).", homeDir))
508+
fmt.Println(color.YellowString(" This is almost never what you want. We recommend creating a subdirectory instead."))
509+
fmt.Println()
510+
511+
if !internal.FConfirmPrompt(color.YellowString("Are you sure you want to continue?"), os.Stdin, os.Stdout) {
512+
return ErrInterrupted
513+
}
514+
return nil
515+
}
516+
}
517+
498518
fmt.Printf(
499519
"This command will clone training source code to %s directory.\n",
500520
trainingDir,

0 commit comments

Comments
 (0)