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

Support for parameters with arguments #159

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

rzikm
Copy link
Contributor

@rzikm rzikm commented Apr 30, 2024

Was playing around with gitu and wanted to refresh some of the Rust I know. This is a very rough sketch which allows me to add arguments to flags (such as git log -n256 or in the future for git log -S).

It's far from optimal, or production quality, just wanted to float it out there and see if you agree with the direction I took. We can iterate from there.

@rzikm rzikm changed the title Support value arguments Support for parameters with arguments Apr 30, 2024
Copy link
Owner

@altsem altsem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
I think it looks pretty good! Happy to see you pick this up, arguments with values is kind of a missing feature.

See if the comments make any sense.

src/menu/arg.rs Outdated Show resolved Hide resolved
src/menu/arg.rs Outdated Show resolved Hide resolved
src/menu/arg.rs Outdated Show resolved Hide resolved
src/menu/arg.rs Outdated Show resolved Hide resolved
src/ops/mod.rs Outdated Show resolved Hide resolved
src/ops/log.rs Outdated Show resolved Hide resolved
@altsem
Copy link
Owner

altsem commented May 2, 2024

@rzikm Code looks good I think. Just some clippy complaints, "feat: " missing, tests.

src/ops/log.rs Outdated Show resolved Hide resolved
@rzikm
Copy link
Contributor Author

rzikm commented May 8, 2024

Did some work on this, I am not happy with how the Arg structure turned out, the fact that we need the Arg::new* functions be complicates it a bit. Maybe if we make it into a get_items() instead, I could simplify Arg a lot.

Anyway, it turns out this change greatly speeds up log screen because we no longer try to read the entire history :D very noticeable on Windows on large repos.

I removed the -S parameter for now, and added -F instead so that it can be checked that the shape works for other arg types.

@rzikm rzikm requested a review from altsem May 9, 2024 11:33
@rzikm
Copy link
Contributor Author

rzikm commented May 9, 2024

Got nerdsniped by this, so I reworked it a bit to allow arbitrary values without need for further Arg changes (that is, unless we want to add parameter completion or list of choices). Still had to fight the Borrow checker on few occasions so there may be some unnecessary copies involved, which I am unable to get rid off.

Should be good for another review

@altsem
Copy link
Owner

altsem commented May 11, 2024

@rzikm I've been busy with work recently, I'll try find some time soon to look at it.

Copy link
Owner

@altsem altsem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dug around a bit. I managed to remove the need to implement Clone! :) It's over at the branch altsem/value-arguments.

I had some idea that the tests could:

  • Create some commits (there's a commit helper function).
  • Limit log to a number less than these commits (We've tested that limiting somewhat works).

Same with grepping:

  • Create two commits, e.g. "Commit 1", "Another commit"
  • Grep for "Another"
  • Only one should be in the log!

I think it would be nice to flatten a few structs maybe. Could dig around a lot. But at some point I'm all for merging this into master and take it from there, it doesn't have to be perfect initially :)

src/menu.rs Outdated
Menu::Rebase => ops::rebase::get_args(),
Menu::Reset => ops::reset::get_args(),
Menu::Revert => ops::revert::get_args(),
Menu::Stash => ops::stash::get_args(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps they should be called init_args? Just to make it clear that it's creating them anew.

@rzikm
Copy link
Contributor Author

rzikm commented May 15, 2024

Thanks a lot, now it looks reasonable to me,

I added some tests as asked.

@rzikm rzikm requested a review from altsem May 15, 2024 19:55
Copy link
Owner

@altsem altsem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm generally happy with the implementation.
Just found one problem: --grep when doing log other.

I tried to make src/tests/log.rs a bit more clear over at altsem/value-arguments. Also added a test for the above.

src/tests/arg.rs Outdated

assert_eq!(arg.value_as::<String>(), None);
assert_eq!(arg.value_as::<u32>(), Some(&1u32));
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No big deal, but.

I would put these more unit-y tests in the same file as the implementation. (like in src/key_parser.rs)

The tests in src/tests used to be in tests/ as proper "integration tests".
However they were moved just to make it easier to inspect internals if really needed.

@rzikm
Copy link
Contributor Author

rzikm commented May 16, 2024

Just found one problem: --grep when doing log other.

Right, this might be more tricky to fix, State.close_menu call seems to throw away the not-yet used arguments, I would have to parse the values from the [OsString] args, which I don't like.

Maybe we can keep the pending_menu a bit longer? What do you think?

@altsem
Copy link
Owner

altsem commented May 16, 2024

I haven't exactly grasped what's going on. pending_menu (and state of the arguments) should exist until the "log other" rev prompt is done and "log other" callback has been executed I think.

edit: I do think getting rid of the args parameter in the callback would be nice.
I'm playing around a bit trying to do this.

Also found that grepping for something that does not match seems to cause a panic:

cargo run -- -k 'l-Fxxxxxxxxx<enter>l'

@altsem
Copy link
Owner

altsem commented May 22, 2024

@rzikm Figured I'd share. After some digging I think I found an approach that might work.
The idea is to:

  • Remove the args: [&OsString] parameter from prompt callbacks.
  • Hide the menu when a prompt is active (you can still access its args).
  • Call state.close_menu() explicitly in each action/prompt.

This way we can close the prompt where appropriate (some actions don't), and after the args have been assigned to commands.

My work so far: 99a75bb

Heading for vacay and might continue next week :)

@rzikm
Copy link
Contributor Author

rzikm commented May 23, 2024

Thanks, I did not have time to spend on this last couple of days, hopefully I will get to it this week so we can finally draw this to finish line.

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.

None yet

2 participants