-
Notifications
You must be signed in to change notification settings - Fork 76
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
Update delete project
and revert project
to include submodules of the project
#160
Conversation
- Created helper functions t.delete() and t.revert() for repetitive code.
…ted helper functions t.delete() and t.revert() for repetitive code.
| Argument | Description | | ||
| ------------- | ----------------------- | | ||
| `PROJECT KEY` | The key of the project. | |
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.
Oh wow, thanks for beautifying those tables! 😄
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.
Honestly, I don't know anything about this! It's not possible that I had accidentally merged someone else's work when I did a git fetch upstream
, is it?
My other guess is that my editor somehow interpreted these as snippets and automatically formatted the markdown tables. 😅
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.
Honestly, I don't know anything about this! It's not possible that I had accidentally merged someone else's work when I did a git fetch upstream, is it?
No, you would have to fetch that particular contributor's fork and merge their commits into your branch - and if you do so, that contributor still appears as the author of those commits in your PR. Which editor are you using? 😄
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 see, that makes sense. And day by day I see more of the genius that went into creating git!
I'm using Neovim, specifically Lunarvim which provides an IDE layer on top of Neovim.
Sorry for the numerous commits!!! I am still figuring out git... The latest commits are WIP addressing #161. The The main challenge that I had was retrieving the records for the submodules in addition to the records for the parent project (since we are now also deleting submodules by default, the option to include records in the delete should also include the submodule records). I wonder if there's a better way to do it than the nested |
I would greatly appreciate some feedback on whether I've been going about this correctly, before proceeding to work on the updates to the Thanks! |
Deleting the records of the submodules along with the records of the actual project makes sense and is consistent, so this is fine. I'm afraid there isn't a better way to delete the records other than using those nested loops. There might be some tricky performance tweak using a map to solve this more efficiently, but I don't see an easy option at the moment.
I think you're solving this correctly and just as expected! The only thing I'm getting more and more concerned of is that the |
BTW, I moved this PR from milestone v0.12.0 to v0.13.0 since the 0.12.0 release got pretty bloated. I'm going to release 0.12.0 with some minor changes, e.g. two new flags. Once those things are cleaned up, I'm going to release 0.13.0 with those more impactful features. |
Thanks, glad to know that I'm on the right track!
With respect to this PR, I added one method
That's just as well; I will take a little bit more time to work on the remaining I'd also just like to say thanks again for this project. I'm finding good utility for it as a user and good learning from working on the code as well. |
Creating a more generic function that takes filter arguments is a nice idea. type ProjectType int
const (
All ProjectType = 0
Active ProjectType = 1
Bak ProjectType = 2
)
func ProjectFilepaths(projectTypes ...ProjectType) []string {
for _, project := range myProjects {
for _, projectType := range projectTypes {
// ... Filter by project type
}
}
}
// Calling the function:
paths := ProjectFilepaths(Active, Bak) But I'm going to create a separate issue for this. |
Yes this is what I was thinking but didn't know how to express quite as clearly in code, didn't think to just write out a code snippet 😅 Is this what is known as an enum in other languages? Is this const declaration block possible to do using iota? And would that be equivalent to simply assigning integer values to each constant? |
Yes, they're the equivalent to enumerations.
We even should do it with
Yes, since |
Hello, in my last commit, Question 1: I think the answer may not be so straightforward as illustrated in the following scenario:
(I don't know why anyone would do things this way but it is a possibility.) Question 2:
Question 3: If through flags, would it make sense to add a new flag, for eg |
Restoring the records isn't a must-have requirement for me, but a nice-to-have for sure. 1) Your edge case is a good point. In that case, it indeed would make sense to require a flag for restoring the records and ask for confirmation, warning that the edited records will be overwritten - except 2) would actually work, which would be a bit crazy but powerful 😄 3) I'm not sure on this yet. Maybe it would make sense to introduce a |
When I first came across the After thinking about this problem a little more I think I may have a clean solution, and would love to hear your thoughts on this:
|
Your ideas absolutely make sense 👍 I think flag combinations like |
Hello! If the |
@@ -44,6 +52,15 @@ func deleteProjectCommand(t *core.Timetrace) *cobra.Command { | |||
key := args[0] | |||
|
|||
if options.Revert { | |||
if !options.ExcludeRecords && askForConfirmation(revertRecordsWarning) { |
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.
Note: We may outsource this entire block into a dedicated revertProject
function later.
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 just left some comments regarding smaller optimizations. Thanks for working on this super-powerful feature!
core/record.go
Outdated
// check for records that match project key and revert record | ||
if len(records) > 0 { | ||
for _, k := range keys { | ||
for _, record := range records { |
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 think we already discussed this; ranging over all records for all projects is insanely inefficient, but there's no other way to do this ATM. We'll need to find a solution with much better runtime performance for the future.
If you have ideas for this, just open an issue (same goes for @aligator) 👍
Co-authored-by: Dominik Braun <mail@dominikbraun.io>
Co-authored-by: Dominik Braun <mail@dominikbraun.io>
Thanks for the review! In particular I learnt something about the behaviour about the I have added a new commit implementing the suggested changes. |
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 fixing those issues! I'm going to merge this large PR now, re-test everything and see if there are some things left to do. Once this is done, it will be released as part of timetrace v0.13.0!
@dominikbraun looks about right. Don't think you've missed anything! |
This PR is contained in timetrace v0.13.0. |
This PR addresses #74.
I thought that if we delete submodules by default, it would make sense if
--revert
would also revert submodules, and so created additional functions for that even though that was not asked for. If you think--revert
should not revert submodules by default, let me know and I'll be happy to amend the commit.