added license

This commit is contained in:
Nilton Constantino
2026-01-19 06:30:40 +00:00
parent d215dbdb44
commit 9d959a2265
8 changed files with 357 additions and 2 deletions
+1
View File
@@ -2,6 +2,7 @@
name = "prometeu-core"
version = "0.1.0"
edition = "2024"
license.workspace = true
[dependencies]
serde = { version = "1.0", features = ["derive"] }
@@ -2,6 +2,7 @@
name = "prometeu-runtime-desktop"
version = "0.1.0"
edition = "2024"
license.workspace = true
[dependencies]
prometeu-core = { path = "../prometeu-core" }
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "prometeu"
version = "0.1.0"
edition = "2024"
license.workspace = true
[dependencies]
clap = { version = "4.5", features = ["derive"] }
+174
View File
@@ -0,0 +1,174 @@
use clap::{Parser, Subcommand};
use std::env;
use std::path::{Path, PathBuf};
use std::process::Command;
#[derive(Parser)]
#[command(name = "prometeu")]
#[command(about = "Dispatcher para o ecossistema Prometeu", long_about = None)]
struct Cli {
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Subcommand)]
enum Commands {
/// Executa um cartucho
Run {
/// Caminho para o cartucho
cart: String,
},
/// Debuga um cartucho
Debug {
/// Caminho para o cartucho
cart: String,
/// Porta para o debugger (padrão: 7777)
#[arg(long, default_value_t = 7777)]
port: u16,
},
/// Compila um projeto
Build {
/// Diretório do projeto
project_dir: String,
},
/// Empacota um cartucho
Pack {
/// Diretório do cartucho
cart_dir: String,
},
/// Verifica integridade de um projeto ou cartucho
Verify {
#[command(subcommand)]
target: VerifyCommands,
},
}
#[derive(Subcommand)]
enum VerifyCommands {
/// Verifica um projeto
C {
/// Diretório do projeto
project_dir: String,
},
/// Verifica um cartucho ou arquivo PMC
P {
/// Caminho para o cartucho ou PMC
cart_or_pmc: String,
},
}
fn main() {
let cli = Cli::parse();
let exe_dir = match env::current_exe() {
Ok(exe_path) => exe_path.parent().unwrap_or_else(|| Path::new(".")).to_path_buf(),
Err(e) => {
eprintln!("Erro ao obter o caminho do executável: {}", e);
std::process::exit(1);
}
};
match cli.command {
Some(Commands::Run { cart }) => {
dispatch(&exe_dir, "prometeu-runtime", &["--run", &cart]);
}
Some(Commands::Debug { cart, port }) => {
dispatch(
&exe_dir,
"prometeu-runtime",
&["--debug", &cart, "--port", &port.to_string()],
);
}
Some(Commands::Build { .. }) => {
not_implemented("build", "prometeuc");
}
Some(Commands::Pack { .. }) => {
not_implemented("pack", "prometeup");
}
Some(Commands::Verify { target }) => match target {
VerifyCommands::C { .. } => not_implemented("verify c", "prometeuc"),
VerifyCommands::P { .. } => not_implemented("verify p", "prometeup"),
},
None => {
use clap::CommandFactory;
Cli::command().print_help().unwrap();
println!();
}
}
}
fn get_binary_path(dir: &Path, name: &str) -> PathBuf {
let mut path = dir.join(name);
if cfg!(target_os = "windows") {
path.set_extension("exe");
}
path
}
fn dispatch(exe_dir: &Path, bin_name: &str, args: &[&str]) {
let bin_path = get_binary_path(exe_dir, bin_name);
if !bin_path.exists() {
// Tenta encontrar o runtime com o nome exato (prometeu-runtime-desktop)
// caso prometeu-runtime seja apenas um alias ou link que ainda não existe
let alt_bin_name = if bin_name == "prometeu-runtime" {
Some("prometeu-runtime-desktop")
} else {
None
};
let final_bin_path = if let Some(alt_name) = alt_bin_name {
let alt_path = get_binary_path(exe_dir, alt_name);
if alt_path.exists() {
alt_path
} else {
bin_path
}
} else {
bin_path
};
if !final_bin_path.exists() {
eprintln!(
"prometeu: comando '{}' ainda não está disponível nesta distribuição",
match bin_name {
"prometeu-runtime" => "run/debug",
"prometeuc" => "build/verify c",
"prometeup" => "pack/verify p",
_ => bin_name,
}
);
std::process::exit(1);
}
execute_bin(&final_bin_path, args);
} else {
execute_bin(&bin_path, args);
}
}
fn execute_bin(bin_path: &Path, args: &[&str]) {
let status = Command::new(bin_path)
.args(args)
.stdin(std::process::Stdio::inherit())
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.status();
match status {
Ok(status) => {
std::process::exit(status.code().unwrap_or(0));
}
Err(e) => {
eprintln!("Erro ao executar {}: {}", bin_path.display(), e);
std::process::exit(1);
}
}
}
fn not_implemented(cmd: &str, _bin_name: &str) {
eprintln!(
"prometeu: comando '{}' ainda não está disponível nesta distribuição",
cmd
);
std::process::exit(1);
}