Skip to content

Commit b8ffa70

Browse files
committed
Improve documentation at the CLI level
Fix cleaning terminal when restarting the run Add more info in the header
1 parent ba3cda9 commit b8ffa70

File tree

5 files changed

+91
-32
lines changed

5 files changed

+91
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/target
22
Cargo.lock
33
build.sh
4+
linux_build.sh
45
homebrew

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pepe"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
authors = ["Omar MHAIMDAT"]
55
edition = "2021"
66
description = "HTTP load generator and performance testing tool"

install.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if [ "$(uname)" = "Darwin" ]; then
1919
echo "pepe installed successfully using Homebrew!"
2020
else
2121
echo "Homebrew not found, downloading pepe for macOS..."
22-
curl -L -o pepe "https://pepe.mhaimdat.com/0.2.0/$(uname -m)-apple-darwin/pepe"
22+
curl -L -o pepe "https://pepe.mhaimdat.com/0.2.1/$(uname -m)-apple-darwin/pepe"
2323
chmod +x pepe
2424
mv pepe /usr/local/bin/
2525
echo "pepe for macOS downloaded and installed successfully!"
@@ -53,8 +53,8 @@ elif [ "$(uname -s)" = "Linux" ]; then
5353
cd "$TEMP_DIR"
5454

5555
echo "Downloading binary..."
56-
curl -L -O "https://pepe.mhaimdat.com/0.2.0/x86_64-unknown-linux-gnu/pepe"
57-
curl -L -O "https://pepe.mhaimdat.com/0.2.0/x86_64-unknown-linux-gnu/pepe.sha256"
56+
curl -L -O "https://pepe.mhaimdat.com/0.2.1/x86_64-unknown-linux-gnu/pepe"
57+
curl -L -O "https://pepe.mhaimdat.com/0.2.1/x86_64-unknown-linux-gnu/pepe.sha256"
5858

5959
echo "Verifying binary integrity..."
6060
EXPECTED_CHECKSUM=$(cat pepe.sha256)

