cli icon indicating copy to clipboard operation
cli copied to clipboard

Top level flag to specify directory to operate in

Open Hellseher opened this issue 5 years ago • 7 comments

Describe the feature or problem you’d like to solve

For example your org has N number of projects you have cloned locally where N may be more then 100. To list all PRs on all projects you need to repeatedly access each project and run gh pr list for N times.

Unwanted scenario:

cd <project>
gh pr list
cd ..
# Repeat N times

Proposed solution

It would be nice to have such key in to level flags such --dir, --repo or --project-path to have such operation possible:

for proj in $(ls); do gh --project-path=$rpoj pr list; done

or to have kind of .ghrc where someone could list all current projects (configuration file in YAML, JSON, or INI format )

It would be helpful for DevOps teams they usually have to deal with all projects at the same time.

Hellseher avatar Oct 19 '20 09:10 Hellseher

Thanks for writing in!

We already support the --repo flag:

gh pr list --repo cli/cli

However, that flag requires you to know the owner/repo pair for a GitHub repo.

If you're operating on local directories exclusively (and don't know exactly which GitHub repos their remotes map to), maybe a flag like git's -C would be useful? https://github.com/cli/cli/issues/1931

gh -C path/to/project pr list

mislav avatar Oct 19 '20 14:10 mislav

@mislav #1913 git-like -C flag looks exactly what I would like to have, thanks 👍 It also mentioned -R flag which I could not find in my current gh version

gh --version
gh version 1.0.0 (2020-09-16)
https://github.com/cli/cli/releases/tag/v1.0.0

UP

-R flag is not in top level

simple hack to list all PRs on all repos cloned locally, assuming that all of them belong to one <org>

ls | xargs -I{} bash -c 'echo ____________ {}; gh pr list -R <org>/{}' >> ../gh-pr-list

Hellseher avatar Oct 20 '20 09:10 Hellseher

@mislav May I ask if there's any update? Or is this something already on the roadmap? Thank you!

ryenus avatar Apr 19 '21 03:04 ryenus

@ryenus No update; nothing on the roadmap.

mislav avatar May 07 '21 14:05 mislav

This option would be really useful.

I see git and the other GitHub CLI hub both support this flag --git-dir=<path> which is very useful when your current working directory isn't within the repository you want to run actions on.

g3kk0 avatar Jul 20 '21 14:07 g3kk0

Looking at how this is done in Git, it's actually quite straightforward, each -C is treated as like a cd option to change the current working directory (CWD). It would be nice if someone familiar with go can help move this forward.

ryenus avatar Jul 21 '21 01:07 ryenus

Maybe add the help wanted label? @mislav or anyone from the team? Just for the status quo.

ryenus avatar Jul 14 '22 18:07 ryenus

Currently must work around this with cd or pushd, not hopeful for any movement after 2 years.

tonglil avatar Oct 18 '22 23:10 tonglil

Agreed; this can be taken up by the community since we failed to do so ourselves.

Tip for implementers: this can probably be done using Cobra global flags and PreRun hooks.

mislav avatar Oct 24 '22 13:10 mislav