From bea551db1edef71d11353af9232b8226b912c8c9 Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 19 Aug 2025 19:49:47 +0300 Subject: [PATCH 1/4] feat: add address for create --- internal/command/create.go | 1 + internal/component/create/create.go | 6 ++++++ internal/component/create/fields.go | 1 + 3 files changed, 8 insertions(+) diff --git a/internal/command/create.go b/internal/command/create.go index 7aa4b61..4c8e242 100644 --- a/internal/command/create.go +++ b/internal/command/create.go @@ -33,6 +33,7 @@ var createCmd = &cobra.Command{ connection := &connect.Connect{ Alias: fields.Alias, Login: fields.Login, + Address: fields.Address, Password: fields.Password, CreatedAt: time.Now().Format("2006.01.02 15:04:05"), UpdatedAt: time.Now().Format("2006.01.02 15:04:05"), diff --git a/internal/component/create/create.go b/internal/component/create/create.go index 200948a..077893e 100644 --- a/internal/component/create/create.go +++ b/internal/component/create/create.go @@ -44,6 +44,12 @@ func Run() (*Fields, error) { Validate(huh.ValidateNotEmpty()). Value(&fields.Login), + huh.NewInput(). + Title("Address"). + Description("Address of the remote machine"). + Validate(huh.ValidateNotEmpty()). + Value(&fields.Address), + huh.NewInput(). Title("Port"). Description("Port number to connect to a remote machine"). diff --git a/internal/component/create/fields.go b/internal/component/create/fields.go index 24be5ce..afb4d16 100644 --- a/internal/component/create/fields.go +++ b/internal/component/create/fields.go @@ -4,6 +4,7 @@ package create type Fields struct { Alias string Login string + Address string Password string Port int PrivateKey string From 40c43a97bec16bbc5f53e8b3a74a8cb07bd49109 Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 19 Aug 2025 19:49:53 +0300 Subject: [PATCH 2/4] feat: add address for update --- internal/command/update.go | 1 + internal/component/update/fields.go | 1 + internal/component/update/update.go | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/internal/command/update.go b/internal/command/update.go index 9c34e12..6defe72 100644 --- a/internal/command/update.go +++ b/internal/command/update.go @@ -45,6 +45,7 @@ var updateCmd = &cobra.Command{ updatedConnection := &connect.Connect{ Alias: fields.Alias, Login: fields.Login, + Address: fields.Address, Password: fields.Password, UpdatedAt: time.Now().Format("2006.01.02 15:04:05"), CreatedAt: selectedConn.CreatedAt, diff --git a/internal/component/update/fields.go b/internal/component/update/fields.go index 3abea67..6b91d90 100644 --- a/internal/component/update/fields.go +++ b/internal/component/update/fields.go @@ -4,6 +4,7 @@ package update type Fields struct { Alias string Login string + Address string Password string Port int PrivateKey string diff --git a/internal/component/update/update.go b/internal/component/update/update.go index 61dd317..0d04585 100644 --- a/internal/component/update/update.go +++ b/internal/component/update/update.go @@ -55,6 +55,12 @@ func Run(connection *connect.Connect) (*Fields, error) { Validate(huh.ValidateNotEmpty()). Value(&updatedConn.Login), + huh.NewInput(). + Title("Address"). + Description("Address of the remote machine"). + Validate(huh.ValidateNotEmpty()). + Value(&updatedConn.Address), + huh.NewInput(). Title("Port"). Description("Port number to connect to a remote machine"). @@ -99,6 +105,7 @@ func Run(connection *connect.Connect) (*Fields, error) { fields.Alias = updatedConn.Alias fields.Login = updatedConn.Login + fields.Address = updatedConn.Address fields.Port = intPort fields.Password = updatedConn.Password fields.PrivateKey = updatedConn.SshOptions.PrivateKey From cefc8370aba66360835ade7d168d1a26487fb00f Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 19 Aug 2025 22:31:02 +0300 Subject: [PATCH 3/4] feat: add picking --- internal/component/create/create.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/component/create/create.go b/internal/component/create/create.go index 077893e..06967e0 100644 --- a/internal/component/create/create.go +++ b/internal/component/create/create.go @@ -78,7 +78,8 @@ func Run() (*Fields, error) { Description("select file with private key"). CurrentDirectory(homedir). Validate(privateKeyValidate). - Value(&fields.PrivateKey), + Value(&fields.PrivateKey). + Picking(true), ).WithHideFunc(func() bool { return authPassConfirm }), From 417b325067c8b6d5e089e5eee19d34e2736bd4b7 Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 19 Aug 2025 22:31:55 +0300 Subject: [PATCH 4/4] fix: change logic update private key --- internal/component/update/update.go | 43 ++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/internal/component/update/update.go b/internal/component/update/update.go index 0d04585..2cc55bb 100644 --- a/internal/component/update/update.go +++ b/internal/component/update/update.go @@ -18,13 +18,19 @@ var ( // Run get form for update connect.Connect func Run(connection *connect.Connect) (*Fields, error) { var authPassConfirm bool + var updatedPrivateKey bool updatedConn := *connection - if len(updatedConn.Password) > 0 { + hasOriginalPrivateKey := len(connection.SshOptions.PrivateKey) > 0 + hasOriginalPassword := len(connection.Password) > 0 + + if hasOriginalPassword { authPassConfirm = true - } else if len(updatedConn.SshOptions.PrivateKey) > 0 { + } else if hasOriginalPrivateKey { authPassConfirm = false + } else { + authPassConfirm = true } homedir, err := os.UserHomeDir() @@ -83,15 +89,34 @@ func Run(connection *connect.Connect) (*Fields, error) { ).WithHideFunc(func() bool { return !authPassConfirm }), + huh.NewGroup( + huh.NewConfirm(). + Title("Update private key?"). + Description("Do you want to update the private key?"). + Affirmative("Yes"). + Negative("No"). + Value(&updatedPrivateKey), + ).WithHideFunc(func() bool { + return authPassConfirm || !hasOriginalPrivateKey + }), huh.NewGroup( huh.NewFilePicker(). Title("PrivateKey"). - Description("select file with private key"). + Description("Select file with private key"). CurrentDirectory(homedir). Validate(privateKeyValidate). - Value(&updatedConn.SshOptions.PrivateKey), + Value(&updatedConn.SshOptions.PrivateKey). + Picking(true), ).WithHideFunc(func() bool { - return authPassConfirm + if authPassConfirm { + return true + } + + if hasOriginalPrivateKey { + return !updatedPrivateKey + } + + return false }), ).WithShowHelp(true).Run() if err != nil { @@ -110,11 +135,15 @@ func Run(connection *connect.Connect) (*Fields, error) { fields.Password = updatedConn.Password fields.PrivateKey = updatedConn.SshOptions.PrivateKey - if len(connection.Password) > 0 && !authPassConfirm { + if hasOriginalPrivateKey && !updatedPrivateKey && !authPassConfirm { + fields.PrivateKey = connection.SshOptions.PrivateKey + } + + if hasOriginalPassword && !authPassConfirm { fields.Password = "" } - if len(updatedConn.SshOptions.PrivateKey) > 0 && authPassConfirm { + if hasOriginalPrivateKey && authPassConfirm { fields.PrivateKey = "" }