Skip to content

Commit

Permalink
Merge pull request #3727 from mulkieran/require-pathbuf-command-line
Browse files Browse the repository at this point in the history
Require a PathBuf for blockdev argument
  • Loading branch information
mulkieran authored Dec 5, 2024
2 parents 46259c2 + 8fa6e4a commit 467156f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/bin/tools/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use std::path::PathBuf;

use clap::{Arg, ArgAction, Command};

use crate::tools::dump_metadata;
Expand All @@ -19,6 +21,7 @@ impl StratisDumpMetadata {
.next_line_help(true)
.arg(
Arg::new("dev")
.value_parser(clap::value_parser!(PathBuf))
.required(true)
.help("Print metadata of given device"),
)
Expand Down Expand Up @@ -49,8 +52,7 @@ impl<'a> ToolCommand<'a> for StratisDumpMetadata {
fn run(&self, command_line_args: Vec<String>) -> Result<(), String> {
let matches = StratisDumpMetadata::cmd().get_matches_from(command_line_args);
let devpath = matches
.get_one::<String>("dev")
.map(|s| s.as_str())
.get_one::<PathBuf>("dev")
.expect("'dev' is a mandatory argument");

dump_metadata::run(
Expand Down
3 changes: 2 additions & 1 deletion src/bin/tools/dump_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use std::{
fs::OpenOptions,
io::{Seek, SeekFrom},
path::PathBuf,
};

use pretty_hex::pretty_hex;
Expand Down Expand Up @@ -111,7 +112,7 @@ fn print_pool_metadata(pool_metadata: &Option<Vec<u8>>, only_pool: bool) -> Resu
// Otherwise display the StaticHeader fields of both sigblocks.
// If print_bytes flag is set to True, display the bytes buffer
// of the sigblock alongside the StaticHeader.
pub fn run(devpath: &str, print_bytes: bool, pool_only: bool) -> Result<(), String> {
pub fn run(devpath: &PathBuf, print_bytes: bool, pool_only: bool) -> Result<(), String> {
let mut devfile = OpenOptions::new()
.read(true)
.open(devpath)
Expand Down

0 comments on commit 467156f

Please sign in to comment.