-
Notifications
You must be signed in to change notification settings - Fork 420
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
add support for jj help <alias>
#3015
base: main
Are you sure you want to change the base?
Conversation
8c7bfab
to
3e61bad
Compare
Two minor notes (that are mostly general gotchas, nothing specific)
Other than that, I'm a fan of long and explicative commit messages like yours, so I'll take a closer look shortly if someone else doesn't get to it. Just wanted to put it out there. |
I almost always do it, but I don't really care much about it. The goal, IMO, is to make the subject line concise and clear. I see the ": " as just a way of helping with that. It basically saves you from instead saying "In the code, ". |
Right. I think having us all do it definitely helps uphold a level of consistency too, which is mostly why I mention it. But we definitely have some deviations e.g. some changes inherently touch multiple crates, stuff like that. On a related note there is some prior art in the Conventional Commits standard to help these sorts of concerns, but ultimately, I don't follow it to a T or anything. Just the syntax |
Looking over the issue, it looks like this isn't As another point of comparison, cargo manually implements the |
Don't worry, clap's built-in help doesn't deal with arguments as well. Something I would consider fixing at some point. |
Doesn't that leave the PR in your own user repo, rather than martinvonz's?
I think that is more Linux like to prefix with the area. I've been wanting to get back to |
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.
For being the first time I've looked at this source code, I think this is likely fine. We'll see what I say if I stick with jj for several months :)
right.
i don't think that would help here. it doesn't make the code much simpler, and it doesn't support aliases in
i think you're talking about
oh right, my bad - i'll fix that real quick |
3e61bad
to
735c3ee
Compare
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!
735c3ee
to
5070a4c
Compare
oh, that's right, i put this on top of #3006 because otherwise clap panics when i try to define help for an alias that has the same name as a built-in command. i can fix it, but the work is redundant if #3006 merges. going to wait to merge this until we decide on the approach there. |
cli/tests/test_alias.rs
Outdated
|
||
let stdout = test_env.jj_cmd_success(&repo_path, &["help", "b"]); | ||
insta::assert_snapshot!(stdout.lines().take(3).join("\n"), @r###" | ||
Alias for ["log", "-r", "@", "-T", "branches"] |
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.
This can be a bit hard to parse as a human, particularly for someone coming fresh into jj.
How would you feel about alias for "jj log -r @ -T branches"
or something along the lines of that? I think that would be nicer for default aliases in particular. A user just starting on jj who runs jj help checkout
might not quite understand alias for ["new"]
, but I imagine they'd understand alias for "jj new"
perfectly.
We might need to use shlex.try_join to ensure that we don't print out wierd stuff when the user writes an alias as ["command", "with spaces", "or", "with_function_call()"]
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.
We should also use that library here:
https://github.com/martinvonz/jj/blob/462c19736a9b3293b4cc9957404504718e19ef84/cli/src/cli_util.rs#L1464-L1465
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.
done. i haven't modified the existing code in start_repo_transaction
because frankly i'm not sure how it works and i've already spent quite a while on this PR; i'd prefer to open a follow-up issue instead.
This comment was marked as resolved.
This comment was marked as resolved.
apparently |
i consider rewriting the `help` command, but that breaks some other things (e.g. tab completion doesn't work, because `clap_complete` doesn't know about the aliases). instead, i found that i can add each alias to the `clap::Command` dynamically at runtime. this works! the help it shows is useful and easy to modify, and it's only about 25 lines of code. the problem is this breaks `resolve_aliases` pretty badly. the replacement loop uses *clap's* API to determine the arguments that come after the alias, and clap does not expose a way to get the raw arguments, only the parsed arguments. it happened to work before because the commands were all `External`, in which case clap doesn't do any parsing. i tried to just stop using clap's API, which simplifies the code a lot and works with the new dynamically added alias subcommands. but that breaks global flags that precede the alias, things like `jj --no-pager alias`. instead, i waited to add the aliases to `Command` until after replacing the string arguments. that breaks because `expand_args()` gets called twice, once before and once after processing `--repository`. so even if i do this afterwards in the `resolve_aliases` function, the *next* call will still break because it parses differently. to work around *that*, i clone the app before passing it to `expand_args`, so that the modifications don't affect the --repository parsing. it's kind of hacky, but i haven't found a simpler solution. --- ## future work * `jj alias -h` shows the help for the *resolved* alias, not the "Alias for ..." short help. that happens because the alias is replaced with its definition before passing it to get_matches. it would be nice to make it consistent with `help`. * `jj help recursive-alias` will only "peel" one level of aliasing in the help; it would be nice to show the fully expanded command instead.
never mind, i found a workaround |
@jyn514, do you remember what the status of this PR is? I skimmed the comments above but it's not obvious to me if we're waiting for some changes from you or if it's ready and the reviewers forgot to review it. |
@martinvonz this still breaks the |
just to document what's going on: here is a test case that makes CI fail with my current PR: diff --git a/cli/tests/test_generate_md_cli_help.rs b/cli/tests/test_generate_md_cli_help.rs
index a752a09ef2...a1c9ce1dae 100644
--- a/cli/tests/test_generate_md_cli_help.rs
+++ b/cli/tests/test_generate_md_cli_help.rs
@@ -27,0 +27,1 @@
+ test_env.add_config(r#"aliases.foo = ["git", "fetch"]"#);
i've opened an issue upstream: ConnorGray/clap-markdown#21 |
oh fun, clap's help is autogenerated and can't be overridden statically without duplicating their whole default template. i suppose that's why so, i can either:
|
fixes #2866.
to test the new completion support in bash, run
source <(cargo run util completion bash)
.jj <TAB>
should show any aliases you have in jj.toml.Checklist
If applicable:
CHANGELOG.md