Skip to content

Commit

Permalink
Add --version and --help flags
Browse files Browse the repository at this point in the history
This commit adds the clap crate to bpftop, enabling standardized
--version and --help flags. The updated help output now explicitly
instructs users to run the command with root privileges (e.g., using
sudo).

Closes: #113
  • Loading branch information
jfernandez committed Feb 2, 2025
1 parent b8948d2 commit 7b85339
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ nix = { version = "0.29.0", features = ["user"] }
circular-buffer = "1.0.0"
procfs = "0.17.0"
tui-input = "0.11.0"
clap = { version = "4.5.27", features = ["derive"] }
18 changes: 18 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use anyhow::{anyhow, Context, Result};
use app::SortColumn;
use app::{App, Mode};
use bpf_program::BpfProgram;
use clap::Parser;
use crossterm::event::{self, poll, Event, KeyCode, KeyModifiers};
use crossterm::execute;
use crossterm::terminal::{
Expand Down Expand Up @@ -69,6 +70,21 @@ const SORT_INFO_FOOTER: &str = "(Esc) back";

const PROCFS_BPF_STATS_ENABLED: &str = "/proc/sys/kernel/bpf_stats_enabled";

#[derive(Parser, Debug)]
#[command(
name = env!("CARGO_PKG_NAME"),
version = env!("CARGO_PKG_VERSION"),
long_version = concat!(
env!("CARGO_PKG_VERSION"), " created by ",
"Jose Fernandez"
),
author = "Jose Fernandez",
about = env!("CARGO_PKG_DESCRIPTION"),
override_usage = "sudo bpftop"
)]
struct Bpftop {
}

impl From<&BpfProgram> for Row<'_> {
fn from(bpf_program: &BpfProgram) -> Self {
let height = 1;
Expand Down Expand Up @@ -115,6 +131,8 @@ impl Drop for TerminalManager {
}

fn main() -> Result<()> {
let _ = Bpftop::parse();

if !nix::unistd::Uid::current().is_root() {
return Err(anyhow!("This program must be run as root"));
}
Expand Down

0 comments on commit 7b85339

Please sign in to comment.