added argument parsing and structure with clap

This commit is contained in:
2023-03-08 20:39:57 +01:00
parent ab4d2bf7c3
commit 85218ba57f
5 changed files with 229 additions and 5 deletions

10
src/app/args/mod.rs Normal file
View File

@@ -0,0 +1,10 @@
use clap::Parser;
use self::structure::Args;
mod structure;
pub fn args() -> Args {
return Args::parse();
}

12
src/app/args/structure.rs Normal file
View File

@@ -0,0 +1,12 @@
use clap::{Parser, Subcommand};
#[derive(Parser)]
pub struct Args {
#[command(subcommand)]
command: Option<CommandArg>
}
#[derive(Subcommand)]
enum CommandArg {
Build,
}

View File

@@ -1,6 +1,7 @@
mod commands;
pub mod builder;
pub mod fs_util;
mod args;
use std::collections::HashMap;
use std::env;
@@ -8,6 +9,8 @@ use std::env;
use commands::traits::Command;
use commands::CommandRegistry;
use self::args::args;
pub struct App {
command_regisrty: CommandRegistry,
}
@@ -19,9 +22,10 @@ impl App {
}
}
pub fn start(self, args: Vec<String>) {
pub fn start(self, old_args: Vec<String>) {
let args = args();
Self::preapare_env_path();
let command_args = &args[1..];
let command_args = &old_args[1..];
let mut path = String::from("");
let mut argument_map = HashMap::new();
let mut only_options_left = false;