mountpoint: use clap
This commit is contained in:
parent
7c7f5fa5d4
commit
0747ccf170
@ -3,6 +3,7 @@
|
|||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
|
||||||
|
use clap::Arg;
|
||||||
use clap::{crate_version, Command};
|
use clap::{crate_version, Command};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
@ -15,20 +16,21 @@ const USAGE: &str = help_usage!("mountpoint.md");
|
|||||||
|
|
||||||
#[uucore::main]
|
#[uucore::main]
|
||||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let args: Vec<String> = env::args().collect();
|
let matches: clap::ArgMatches = uu_app().try_get_matches_from(args)?;
|
||||||
|
let path = matches.get_one::<String>("path");
|
||||||
|
|
||||||
if args.len() != 2 {
|
if let Some(path) = path {
|
||||||
eprintln!("Usage: mountpoint <path>");
|
if is_mountpoint(path) {
|
||||||
|
println!("{} is a mountpoint", path);
|
||||||
|
} else {
|
||||||
|
println!("{} is not a mountpoint", path);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Handle the case where path is not provided
|
||||||
|
eprintln!("Error: Path argument is required");
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
let path = &args[1];
|
|
||||||
if is_mountpoint(path) {
|
|
||||||
println!("{} is a mountpoint", path);
|
|
||||||
} else {
|
|
||||||
println!("{} is not a mountpoint", path);
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_mountpoint(path: &str) -> bool {
|
fn is_mountpoint(path: &str) -> bool {
|
||||||
@ -54,4 +56,10 @@ pub fn uu_app() -> Command {
|
|||||||
.about(ABOUT)
|
.about(ABOUT)
|
||||||
.override_usage(format_usage(USAGE))
|
.override_usage(format_usage(USAGE))
|
||||||
.infer_long_args(true)
|
.infer_long_args(true)
|
||||||
|
|
||||||
|
.arg(Arg::new("path")
|
||||||
|
.value_name("PATH")
|
||||||
|
.help("Path to check for mountpoint")
|
||||||
|
.required(true)
|
||||||
|
.index(1))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user