MCPcopy
hub / github.com/dnote/dnote / newRun

Function newRun

pkg/cli/cmd/login/login.go:146–184  ·  view source on GitHub ↗
(ctx context.DnoteCtx)

Source from the content-addressed store, hash-verified

144}
145
146func newRun(ctx context.DnoteCtx) infra.RunEFunc {
147 return func(cmd *cobra.Command, args []string) error {
148 // Override APIEndpoint if flag was provided
149 if apiEndpointFlag != "" {
150 ctx.APIEndpoint = apiEndpointFlag
151 }
152
153 greeting := getGreeting(ctx)
154 log.Plain(greeting)
155
156 email, err := getUsername()
157 if err != nil {
158 return errors.Wrap(err, "getting email input")
159 }
160
161 password, err := getPassword()
162 if err != nil {
163 return errors.Wrap(err, "getting password input")
164 }
165 if password == "" {
166 return errors.New("Password is empty")
167 }
168
169 log.Debug("Logging in with email: %s and password: (length %d)\n", email, len(password))
170
171 err = Do(ctx, email, password)
172 if errors.Cause(err) == client.ErrInvalidLogin {
173 log.Error("wrong login\n")
174 return nil
175 } else if err != nil {
176 return errors.Wrap(err, "logging in")
177 }
178
179 log.Success("logged in\n")
180
181 return nil
182 }
183
184}

Callers 1

NewCmdFunction · 0.70

Calls 9

PlainFunction · 0.92
DebugFunction · 0.92
ErrorFunction · 0.92
SuccessFunction · 0.92
getGreetingFunction · 0.85
getUsernameFunction · 0.85
getPasswordFunction · 0.85
NewMethod · 0.80
DoFunction · 0.70

Tested by

no test coverage detected