Skip to content

Commit

Permalink
update to clap 4.0 (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmc-msft authored Oct 3, 2022
1 parent f7a891c commit 627c802
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 89 deletions.
64 changes: 25 additions & 39 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ status = ["atty", "indicatif"]

[dependencies]
bytes = "1.2"
elf = "0.0.10"
elf = "0.0.11"
byteorder = "1.3"
clap = { version = "3.2", default-features = false, features=["derive", "std"] }
clap = { version = "4.0.8", default-features = false, features=["derive", "std", "usage", "error-context", "help"]}
http = "0.2"
snap = "1.0"
futures = "0.3"
Expand Down
16 changes: 7 additions & 9 deletions src/bin/avml-convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#![deny(clippy::indexing_slicing)]

use avml::{image, iomem::split_ranges, Error, Result, Snapshot, Source, ONE_MB};
use clap::{ArgEnum, Parser};
use clap::{Parser, ValueEnum};
use snap::read::FrameDecoder;
use std::{
convert::TryFrom,
Expand Down Expand Up @@ -124,30 +124,28 @@ fn convert_from_raw(src: &Path, dst: &Path, compress: bool) -> Result<()> {

#[derive(Parser)]
/// AVML compress/decompress tool
#[clap(version)]
#[command(version)]
struct Config {
/// specify output format [possible values: raw, lime, lime_compressed. Default: lime_compressed]
#[clap(long, arg_enum, default_value_t = Format::LimeCompressed, value_parser)]
/// specify output format
#[arg(long, value_enum, default_value_t = Format::LimeCompressed)]
source_format: Format,

/// specify output format
#[clap(long, arg_enum, default_value_t = Format::Lime, value_parser)]
#[arg(long, value_enum, default_value_t = Format::Lime)]
format: Format,

/// name of the source file to read to on local system
#[clap(value_parser)]
src: PathBuf,

/// name of the destination file to write to on local system
#[clap(value_parser)]
dst: PathBuf,
}

#[derive(ArgEnum, Clone)]
#[derive(ValueEnum, Clone)]
enum Format {
Raw,
Lime,
#[clap(rename_all = "snake_case")]
#[value(rename_all = "snake_case")]
LimeCompressed,
}

Expand Down
27 changes: 12 additions & 15 deletions src/bin/avml-upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,43 @@ use tokio::runtime::Runtime;
use url::Url;

#[derive(Parser)]
#[clap(version)]
#[command(version)]
/// AVML upload tool
struct Cmd {
#[clap(subcommand)]
subcommand: SubCommands,
#[command(subcommand)]
command: Commands,
}

#[derive(Subcommand)]
enum SubCommands {
enum Commands {
Put {
/// name of the file to upload on the local system
#[clap(value_parser)]
filename: PathBuf,

// url to upload via HTTP PUT
#[clap(value_parser)]
/// url to upload via HTTP PUT
url: Url,
},
UploadBlob {
/// name of the file to upload on the local system
#[clap(value_parser)]
filename: PathBuf,

// url to upload via Azure Blob Storage
#[clap(value_parser)]
/// url to upload via Azure Blob Storage
url: Url,

/// specify blob upload concurrency
#[clap(long, value_parser)]
#[arg(long)]
sas_block_concurrency: Option<usize>,

/// specify maximum block size in MiB
#[clap(long, value_parser)]
#[arg(long)]
sas_block_size: Option<usize>,
},
}

async fn run(cmd: Cmd) -> avml::Result<()> {
match cmd.subcommand {
SubCommands::Put { filename, url } => put(&filename, &url).await?,
SubCommands::UploadBlob {
match cmd.command {
Commands::Put { filename, url } => put(&filename, &url).await?,
Commands::UploadBlob {
filename,
url,
sas_block_size,
Expand Down
17 changes: 8 additions & 9 deletions src/bin/avml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,42 @@ use url::Url;

#[derive(Parser)]
/// A portable volatile memory acquisition tool for Linux
#[clap(version)]
#[command(author, version, about, long_about = None)]
struct Config {
/// compress via snappy
#[clap(long, value_parser)]
#[arg(long)]
compress: bool,

/// specify input source
#[clap(long, arg_enum, value_parser)]
#[arg(long, value_enum)]
source: Option<Source>,

/// upload via HTTP PUT upon acquisition
#[cfg(feature = "put")]
#[clap(long, value_parser)]
#[arg(long)]
url: Option<Url>,

/// delete upon successful upload
#[cfg(any(feature = "blobstore", feature = "put"))]
#[clap(long, value_parser)]
#[arg(long)]
delete: bool,

/// upload via Azure Blob Store upon acquisition
#[cfg(feature = "blobstore")]
#[clap(long, value_parser)]
#[arg(long)]
sas_url: Option<Url>,

/// specify maximum block size in MiB
#[cfg(feature = "blobstore")]
#[clap(long, value_parser)]
#[arg(long)]
sas_block_size: Option<usize>,

/// specify blob upload concurrency
#[cfg(feature = "blobstore")]
#[clap(long, value_parser)]
#[arg(long)]
sas_block_concurrency: Option<usize>,

/// name of the file to write to on local system
#[clap(value_parser)]
filename: PathBuf,
}

Expand Down
Loading

0 comments on commit 627c802

Please sign in to comment.