Parse command line args
This commit is contained in:
parent
6234038460
commit
4aecce8107
3 changed files with 241 additions and 2 deletions
33
src/main.rs
33
src/main.rs
|
|
@ -1,7 +1,36 @@
|
|||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
mod builtin;
|
||||
mod table;
|
||||
mod value;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
#[derive(Parser)]
|
||||
enum Command {
|
||||
Parse { file: PathBuf },
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Args {
|
||||
#[command(subcommand)]
|
||||
command: Command,
|
||||
}
|
||||
|
||||
/// Foo
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let args = Args::parse();
|
||||
|
||||
match args.command {
|
||||
Command::Parse { file } => {
|
||||
let content = fs::read_to_string(&file)?;
|
||||
print!("{content}");
|
||||
if !content.ends_with('\n') {
|
||||
println!();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue