@@ -18,13 +18,19 @@ var (
1818// Run get form for update connect.Connect
1919func Run (connection * connect.Connect ) (* Fields , error ) {
2020 var authPassConfirm bool
21+ var updatedPrivateKey bool
2122
2223 updatedConn := * connection
2324
24- if len (updatedConn .Password ) > 0 {
25+ hasOriginalPrivateKey := len (connection .SshOptions .PrivateKey ) > 0
26+ hasOriginalPassword := len (connection .Password ) > 0
27+
28+ if hasOriginalPassword {
2529 authPassConfirm = true
26- } else if len ( updatedConn . SshOptions . PrivateKey ) > 0 {
30+ } else if hasOriginalPrivateKey {
2731 authPassConfirm = false
32+ } else {
33+ authPassConfirm = true
2834 }
2935
3036 homedir , err := os .UserHomeDir ()
@@ -55,6 +61,12 @@ func Run(connection *connect.Connect) (*Fields, error) {
5561 Validate (huh .ValidateNotEmpty ()).
5662 Value (& updatedConn .Login ),
5763
64+ huh .NewInput ().
65+ Title ("Address" ).
66+ Description ("Address of the remote machine" ).
67+ Validate (huh .ValidateNotEmpty ()).
68+ Value (& updatedConn .Address ),
69+
5870 huh .NewInput ().
5971 Title ("Port" ).
6072 Description ("Port number to connect to a remote machine" ).
@@ -77,15 +89,34 @@ func Run(connection *connect.Connect) (*Fields, error) {
7789 ).WithHideFunc (func () bool {
7890 return ! authPassConfirm
7991 }),
92+ huh .NewGroup (
93+ huh .NewConfirm ().
94+ Title ("Update private key?" ).
95+ Description ("Do you want to update the private key?" ).
96+ Affirmative ("Yes" ).
97+ Negative ("No" ).
98+ Value (& updatedPrivateKey ),
99+ ).WithHideFunc (func () bool {
100+ return authPassConfirm || ! hasOriginalPrivateKey
101+ }),
80102 huh .NewGroup (
81103 huh .NewFilePicker ().
82104 Title ("PrivateKey" ).
83- Description ("select file with private key" ).
105+ Description ("Select file with private key" ).
84106 CurrentDirectory (homedir ).
85107 Validate (privateKeyValidate ).
86- Value (& updatedConn .SshOptions .PrivateKey ),
108+ Value (& updatedConn .SshOptions .PrivateKey ).
109+ Picking (true ),
87110 ).WithHideFunc (func () bool {
88- return authPassConfirm
111+ if authPassConfirm {
112+ return true
113+ }
114+
115+ if hasOriginalPrivateKey {
116+ return ! updatedPrivateKey
117+ }
118+
119+ return false
89120 }),
90121 ).WithShowHelp (true ).Run ()
91122 if err != nil {
@@ -99,15 +130,20 @@ func Run(connection *connect.Connect) (*Fields, error) {
99130
100131 fields .Alias = updatedConn .Alias
101132 fields .Login = updatedConn .Login
133+ fields .Address = updatedConn .Address
102134 fields .Port = intPort
103135 fields .Password = updatedConn .Password
104136 fields .PrivateKey = updatedConn .SshOptions .PrivateKey
105137
106- if len (connection .Password ) > 0 && ! authPassConfirm {
138+ if hasOriginalPrivateKey && ! updatedPrivateKey && ! authPassConfirm {
139+ fields .PrivateKey = connection .SshOptions .PrivateKey
140+ }
141+
142+ if hasOriginalPassword && ! authPassConfirm {
107143 fields .Password = ""
108144 }
109145
110- if len ( updatedConn . SshOptions . PrivateKey ) > 0 && authPassConfirm {
146+ if hasOriginalPrivateKey && authPassConfirm {
111147 fields .PrivateKey = ""
112148 }
113149
0 commit comments