New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MM-19066] Added user list
command
#34
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @njkevlani!! It looks very good, a few changes noted.
Would you be open to add some unit tests for these PR? You can take inspiration on the search channel command test
Sure, will do that. |
To report an error if there are any positional args
Tests added. Let me know if this seems fine :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the addition of the tests @njkevlani!!
Co-Authored-By: Miguel de la Cruz <mgdelacroix@gmail.com>
* Replace printer.Flush() with printer.Clean() * Added printer.Flush() in first test case as well * Added one more mock call when --all flag is passed
This issue has been automatically labelled "stale" because it hasn't had recent activity. /cc @jasonblais @hanzei |
@njkevlani Would you please merge |
@hanzei master branch is merged into this branch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes @njkevlani, LGTM 👍
ping @mkraft |
commands/user.go
Outdated
showAll, _ := command.Flags().GetBool("all") | ||
|
||
tpl := `{{.Id}}: {{.Username}} ({{.Email}})` | ||
for users, _ := c.GetUsers(page, perPage, ""); users != nil && len(users) > 0; users, _ = c.GetUsers(page, perPage, "") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason we're using the blank identifier for these GetUsers
errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no particular reason behind that. I guess we can handle that response like following:
if response.Error != nil {
printer.PrintError("Unable list all users.\n " + response.Error.Error())
}
Let me know if this seems fine or it can be improved :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@njkevlani would you be open to help with @mkraft's question above? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @jasonblais,
Actually I have suggested what should be changed in my last comment, but haven't got any confirmation on that. Can you please check that out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also have the same question. We should check the error and bubble that above.
And this logic still uses the page
number if showAll is set. What we should probably do is:
if showAll {
page = 0
}
And then loop through c.GetUsers
until it runs out of users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will commit & push soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'll check for error and bubble that up.
if response.Error != nil {
return errors.Wrap(response.Error, "Failed to fetch users")
}
- Sort import - Typo fix - Utilized `EqualError` rather than using `Equal` - Added one more test
We are nearly there. Just one outstanding comment to clarify. And please fix the merge conflicts. Thanks ! |
Does this reply answer the question in linked comment? |
That doesn't link to a comment for me. :( Feel free to just paste the comment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, perhaps there is some miscommunication amongst us. I meant why do we need to call the GetUsers method twice. Does something like this work ?
for {
users, res := c.GetUsers(page, perPage, "")
if res.Error != nil {
return errors.Wrap(...)
}
if len(users) == 0 {
break
}
for _, user := range users {
printer.PrintT(tpl, user)
}
if !showAll {
break
}
page++
}
check for error in server response outside of loop
Yes, this would work fine. I guess the difference in this approach any my previous code is that,
Anyway, I have made changes in code. Let me know if all look good. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your patience on this @njkevlani !
Thanks for feedback on this, got to learn some things :) @agnivade |
…19066 � Conflicts: � client/client.go � commands/user_test.go � mocks/client_mock.go
@mgdelacroix any updates? |
@njkevlani thanks a lot for all the changes you've implemented! Can you please run |
Done :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Will try to auto merge this PR once all tests and checks are passing. This might take up to an hour. |
1 similar comment
Will try to auto merge this PR once all tests and checks are passing. This might take up to an hour. |
Trying to auto merge this PR. |
Pull Request successfully merged |
Fixes mattermost/mattermost#12965