(ctx context.DnoteCtx)
| 144 | } |
| 145 | |
| 146 | func 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 | } |
no test coverage detected