Skip to content

Commit

Permalink
Merge branch 'main' into feat/configure-installation-path
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianbormann authored Nov 29, 2024
2 parents b3018a6 + 4380459 commit 1961687
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 20 deletions.
42 changes: 42 additions & 0 deletions .github/ISSUE_TEMPLATE/task.yaml
Original file line number Diff line number Diff line change
@@ -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 🎉!!
86 changes: 68 additions & 18 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,7 +18,7 @@ mod utils;
struct Args {
/// Subcommand to execute
#[command(subcommand)]
command: Commands,
command: Option<Commands>,
/// Verbosity level (0 = quite, 1 = standard, 2 = warning, 3 = error, 4 = info, 5 = verbose)
#[arg(long, default_value_t = 1)]
verbose: usize,
Expand Down Expand Up @@ -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<String> = 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);
}
}
}
}
6 changes: 4 additions & 2 deletions cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"
_____ _
Expand All @@ -28,8 +29,9 @@ pub fn print_header() {
| | | | _____ _| ' / _| |_
| | | |/ _ \ \ / / < | | __|
| |__| | __/\ V /| . \| | |_
|_____/ \___| \_/ |_|\_\_|\__| v.0.0.1
"#
|_____/ \___| \_/ |_|\_\_|\__| v{}
"#,
VERSION
);
}

Expand Down

0 comments on commit 1961687

Please sign in to comment.