ssh_theater: ask the user before editing config
diff --git a/dockerimg/ssh_theater.go b/dockerimg/ssh_theater.go
index 69e63de..6afcfc9 100644
--- a/dockerimg/ssh_theater.go
+++ b/dockerimg/ssh_theater.go
@@ -125,7 +125,7 @@
return cst, nil
}
-func CheckForIncludeWithFS(fs FileSystem) error {
+func CheckForIncludeWithFS(fs FileSystem, stdinReader bufio.Reader) error {
sketchSSHPathInclude := "Include " + filepath.Join(os.Getenv("HOME"), ".config", "sketch", "ssh_config")
defaultSSHPath := filepath.Join(os.Getenv("HOME"), ".ssh", "config")
@@ -163,6 +163,14 @@
}
if sketchInludePos == nil {
+ fmt.Printf("\nTo enable you to use ssh to connect to local sketch containers: \nAdd %q to the top of %s [y/N]? ", sketchSSHPathInclude, defaultSSHPath)
+ char, _, err := stdinReader.ReadRune()
+ if err != nil {
+ return fmt.Errorf("couldn't read from stdin: %w", err)
+ }
+ if char != 'y' && char != 'Y' {
+ return fmt.Errorf("User declined to edit ssh config file")
+ }
// Include line not found, add it to the top of the file
cfgBytes, err := cfg.MarshalText()
if err != nil {
@@ -557,5 +565,5 @@
// CheckForInclude checks if the user's SSH config includes the Sketch SSH config file
func CheckForInclude() error {
- return CheckForIncludeWithFS(&RealFileSystem{})
+ return CheckForIncludeWithFS(&RealFileSystem{}, *bufio.NewReader(os.Stdin))
}