MCPcopy Create free account
hub / github.com/dotzero/git-profile / profileUpdateEntries

Function profileUpdateEntries

cmd/add.go:98–167  ·  view source on GitHub ↗

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),
)

Source from the content-addressed store, hash-verified

96
97//nolint:funlen
98func 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.")

Callers 1

addCommandFunction · 0.85

Calls 5

PrintlnFunction · 0.92
entriesToMapFunction · 0.85
LookupMethod · 0.65
StoreMethod · 0.65
SaveMethod · 0.65

Tested by

no test coverage detected