src/main.rs

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
use clap::{ArgAction::HelpLong, Parser};
22
use crossterm::{
3-
cursor::{Hide, Show},
3+
cursor::Show,
44
event::KeyCode,
55
execute,
6-
terminal::{
7-
disable_raw_mode, enable_raw_mode, Clear, ClearType, EnterAlternateScreen,
8-
LeaveAlternateScreen,
9-
},
6+
terminal::{disable_raw_mode, enable_raw_mode, LeaveAlternateScreen},
107
};
118
use curl_parser;
129
use hyper::{HeaderMap, Uri};
@@ -26,25 +23,47 @@ mod ui;
2623
// #[command(long_about = USAGE)]
2724
#[clap(disable_help_flag = true)]
2825
struct Args {
29-
#[arg(long, action = HelpLong)]
26+
#[arg(short, long, action = HelpLong)]
3027
help: Option<bool>,
31-
#[clap(short = 'n', long, default_value = "100")]
28+
#[clap(short = 'n', long, default_value = "100", help = "Number of requests")]
3229
number: u32,
33-
#[clap(short = 'c', long, default_value_t = default_concurrency())]
30+
#[clap(short = 'c', long, default_value_t = default_concurrency(), help = "Number of concurrent requests")]
3431
concurrency: u32,
35-
#[clap(short = 'q', long, default_value = "0")]
32+
#[clap(
33+
short = 'q',
34+
long,
35+
default_value = "0",
36+
help = "Number of requests to perform before exiting"
37+
)]
3638
rate_limit: u32,
3739
#[clap(short = 'z', long)]
3840
duration: Option<String>,
3941
#[clap(short = 'o', long)]
4042
output: Option<String>,
41-
#[clap(long = "curl", help = "Curl command to convert to HTTP request")]
43+
#[clap(
44+
long = "curl",
45+
help = "Curl mode to parse curl command, e.g. pepe --curl -- 'curl -X POST http://localhost:8080'"
46+
)]
4247
curl: bool,
43-
#[clap(short = 'm', long, default_value = "GET")]
48+
#[clap(
49+
short = 'm',
50+
long,
51+
default_value = "GET",
52+
help = "HTTP method, e.g. GET, POST, PUT, DELETE"
53+
)]
4454
method: String,
45-
#[clap(short = 'H', long)]
55+
#[clap(
56+
short = 'H',
57+
long,
58+
help = "HTTP headers, e.g. -H 'Accept: application/json'"
59+
)]
4660
headers: Vec<String>,
47-
#[clap(short = 't', long, default_value = "20")]
61+
#[clap(
62+
short = 't',
63+
long,
64+
default_value = "20",
65+
help = "Time in seconds to wait for a response"
66+
)]
4867
timeout: u32,
4968
#[clap(short = 'A', long)]
5069
accept: Option<String>,
@@ -54,7 +73,7 @@ struct Args {
5473
body_file: Option<String>,
5574
#[clap(short = 'T', long, default_value = "text/html")]
5675
content_type: String,
57-
#[clap(short, long, default_value = concat!("pepe/", env!("CARGO_PKG_VERSION")))]
76+
#[clap(short, long, default_value = concat!("pepe/", env!("CARGO_PKG_VERSION")), help = "User-Agent string, default is pepe/{version}")]
5877
user_agent: String,
5978
#[clap(short, long)]
6079
basic_auth: Option<String>,
@@ -72,7 +91,7 @@ struct Args {
7291
disable_keepalive: bool,
7392
#[clap(long)]
7493
disable_redirects: bool,
75-
#[clap(default_value = "")]
94+
#[clap(default_value = "", help = "URL to request")]
7695
url: String,
7796
#[clap(last = true, default_value = "")]
7897
args: Vec<String>,
@@ -118,7 +137,6 @@ impl Args {
118137
})
119138
.collect::<Vec<_>>()
120139
.join(" ");
121-
println!("Curl command: {}", curl_command);
122140
let parsed_request = curl_parser::ParsedRequest::load(&curl_command, Some(()));
123141
if parsed_request.is_err() {
124142
eprintln!("Error: {}", parsed_request.err().unwrap());
@@ -471,7 +489,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
471489

472490
enable_raw_mode()?;
473491
let mut stdout = stdout();
474-
execute!(stdout, EnterAlternateScreen, Clear(ClearType::All), Hide)?;
475492

476493
let interrupted = Arc::new(tokio::sync::Notify::new());
477494

src/ui.rs

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ impl Dashboard {
164164
enable_raw_mode()?;
165165
let mut terminal = Terminal::new(CrosstermBackend::new(std::io::stdout()))?;
166166

167+
terminal.clear()?;
168+
167169
loop {
168170
// Update stats
169171
while let Ok(stat) = rx.try_recv() {
@@ -188,6 +190,7 @@ impl Dashboard {
188190
| KeyCode::Enter
189191
| KeyCode::Char('i')
190192
) {
193+
terminal.clear()?;
191194
return Ok(key.code);
192195
}
193196
}
@@ -345,7 +348,8 @@ impl Dashboard {
345348
.direction(Direction::Horizontal)
346349
.constraints([
347350
Constraint::Percentage(20),
348-
Constraint::Percentage(20),
351+
Constraint::Percentage(10),
352+
Constraint::Percentage(10),
349353
Constraint::Percentage(60),
350354
])
351355
.split(area);
@@ -356,7 +360,43 @@ impl Dashboard {
356360
.unwrap_or(NonZeroUsize::new(8).unwrap_or(default_n_threads))
357361
.get();
358362
}
363+
359364
// Logo section
365+
f.render_widget(
366+
Paragraph::new(LOGO)
367+
.style(Style::default().fg(Color::Cyan))
368+
.block(Block::default().borders(Borders::ALL)),
369+
chunks[0],
370+
);
371+
372+
// Commands section
373+
let commands: Vec<Line<'_>> = vec![
374+
Line::from(vec![
375+
Span::styled("Quit: ", Style::default().fg(Color::Yellow)),
376+
Span::raw("q"),
377+
]),
378+
Line::from(vec![
379+
Span::styled("Restart: ", Style::default().fg(Color::Yellow)),
380+
Span::raw("r"),
381+
]),
382+
Line::from(vec![
383+
Span::styled("Interrupt: ", Style::default().fg(Color::Yellow)),
384+
Span::raw("i"),
385+
]),
386+
];
387+
388+
f.render_widget(
389+
Paragraph::new(commands).block(
390+
Block::default()
391+
.title("Commands")
392+
.borders(Borders::ALL)
393+
.style(Style::default().fg(Color::Cyan))
394+
.title_style(Style::default().fg(Color::White)),
395+
),
396+
chunks[1],
397+
);
398+
399+
// Info section
360400
let version_info = vec![
361401
Line::from(vec![
362402
Span::styled("Version: ", Style::default().fg(Color::Yellow)),
@@ -378,15 +418,12 @@ impl Dashboard {
378418
Span::styled("Cores: ", Style::default().fg(Color::Yellow)),
379419
Span::raw(n_threads.to_string()),
380420
]),
421+
Line::from(vec![
422+
Span::styled("PID: ", Style::default().fg(Color::Yellow)),
423+
Span::raw(std::process::id().to_string()),
424+
]),
381425
];
382426

383-
f.render_widget(
384-
Paragraph::new(LOGO)
385-
.style(Style::default().fg(Color::Cyan))
386-
.block(Block::default().borders(Borders::ALL)),
387-
chunks[0],
388-
);
389-
390427
f.render_widget(
391428
Paragraph::new(version_info)
392429
.block(
@@ -396,7 +433,7 @@ impl Dashboard {
396433
.title_style(Style::default().fg(Color::White)),
397434
)
398435
.style(Style::default().fg(Color::Cyan)),
399-
chunks[1],
436+
chunks[2],
400437
);
401438

402439
// Parameters section
@@ -417,6 +454,10 @@ impl Dashboard {
417454
Span::styled("Total Requests: ", Style::default().fg(Color::Yellow)),
418455
Span::raw(self.args.number.to_string()),
419456
]),
457+
Line::from(vec![
458+
Span::styled("Timeout: ", Style::default().fg(Color::Yellow)),
459+
Span::raw(self.args.timeout.to_string()),
460+
]),
420461
];
421462

422463
f.render_widget(
@@ -427,7 +468,7 @@ impl Dashboard {
427468
.style(Style::default().fg(Color::Cyan))
428469
.title_style(Style::default().fg(Color::White)),
429470
),
430-
chunks[2],
471+
chunks[3],
431472
);
432473
}
433474

@@ -618,7 +659,7 @@ impl Dashboard {
618659
self.render_stat_widget(
619660
f,
620661
stats_chunks[1],
621-
"RPS",
662+
"Request per Second",
622663
self.stats.rps.to_string(),
623664
Color::Magenta,
624665
);

0 commit comments

Comments
 (0)