nolint:funlen
( cmd *cobra.Command, cfg storage, filename string, promptProfileName func(io.Reader, io.Writer) (string, error), editProfileFields func(ui.ProfileFormData, io.Reader, io.Writer) (ui.ProfileFormData, error), )
| 96 | |
| 97 | //nolint:funlen |
| 98 | func profileUpdateEntries( |
| 99 | cmd *cobra.Command, |
| 100 | cfg storage, |
| 101 | filename string, |
| 102 | promptProfileName func(io.Reader, io.Writer) (string, error), |
| 103 | editProfileFields func(ui.ProfileFormData, io.Reader, io.Writer) (ui.ProfileFormData, error), |
| 104 | ) error { |
| 105 | profile, err := promptProfileName(cmd.InOrStdin(), cmd.OutOrStdout()) |
| 106 | if err != nil { |
| 107 | return err |
| 108 | } |
| 109 | |
| 110 | formData := ui.ProfileFormData{ |
| 111 | Profile: profile, |
| 112 | } |
| 113 | |
| 114 | if entries, ok := cfg.Lookup(profile); ok { |
| 115 | values := entriesToMap(entries) |
| 116 | formData.UserName = values[userNameKey] |
| 117 | formData.UserEmail = values[userEmailKey] |
| 118 | formData.UserSigningKey = values[userSigningKeyKey] |
| 119 | } |
| 120 | |
| 121 | result, err := editProfileFields(formData, cmd.InOrStdin(), cmd.OutOrStdout()) |
| 122 | if err != nil { |
| 123 | return err |
| 124 | } |
| 125 | |
| 126 | currentValues := map[string]string{} |
| 127 | if entries, ok := cfg.Lookup(result.Profile); ok { |
| 128 | currentValues = entriesToMap(entries) |
| 129 | } |
| 130 | |
| 131 | changed := 0 |
| 132 | |
| 133 | values := map[string]string{ |
| 134 | userNameKey: result.UserName, |
| 135 | userEmailKey: result.UserEmail, |
| 136 | userSigningKeyKey: result.UserSigningKey, |
| 137 | } |
| 138 | |
| 139 | for _, key := range []string{userNameKey, userEmailKey, userSigningKeyKey} { |
| 140 | value := strings.TrimSpace(values[key]) |
| 141 | if value == "" { |
| 142 | continue |
| 143 | } |
| 144 | |
| 145 | if currentValues[key] == value { |
| 146 | continue |
| 147 | } |
| 148 | |
| 149 | cfg.Store(result.Profile, key, value) |
| 150 | |
| 151 | changed++ |
| 152 | } |
| 153 | |
| 154 | if changed == 0 { |
| 155 | ui.Println(cmd, ui.SuccessStyle, "No profile changes to save.") |
no test coverage detected