-
-
Notifications
You must be signed in to change notification settings - Fork 669
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 stdin input, make every prompt editable #93
Conversation
…both are present.
…hether it comes from stdin or prompt argument.
prompt: str = typer.Argument(None, show_default=False, help="The prompt to generate completions for."), | ||
prompt: Optional[str] = typer.Argument( | ||
None, show_default=False, help="The prompt to generate completions for."), | ||
stdin_before: bool = typer.Option(False, "--stdin-before", "-b", help="Place stdin prompt before argument prompt, default is after."), |
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 is probably fine. After talking to ChatGPT for a bit it looks like it would be more complicated to make it a combo option so in the --help screen it wouldn't show --no-stdin-before
"User:
I'm looking for how do I coude the other side of a bool typed default. Example:
code: bool = typer.Option(False, help="Provide code as output.")
Adds this to the help statment:
│ --code --no-code Provide code as output. [default: no-code] │
Instead of --no-code as the opposite, how would I make that --anti-code
"
"Assistant:
To make the opposite flag --anti-code
, you can provide the --code
option with customized --anti-code
flag using the show_default
and opposite
parameter of the typer.Option
. Here's an example:
import typer
app = typer.Typer()
@app.command()
def main(code: bool = typer.Option(
False,
help="Provide code as output.",
show_default="--anti-code",
)):
if code:
typer.echo("Code")
else:
typer.echo("Anti-Code")
if __name__ == "__main__":
app()
In this example, the show_default
is set to --anti-code
, and while it won't appear as an option in help, the output will show --anti-code
as the default opposite flag. To include it as an actual alternative flag, you would need to use two options and process them in your function:
import typer
app = typer.Typer()
@app.command()
def main(
code: bool = typer.Option(False, "--code", help="Provide code as output."),
anti_code: bool = typer.Option(False, "--anti-code", help="Provide code as output.")
):
result = "Neither"
if code and not anti_code:
result = "Code"
elif not code and anti_code:
result = "Anti-Code"
elif code and anti_code:
result = "Error: Both --code and --anti-code can't be used simultaneously."
typer.echo(result)
if __name__ == "__main__":
app()
Now you explicitly have --code
and --anti-code
available as options, and the function checks for their combinations and takes appropriate actions accordingly.
"
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.
Looks good to me, and executes fine in codespace.
Thank you for the PR, since we are rolling out new versions of |
This pull request adds support for optionally receiving a prompt from stdin. Also --editor now allows you to edit prompt regardless of prompt source.
Usage:
sgpt will use either stdin prompt or argument prompt, and combine them if both are present. The --stdin-before / -b argument reverses the ordering of the two prompts when combined.
Default ordering:
echo "stdin prompt" | sgpt "argument prompt"
Reversed ordering:
echo "stdin prompt" | sgpt --stdin-before "argument prompt"