Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 0c839a4

Browse files
committed
fixup! Add gendocs ci step
1 parent edd2000 commit 0c839a4

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

internal/cmd/configssh.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net"
88
"net/url"
99
"os"
10+
"os/user"
1011
"path/filepath"
1112
"strings"
1213
"time"
@@ -35,7 +36,7 @@ func makeConfigSSHCmd() *cobra.Command {
3536
return cmd
3637
}
3738

38-
func configSSH(filepath *string, remove *bool) func(cmd *cobra.Command, _ []string) error {
39+
func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []string) error {
3940
startToken := "# ------------START-CODER-ENTERPRISE-----------"
4041
startMessage := `# The following has been auto-generated by "coder config-ssh"
4142
# to make accessing your Coder Enterprise environments easier.
@@ -51,12 +52,20 @@ func configSSH(filepath *string, remove *bool) func(cmd *cobra.Command, _ []stri
5152
ctx, cancel := context.WithCancel(context.Background())
5253
defer cancel()
5354

54-
currentConfig, err := readStr(*filepath)
55+
if strings.HasPrefix(*configpath, "~") {
56+
usr, err := user.Current()
57+
if err != nil {
58+
return xerrors.Errorf("get user home directory: %w", err)
59+
}
60+
*configpath = strings.Replace(*configpath, "~", usr.HomeDir, 1)
61+
}
62+
63+
currentConfig, err := readStr(*configpath)
5564
if os.IsNotExist(err) {
5665
// SSH configs are not always already there.
5766
currentConfig = ""
5867
} else if err != nil {
59-
return xerrors.Errorf("read ssh config file %q: %w", filepath, err)
68+
return xerrors.Errorf("read ssh config file %q: %w", configpath, err)
6069
}
6170

6271
startIndex := strings.Index(currentConfig, startToken)
@@ -68,9 +77,9 @@ func configSSH(filepath *string, remove *bool) func(cmd *cobra.Command, _ []stri
6877
}
6978
currentConfig = currentConfig[:startIndex-1] + currentConfig[endIndex+len(endToken)+1:]
7079

71-
err = writeStr(*filepath, currentConfig)
80+
err = writeStr(*configpath, currentConfig)
7281
if err != nil {
73-
return xerrors.Errorf("write to ssh config file %q: %v", *filepath, err)
82+
return xerrors.Errorf("write to ssh config file %q: %v", *configpath, err)
7483
}
7584

7685
return nil
@@ -105,16 +114,16 @@ func configSSH(filepath *string, remove *bool) func(cmd *cobra.Command, _ []stri
105114
currentConfig = currentConfig[:startIndex-1] + currentConfig[endIndex+len(endToken)+1:]
106115
}
107116

108-
err = writeStr(*filepath, currentConfig+newConfig)
117+
err = writeStr(*configpath, currentConfig+newConfig)
109118
if err != nil {
110-
return xerrors.Errorf("write new configurations to ssh config file %q: %w", filepath, err)
119+
return xerrors.Errorf("write new configurations to ssh config file %q: %w", *configpath, err)
111120
}
112121
err = writeSSHKey(ctx, entClient)
113122
if err != nil {
114123
return xerrors.Errorf("fetch and write ssh key: %w", err)
115124
}
116125

117-
fmt.Printf("An auto-generated ssh config was written to %q\n", *filepath)
126+
fmt.Printf("An auto-generated ssh config was written to %q\n", *configpath)
118127
fmt.Printf("Your private ssh key was written to %q\n", privateKeyFilepath)
119128
fmt.Println("You should now be able to ssh into your environment")
120129
fmt.Printf("For example, try running\n\n\t$ ssh coder.%s\n\n", envs[0].Name)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy