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

Multi line body with flags #595

Closed
Nhoutain opened this issue Mar 5, 2020 · 7 comments
Closed

Multi line body with flags #595

Nhoutain opened this issue Mar 5, 2020 · 7 comments
Labels
core This issue is not accepting PRs from outside contributors enhancement a request to improve CLI

Comments

@Nhoutain
Copy link

Nhoutain commented Mar 5, 2020

Describe the feature or problem you’d like to solve

I can't find a way to create a PR with a multi line body with the flags

Proposed solution

One solution can be to allow multiple time the flag --body and concatenate with the newline separator. It's useful when use the cli in a script or something like that

Or may be there is another way?

@Nhoutain Nhoutain added the enhancement a request to improve CLI label Mar 5, 2020
@mislav
Copy link
Contributor

mislav commented Mar 5, 2020

Good question!

One way that is immediately available to you is passing a multiline string as the --body argument:

gh issue create -t mytitle -b 'hello
multiline
body'

If you have a multiline string in a shell variable, you could also simply pass it like so: --body "$mybody". (Although, keep in mind while constructing that variable that the common notation \n does not, in fact, constitute a newline in a double-quoted bash string literal. This trips a lot of people up.)

I also like your suggestion of passing multiple --body. The git commit command allows this with --message and I think that's useful. It's also relatively easily to implement and backwards-compatible with current usage.

Finally, I believe that in general, any command-line operation that accepts a blob of text should also accept it from standard input. There is usually some way of signalling that; in our case, we could accept --body=-, for example, and interpret that as "ready the body contents from standard input". The drawback of this particular implementation would be that it would be impossible to pass the literal body value of -, but nobody should ever submit that as a body of an issue, pull request, or comment anyway, so I think we would be fine.

@Nhoutain
Copy link
Author

Nhoutain commented Mar 6, 2020

Thanks for the quick answer..

Indeed, I use a library to launch the command that use a double-quoted to pass argument.. That's why it doesn't work. Thanks for the tips.

@magiconair
Copy link

Reading from stdin with -b- sounds like the right thing to do. If someone wants to create a body with only - they can use echo "-" | gh pr create -b-

Other options:

  • -F to read title and body from a file like git commit -F <file>
  • Interpret \n in the message body.

I think any solution should do what git does by default so that you don't have to use two different mechanisms.

@magiconair
Copy link

My current workaround is to write the message to a file and then do this:

echo -e "line1\nline2\nline3\n" > msg
export msg=$(cat msg) ; gh create pr -b "$msg"

@vilmibm vilmibm added the core This issue is not accepting PRs from outside contributors label Oct 7, 2020
@msfjarvis
Copy link
Contributor

The --body-file option is reasonable, but I feel the parallel from the Git CLI where git commit -m "line 1" -m "line 2" is a supported way of doing things is something that more users would find handy. To that end, I've put together a very rough PoC of how this could be done here. If the CLI team agrees with supporting this pattern, I'd love to start a PR.

@mislav
Copy link
Contributor

mislav commented Mar 2, 2021

@msfjarvis I like the ability for git commit to receive multiple -m flags and join them with an empty line, but I feel the feature doesn't fit well in GitHub CLI core. It would be tricky to explain in documentation and I don't think it would see much use. To keep things simple, we will stick to a single --body flag, with the addition of --body-file for scripting.

@mislav
Copy link
Contributor

mislav commented Mar 16, 2021

The latest release of gh supports passing a -F/--body-file with either a filename or - to read from standard input. This is the preferred alternative to specifying multi-line bodies inline using the -b/--body flag.

@mislav mislav closed this as completed Mar 16, 2021
changchiyou added a commit to changchiyou/Python-Action-Demo that referenced this issue Aug 22, 2023
changchiyou added a commit to changchiyou/Python-Action-Demo that referenced this issue Aug 22, 2023
JoeWang1127 added a commit to googleapis/sdk-platform-java that referenced this issue Mar 8, 2024
In this PR:
- Write PR description into a file which lives the same directory with
the configuration.

Context:
After #2531, we can generate pull request description from generation
config and a baseline commit.

However, the return value (string) can not be retrieved when running in
docker environment. Therefore, write the description to a file. Put
multi-line description to a file also helps editing the pr body
([link](cli/cli#595 (comment))).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core This issue is not accepting PRs from outside contributors enhancement a request to improve CLI
Projects
None yet
Development

No branches or pull requests

5 participants