Added resolving paths.
This commit is contained in:
parent
6fe987a1d0
commit
ea3be48577
|
@ -0,0 +1 @@
|
||||||
|
pub mod run;
|
|
@ -0,0 +1,16 @@
|
||||||
|
use clap::Args;
|
||||||
|
use crate::utils::file_resolvers::resolve_configuration_file;
|
||||||
|
|
||||||
|
#[derive(Args, Debug)]
|
||||||
|
pub struct Arguments {
|
||||||
|
#[arg(default_value = ".")]
|
||||||
|
target: String
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run (arguments: &Arguments) -> Result<(), String> {
|
||||||
|
let target = resolve_configuration_file(&arguments.target)?;
|
||||||
|
|
||||||
|
println!("{:?}", target);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
32
src/main.rs
32
src/main.rs
|
@ -1,3 +1,31 @@
|
||||||
fn main() {
|
use std::process::exit;
|
||||||
println!("Hello, world!");
|
use clap::{Parser, Subcommand};
|
||||||
|
use commands::run;
|
||||||
|
|
||||||
|
mod commands;
|
||||||
|
mod utils;
|
||||||
|
|
||||||
|
#[derive(Subcommand, Debug)]
|
||||||
|
enum Command {
|
||||||
|
Run(run::Arguments)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
#[command(author, version, about, long_about = None, propagate_version = true)]
|
||||||
|
struct Arguments {
|
||||||
|
#[command(subcommand)]
|
||||||
|
command: Command
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let arguments = Arguments::parse();
|
||||||
|
|
||||||
|
let result = match &arguments.command {
|
||||||
|
Command::Run(arguments) => { run::run(arguments) }
|
||||||
|
};
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Ok(_) => exit(0),
|
||||||
|
Err(err) => eprintln!("{}", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::fs::canonicalize;
|
||||||
|
|
||||||
|
const DEFAULT_FILENAME: &str = "rask.yaml";
|
||||||
|
|
||||||
|
pub fn resolve_configuration_file(target: &String) -> Result<PathBuf, String> {
|
||||||
|
let target_path = Path::new(target);
|
||||||
|
|
||||||
|
let mut target = match canonicalize(target_path) {
|
||||||
|
Ok(target) => target,
|
||||||
|
Err(_) => return Err(format!("Target does not exists: {:?}", target))
|
||||||
|
};
|
||||||
|
|
||||||
|
if target.is_dir() {
|
||||||
|
target.push(DEFAULT_FILENAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
if !target.exists() {
|
||||||
|
return Err(format!("Target does not exists: {:?}", target))
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(target)
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
pub mod file_resolvers;
|
Loading…
Reference in New Issue