Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commit0c839a4

Browse files
committed
fixup! Add gendocs ci step
1 parentedd2000 commit0c839a4

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
returncmd
3637
}
3738

38-
funcconfigSSH(filepath*string,remove*bool)func(cmd*cobra.Command,_ []string)error {
39+
funcconfigSSH(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
defercancel()
5354

54-
currentConfig,err:=readStr(*filepath)
55+
ifstrings.HasPrefix(*configpath,"~") {
56+
usr,err:=user.Current()
57+
iferr!=nil {
58+
returnxerrors.Errorf("get user home directory: %w",err)
59+
}
60+
*configpath=strings.Replace(*configpath,"~",usr.HomeDir,1)
61+
}
62+
63+
currentConfig,err:=readStr(*configpath)
5564
ifos.IsNotExist(err) {
5665
// SSH configs are not always already there.
5766
currentConfig=""
5867
}elseiferr!=nil {
59-
returnxerrors.Errorf("read ssh config file %q: %w",filepath,err)
68+
returnxerrors.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
iferr!=nil {
73-
returnxerrors.Errorf("write to ssh config file %q: %v",*filepath,err)
82+
returnxerrors.Errorf("write to ssh config file %q: %v",*configpath,err)
7483
}
7584

7685
returnnil
@@ -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
iferr!=nil {
110-
returnxerrors.Errorf("write new configurations to ssh config file %q: %w",filepath,err)
119+
returnxerrors.Errorf("write new configurations to ssh config file %q: %w",*configpath,err)
111120
}
112121
err=writeSSHKey(ctx,entClient)
113122
iferr!=nil {
114123
returnxerrors.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)

[8]ページ先頭

©2009-2025 Movatter.jp