Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/command/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
1 change: 1 addition & 0 deletions internal/command/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion internal/component/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down Expand Up @@ -72,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
}),
Expand Down
1 change: 1 addition & 0 deletions internal/component/create/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package create
type Fields struct {
Alias string
Login string
Address string
Password string
Port int
PrivateKey string
Expand Down
1 change: 1 addition & 0 deletions internal/component/update/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package update
type Fields struct {
Alias string
Login string
Address string
Password string
Port int
PrivateKey string
Expand Down
50 changes: 43 additions & 7 deletions internal/component/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -55,6 +61,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").
Expand All @@ -77,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 {
Expand All @@ -99,15 +130,20 @@ 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

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 = ""
}

Expand Down
Loading