diff --git a/.github/ISSUE_TEMPLATE/task.yaml b/.github/ISSUE_TEMPLATE/task.yaml new file mode 100644 index 0000000..5936906 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/task.yaml @@ -0,0 +1,42 @@ +name: 📝 Task +description: Create a task +title: "[Task]: " +labels: ["task"] + +body: + - type: textarea + attributes: + label: 📝 Task description + description: > + A clear and concise description of the task. + validations: + required: true + - type: dropdown + attributes: + label: Component + description: > + Select the component related to this feature request. + options: + - ui + - cli + - package distribution + - testing + - explorer + - IDE plugins + - other + validations: + required: true + - type: textarea + attributes: + label: Steps to complete + description: > + Detailed steps to complete the task. + - type: textarea + attributes: + label: Additional context + description: > + Add any other context about the task here. + - type: markdown + attributes: + value: > + Thanks for contributing 🎉!! \ No newline at end of file diff --git a/cli/src/main.rs b/cli/src/main.rs index 4cfd22b..ccf54b6 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,5 +1,11 @@ +use std::path::Path; +use std::process::Command; + +use clap::CommandFactory; use clap::Parser; use clap::Subcommand; +use logger::error; +use logger::log; mod config; mod logger; @@ -12,7 +18,7 @@ mod utils; struct Args { /// Subcommand to execute #[command(subcommand)] - command: Commands, + command: Option, /// Verbosity level (0 = quite, 1 = standard, 2 = warning, 3 = error, 4 = info, 5 = verbose) #[arg(long, default_value_t = 1)] verbose: usize, @@ -45,28 +51,72 @@ async fn main() { std::process::exit(1); } - let args = Args::parse(); + let parsed_args = Args::try_parse(); utils::print_header(); - logger::init(args.verbose); + logger::init(parsed_args.as_ref().map(|args| args.verbose).unwrap_or(1)); + config::init(); + + utils::check_setup().await.unwrap_or_else(|e| { + logger::error(&format!( + "Failed to check your Yaci DevKit and services setup: {}", + e + )); + std::process::exit(1); + }); - match args.command { - Commands::Init { path } => { - config::init(path); - utils::check_setup().await.unwrap_or_else(|e| { - logger::error(&format!( - "Failed to check your Yaci DevKit and services setup: {}", - e + match parsed_args { + Ok(args) => match args.command { + Some(Commands::Init) { path } => { + config::init(path); + utils::check_setup().await.unwrap_or_else(|e| { + logger::error(&format!( + "Failed to check your Yaci DevKit and services setup: {}", + e + )); + std::process::exit(1); + }); + } + Some(Commands::Start) => match start::start_devkit() { + Ok(_) => logger::log("Cardano DevKit started successfully"), + Err(e) => { + logger::error(&format!("Failed to start Cardano DevKit: {}", e)); + std::process::exit(1); + } + }, + Some(Commands::Stop) => logger::log("Stop command not implemented yet"), + None => { + error("Please provide a subcommand to execute."); + log(&format!( + "{}", + Args::command().render_long_help().to_string() )); std::process::exit(1); - }); - } - Commands::Start => match start::start_devkit() { - Ok(_) => logger::log("Cardano DevKit started successfully"), - Err(e) => { - logger::error(&format!("Failed to start Cardano DevKit: {}", e)); - std::process::exit(1); } }, - Commands::Stop => logger::log("Stop command not implemented yet"), + Err(_) => { + let cli_args: Vec = std::env::args().skip(1).collect(); + let configuration = config::get_config(); + let yaci_devkit_path = Path::new(&configuration.yaci_devkit.path); + + let output = Command::new(yaci_devkit_path.join("yaci-cli")) + .current_dir(yaci_devkit_path) + .args(cli_args) + .output() + .map_err(|yaci_cli_error| { + error(&format!( + "Failed to execute {}/yaci-cli: {}", + yaci_devkit_path.display(), + yaci_cli_error + )) + }) + .expect("Failed to execute yaci-cli"); + + if output.status.success() { + log(&String::from_utf8_lossy(&output.stdout)); + } else { + error(&String::from_utf8_lossy(&output.stderr)); + std::process::exit(1); + } + } } } diff --git a/cli/src/utils.rs b/cli/src/utils.rs index d32049e..a327388 100644 --- a/cli/src/utils.rs +++ b/cli/src/utils.rs @@ -15,6 +15,7 @@ use crate::config; use crate::logger::{error, log}; pub fn print_header() { + const VERSION: &str = env!("CARGO_PKG_VERSION"); println!( r#" _____ _ @@ -28,8 +29,9 @@ pub fn print_header() { | | | | _____ _| ' / _| |_ | | | |/ _ \ \ / / < | | __| | |__| | __/\ V /| . \| | |_ - |_____/ \___| \_/ |_|\_\_|\__| v.0.0.1 - "# + |_____/ \___| \_/ |_|\_\_|\__| v{} + "#, + VERSION ); }