Skip to content
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

Allow action on multiple items at once #242

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tcassaert
Copy link
Contributor

This PR allows (un)archiving, (un)completing, deleting, (un)prioritizing multiple items at once.

With this PR, you can now do

ultralist complete 1 2 3

Before these changes, it would only do the action on the first ID.

@gammons
Copy link
Owner

gammons commented Nov 12, 2020

ah, great catch @tcassaert !

One of the things I've been doing recently is making the app a bit more resilient to open-ended input. We added the cobra library recently, and that's been a huge help with separating concerns.

I'm wondering if it makes sense to have these methods (CompleteTodo, ArchiveTodo, etc) take arrays of ints rather than a string input. Then the Run functions from cobra could instead send an array of ints, rather than the raw input.

We'd still need to validate that the todo IDs exist, but I feel like that'd be a relatively easy refactor of app.getIDs.

Let me know if that makes sense!

@tcassaert
Copy link
Contributor Author

The cobra library is great! I've used it too, for a little project when I was trying to learn Golang.
I've used it together with viper (https://github.com/spf13/viper) for argument passing. Not sure if that would be a good fit here... It would be for things like --archive, but not sure how it handles input without a flag.

What difference would it make, to let them take an array of ints? Would we then do

ultralist complete 1,2,3

or how do you see that?

@gammons
Copy link
Owner

gammons commented Nov 16, 2020

So I was thinking that the syntax would still be what you originally proposed:

ultralist complete 1 2 3

And then here,

https://github.com/ultralist/ultralist/blob/7784c597dd7a94bca319d4be369a3218d8acd54c/cmd/complete.go#L36

..sending along the array of ints to the App:

ultralist.NewApp().CompleteTodo(strings, archiveCompletedTodo)

Since the cmd functions already have the args in an array, there's no need to join them together, only to re-separate them once they are in App. Does that make sense?

@gammons
Copy link
Owner

gammons commented Nov 16, 2020

Just to give a bit more context -

in App there is a CompleteTodo function, which currently takes a free-form string:

https://github.com/ultralist/ultralist/blob/7784c597dd7a94bca319d4be369a3218d8acd54c/ultralist/app.go#L100

It then runs getIDs to parse out the ids, make sure they exist, etc. It does this by breaking apart the input into an array. What I'm saying is, we don't necessarily need to do that step, since the cobra library already has the args as an array. We can just pass that into CompleteTodo.

@tcassaert
Copy link
Contributor Author

Alright, I now get it, thanks for clarifying!

It does seem a good improvement. If cobra already does it, there's no need to reinvent the wheel and do the conversion ourselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants