use clap::{Arg, Command}; use std::fs; use std::io; use std::path; use std::path::Path; fn create_file(path: &str) -> io::Result<()> { fs::File::create(path)?; println!("File '{}' created successfully.", path); Ok(()) } fn main() { println!("Hello, world!"); let matches = Command::new("File Manager CLI") .version("1.0") .author("Yu LinLing") .about("A simple file management tool") .subcommand( Command::new("create") .about("Create a file or dircetory") .arg( Arg::new("path") .help("Path to the file or directory") .required(true) .index(1), ) .arg( Arg::new("type") .help("Type of entity to create file or dic") .required(true) .long("type") .value_parser(clap::value_parser!(String)) .num_args(1), ), ) .get_matches(); if let Some(matches) = matches.subcommand_matches("create") { let path = matches.get_one::("path").unwrap(); let entity_type = matches.get_one::("type").unwrap(); if entity_type == "file" { if let Err(e) = create_file(path) { eprintln!("Error creating file: {}", e); } } else if entity_type == "dir" { if let Err(e) = create_file(path) { eprintln!("Error creating directory: {}", e); } } else { println!("Invalid type. Use 'file' or 'dir' "); } } }