xtask: Use clap instead of structopt

structopt was merged into clap (starting from clap 3.0), therefore
becoming a deprecated project.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
pull/44/head
Michal Rostecki 2 years ago
parent 5dd77572e6
commit 9297249e01

@ -3,8 +3,6 @@ name = "xtask"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
structopt = {version = "0.3", default-features = false }
anyhow = "1" anyhow = "1"
clap = { version = "3.1", features = ["derive"] }

@ -1,7 +1,7 @@
use std::path::PathBuf; use std::path::PathBuf;
use std::process::Command; use std::process::Command;
use structopt::StructOpt; use clap::Parser;
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub enum Architecture { pub enum Architecture {
@ -30,13 +30,13 @@ impl std::fmt::Display for Architecture {
} }
} }
#[derive(StructOpt)] #[derive(Debug, Parser)]
pub struct Options { pub struct Options {
/// Set the endianness of the BPF target /// Set the endianness of the BPF target
#[structopt(default_value = "bpfel-unknown-none", long)] #[clap(default_value = "bpfel-unknown-none", long)]
pub target: Architecture, pub target: Architecture,
/// Build the release target /// Build the release target
#[structopt(long)] #[clap(long)]
pub release: bool, pub release: bool,
} }

@ -3,21 +3,22 @@ mod run;
use std::process::exit; use std::process::exit;
use structopt::StructOpt; use clap::Parser;
#[derive(StructOpt)]
#[derive(Debug, Parser)]
pub struct Options { pub struct Options {
#[structopt(subcommand)] #[clap(subcommand)]
command: Command, command: Command,
} }
#[derive(StructOpt)] #[derive(Debug, Parser)]
enum Command { enum Command {
BuildEbpf(build_ebpf::Options), BuildEbpf(build_ebpf::Options),
Run(run::Options), Run(run::Options),
} }
fn main() { fn main() {
let opts = Options::from_args(); let opts = Options::parse();
use Command::*; use Command::*;
let ret = match opts.command { let ret = match opts.command {

@ -1,23 +1,23 @@
use std::{os::unix::process::CommandExt, process::Command}; use std::{os::unix::process::CommandExt, process::Command};
use anyhow::Context as _; use anyhow::Context as _;
use structopt::StructOpt; use clap::Parser;
use crate::build_ebpf::{build_ebpf, Architecture, Options as BuildOptions}; use crate::build_ebpf::{build_ebpf, Architecture, Options as BuildOptions};
#[derive(StructOpt)] #[derive(Debug, Parser)]
pub struct Options { pub struct Options {
/// Set the endianness of the BPF target /// Set the endianness of the BPF target
#[structopt(default_value = "bpfel-unknown-none", long)] #[clap(default_value = "bpfel-unknown-none", long)]
pub bpf_target: Architecture, pub bpf_target: Architecture,
/// Build and run the release target /// Build and run the release target
#[structopt(long)] #[clap(long)]
pub release: bool, pub release: bool,
/// The command used to wrap your application /// The command used to wrap your application
#[structopt(short, long, default_value = "sudo -E")] #[clap(short, long, default_value = "sudo -E")]
pub runner: String, pub runner: String,
/// Arguments to pass to your application /// Arguments to pass to your application
#[structopt(name = "args", last = true)] #[clap(name = "args", last = true)]
pub run_args: Vec<String>, pub run_args: Vec<String>,
} }

Loading…
Cancel
Save