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

Add prompt if arguments are empty #5

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use hyper::{body::Buf, header, Body, Client, Request};
use hyper_tls::HttpsConnector;
use serde_derive::{Deserialize, Serialize};
use std::io::{stdin, stdout, Write};
use std::{env, env::args};

#[derive(Deserialize, Debug)]
Expand Down Expand Up @@ -47,13 +48,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
arguments.remove(0);

if arguments.is_empty() {
println!("Welcome to Rusty! Enter an argument to get started.");
std::process::exit(1);
}

for x in arguments {
user_input.push(' ');
user_input.push_str(&x);
print!("Enter prompt: ");
let _ = stdout().flush();
stdin()
.read_line(&mut user_input)
.expect("Failed to read prompt.");
} else {
for x in arguments {
user_input.push(' ');
user_input.push_str(&x);
}
}

let auth_header_val = format!("Bearer {}", api_key);
Expand Down