Improve documentation and consistency of the --commit flag for gh browse command#7105
Improve documentation and consistency of the --commit flag for gh browse command#7105
--commit flag for gh browse command#7105Conversation
6357062 to
ae1724f
Compare
Before, the --commit flag for the `gh browse` command always generated the `/tree` repository url for the latest commit. This commit adjusts the `--commit` flag to match the `--branch` flag behavior. The `--commit` flag now accepts an arbitrary commit sha and generates the `/tree` url for the repository at that commit. It also defaults to the latest commit, if no argument is provided to the flag, to maintain backwards compatibility.
ae1724f to
3a9d6aa
Compare
|
|
||
| // To preserve backwards compatibility when commit flag used to be a | ||
| // boolean flag. | ||
| cmd.Flags().Lookup("commit").NoOptDefVal = emptyCommitFlag |
There was a problem hiding this comment.
I couldn't think of a better way of maintaining backwards compatibility while switching the commit flag from a boolean flag to a string flag.
This seemed like a suggested way of doing it by the pflag: https://pkg.go.dev/github.com/spf13/pflag#readme-setting-no-option-default-values-for-flags
However, this means that the commit flag now must use an equals sign to assign the flag value (i.e. --commit=12a4) which looks pretty inconsistent compared to the --branch flag, for example, which just expects a typical string argument after itself.
Please let me know if you think there's a way to improve this
There was a problem hiding this comment.
Yeah this is unfortunately the only way to do this. I think it is good for now and then in a future release, perhaps when we do another major release, we can remove the NoOptDefVal and break the backwards compatibility.
samcoe
left a comment
There was a problem hiding this comment.
@alex-petrov-vt Thanks for this! The code looks good to me. I pushed a small commit to cleanup some of the already present logic in the command to make it easier to understand.
This is a follow up PR to the discussion in #6926
Before, the --commit flag for the
gh browsecommand always generated the/treerepository url for the latest commit.This PR adjusts the
--commitflag to match the--branchflag behavior. The--commitflag now accepts an arbitrary commit sha and generates the/treeurl for the repository at that commit. It also defaults to the latest commit, if no argument is provided to the flag, to maintain backwards compatibility.Fixes #6926 (maybe 😆)