Absolutely all logs have been replaced with the new system on log.

This commit is contained in:
alex-xr555
2026-09-11 20:10:17 +03:00
parent df674defe1
commit 991d1c20af
16 changed files with 176 additions and 160 deletions

View File

@@ -15,10 +15,11 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::prelude::*;
use crate::core::build_config::Config; use crate::core::build_config::Config;
use crate::core::deps::register; use crate::core::deps::register;
use crate::utils::fs::find_project_root; use crate::utils::fs::find_project_root;
use crate::utils::log::error;
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc}; use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc};
use toml::Value; use toml::Value;
use toml::map::Map; use toml::map::Map;
@@ -91,7 +92,7 @@ pub fn add(args: &[String]) -> i32 {
let start_dir = match std::env::current_dir() { let start_dir = match std::env::current_dir() {
Ok(dir) => dir, Ok(dir) => dir,
Err(_) => { Err(_) => {
error("Failed to determine current directory"); error!("Failed to determine current directory");
return 1; return 1;
} }
}; };
@@ -99,11 +100,11 @@ pub fn add(args: &[String]) -> i32 {
let root = match find_project_root(&start_dir) { let root = match find_project_root(&start_dir) {
Ok(Some(dir)) => dir, Ok(Some(dir)) => dir,
Ok(None) => { Ok(None) => {
error("dcr.toml file not found"); error!("dcr.toml file not found");
return 1; return 1;
} }
Err(_) => { Err(_) => {
error("Failed to find project root"); error!("Failed to find project root");
return 1; return 1;
} }
}; };
@@ -111,7 +112,7 @@ pub fn add(args: &[String]) -> i32 {
let mut config = match Config::open(&root.join("dcr.toml").to_string_lossy()) { let mut config = match Config::open(&root.join("dcr.toml").to_string_lossy()) {
Ok(cfg) => cfg, Ok(cfg) => cfg,
Err(err) => { Err(err) => {
error(&err.to_string()); error!("{}", &err.to_string());
return 1; return 1;
} }
}; };
@@ -154,13 +155,13 @@ pub fn add(args: &[String]) -> i32 {
} else if let Some(version) = add_args.version_from_registry { } else if let Some(version) = add_args.version_from_registry {
Value::String(version) Value::String(version)
} else { } else {
error("Dependency source (path, git, or pkg-config) must be provided"); error!("Dependency source (path, git, or pkg-config) must be provided");
return 1; return 1;
}; };
let key = format!("dependencies.{}", add_args.name); let key = format!("dependencies.{}", add_args.name);
if let Err(err) = config.edit(&key, dep_value) { if let Err(err) = config.edit(&key, dep_value) {
error(&format!("Failed to update dcr.toml: {}", err)); error!("Failed to update dcr.toml: {}", err);
return 1; return 1;
} }
@@ -179,13 +180,13 @@ pub fn add(args: &[String]) -> i32 {
/// `path:`, `github:`, `gitlab:`, or `git:` prefixes, or a full git URL. /// `path:`, `github:`, `gitlab:`, or `git:` prefixes, or a full git URL.
fn parse_add_args(args: &[String]) -> Result<AddArgs, i32> { fn parse_add_args(args: &[String]) -> Result<AddArgs, i32> {
if args.is_empty() { if args.is_empty() {
error("Usage: dcr add <name> <source> [--branch <branch> | --tag <tag> | --rev <rev>]"); error!("Usage: dcr add <name> <source> [--branch <branch> | --tag <tag> | --rev <rev>]");
error("Sources:"); error!("Sources:");
error(" github:user/repo -> github.com/user/repo"); error!(" github:user/repo -> github.com/user/repo");
error(" gitlab:user/repo -> gitlab.com/user/repo"); error!(" gitlab:user/repo -> gitlab.com/user/repo");
error(" git:host.com/user/repo -> host.com/user/repo"); error!(" git:host.com/user/repo -> host.com/user/repo");
error(" path:./path/to/lib -> local path"); error!(" path:./path/to/lib -> local path");
error(" pkg-config:fmt -> system pkg-config package"); error!(" pkg-config:fmt -> system pkg-config package");
return Err(1); return Err(1);
} }
@@ -198,7 +199,7 @@ fn parse_add_args(args: &[String]) -> Result<AddArgs, i32> {
let mut iter = args.iter(); let mut iter = args.iter();
if let Some(n) = iter.next() { if let Some(n) = iter.next() {
if n.starts_with("--") { if n.starts_with("--") {
error("First argument must be the dependency name"); error!("First argument must be the dependency name");
return Err(1); return Err(1);
} }
name = n.clone(); name = n.clone();
@@ -206,7 +207,7 @@ fn parse_add_args(args: &[String]) -> Result<AddArgs, i32> {
if let Some(s) = iter.next() { if let Some(s) = iter.next() {
if s.starts_with("--") { if s.starts_with("--") {
error("Second argument must be the dependency source"); error!("Second argument must be the dependency source");
return Err(1); return Err(1);
} }
source_spec = s.clone(); source_spec = s.clone();
@@ -225,7 +226,7 @@ fn parse_add_args(args: &[String]) -> Result<AddArgs, i32> {
) )
}) })
.map_err(|(msg, code)| { .map_err(|(msg, code)| {
error(&msg); error!("{msg}");
code code
})?; })?;
return Ok(AddArgs { return Ok(AddArgs {
@@ -240,7 +241,7 @@ fn parse_add_args(args: &[String]) -> Result<AddArgs, i32> {
}); });
} }
Err(e) => { Err(e) => {
error(&format!("Cannot add `{}` without source: {}", name, e)); error!("Cannot add `{}` without source: {}", name, e);
return Err(1); return Err(1);
} }
} }
@@ -251,26 +252,26 @@ fn parse_add_args(args: &[String]) -> Result<AddArgs, i32> {
"--branch" => { "--branch" => {
branch = iter.next().cloned(); branch = iter.next().cloned();
if branch.is_none() { if branch.is_none() {
error("--branch requires a value"); error!("--branch requires a value");
return Err(1); return Err(1);
} }
} }
"--tag" => { "--tag" => {
tag = iter.next().cloned(); tag = iter.next().cloned();
if tag.is_none() { if tag.is_none() {
error("--tag requires a value"); error!("--tag requires a value");
return Err(1); return Err(1);
} }
} }
"--rev" => { "--rev" => {
rev = iter.next().cloned(); rev = iter.next().cloned();
if rev.is_none() { if rev.is_none() {
error("--rev requires a value"); error!("--rev requires a value");
return Err(1); return Err(1);
} }
} }
_ => { _ => {
error(&format!("Unknown argument: {}", arg)); error!("Unknown argument: {arg}");
return Err(1); return Err(1);
} }
} }
@@ -292,7 +293,7 @@ fn parse_add_args(args: &[String]) -> Result<AddArgs, i32> {
.map(str::to_string) .map(str::to_string)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
if packages.is_empty() { if packages.is_empty() {
error("pkg-config source must name at least one package"); error!("pkg-config source must name at least one package");
return Err(1); return Err(1);
} }
pkg_config = Some(packages); pkg_config = Some(packages);
@@ -326,7 +327,7 @@ fn parse_add_args(args: &[String]) -> Result<AddArgs, i32> {
{ {
path = Some(source_spec); path = Some(source_spec);
} else { } else {
error( error!(
"Source must be a path, pkg-config:, a prefixed source (path:, git:, github:, gitlab:), or a full URL", "Source must be a path, pkg-config:, a prefixed source (path:, git:, github:, gitlab:), or a full URL",
); );
return Err(1); return Err(1);

View File

@@ -15,6 +15,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::prelude::*;
use crate::cli::clean::clean; use crate::cli::clean::clean;
use crate::cli::flags::parse_build_run_flags; use crate::cli::flags::parse_build_run_flags;
use crate::cli::r#gen::{ProjectInfo, write_dcr_metadata}; use crate::cli::r#gen::{ProjectInfo, write_dcr_metadata};
@@ -27,7 +29,6 @@ use crate::utils::build::{
normalize_kind, resolve_artifact_target_dir, resolve_compiler, normalize_kind, resolve_artifact_target_dir, resolve_compiler,
}; };
use crate::utils::fs::{canonicalize_path, find_project_root}; use crate::utils::fs::{canonicalize_path, find_project_root};
use crate::utils::log::error;
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, BOLD_YELLOW, colored, printc}; use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, BOLD_YELLOW, colored, printc};
use std::io::IsTerminal; use std::io::IsTerminal;
use std::path::Path; use std::path::Path;
@@ -173,18 +174,18 @@ pub fn build(args: &[String]) -> i32 {
let start_dir = match std::env::current_dir() { let start_dir = match std::env::current_dir() {
Ok(dir) => dir, Ok(dir) => dir,
Err(_) => { Err(_) => {
error("Failed to determine current directory"); error!("Failed to determine current directory");
return 1; return 1;
} }
}; };
let root = match find_project_root(&start_dir) { let root = match find_project_root(&start_dir) {
Ok(Some(dir)) => canonicalize_path(&dir), Ok(Some(dir)) => canonicalize_path(&dir),
Ok(None) => { Ok(None) => {
error("dcr.toml file not found"); error!("dcr.toml file not found");
return 1; return 1;
} }
Err(_) => { Err(_) => {
error("Failed to find project root"); error!("Failed to find project root");
return 1; return 1;
} }
}; };
@@ -242,7 +243,7 @@ pub fn build(args: &[String]) -> i32 {
} }
Err(err) => { Err(err) => {
common::finish_progress_line(); common::finish_progress_line();
error(&err.message); error!("{}", &err.message);
1 1
} }
} }

View File

@@ -15,11 +15,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::prelude::*;
use crate::core::build_config::Config; use crate::core::build_config::Config;
use crate::core::workspace::parse_workspace; use crate::core::workspace::parse_workspace;
use crate::utils::build::{default_profile_flags, default_target_triple, parse_version_info}; use crate::utils::build::{default_profile_flags, default_target_triple, parse_version_info};
use crate::utils::fs::{check_dir, find_project_root, with_dir}; use crate::utils::fs::{check_dir, find_project_root, with_dir};
use crate::utils::log::{error, warn};
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc}; use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc};
use glob::glob; use glob::glob;
use std::fs; use std::fs;
@@ -56,25 +57,25 @@ pub fn clean(args: &[String]) -> i32 {
let start_dir = match std::env::current_dir() { let start_dir = match std::env::current_dir() {
Ok(dir) => dir, Ok(dir) => dir,
Err(_) => { Err(_) => {
error("Failed to determine current directory"); error!("Failed to determine current directory");
return 1; return 1;
} }
}; };
let root = match find_project_root(&start_dir) { let root = match find_project_root(&start_dir) {
Ok(Some(dir)) => dir, Ok(Some(dir)) => dir,
Ok(None) => { Ok(None) => {
error("dcr.toml file not found"); error!("dcr.toml file not found");
return 1; return 1;
} }
Err(_) => { Err(_) => {
error("Failed to find project root"); error!("Failed to find project root");
return 1; return 1;
} }
}; };
let flags = match parse_clean_flags(args) { let flags = match parse_clean_flags(args) {
Ok(v) => v, Ok(v) => v,
Err(msg) => { Err(msg) => {
error(&msg); error!("{msg}");
return 1; return 1;
} }
}; };
@@ -83,7 +84,7 @@ pub fn clean(args: &[String]) -> i32 {
match with_dir(&root, || clean_from_root(&root, &flags)) { match with_dir(&root, || clean_from_root(&root, &flags)) {
Ok(()) => 0, Ok(()) => 0,
Err(msg) => { Err(msg) => {
error(&msg); error!("{msg}");
1 1
} }
} }
@@ -229,7 +230,7 @@ fn clean_project_at(
target_items.contains(&profile.to_string()) target_items.contains(&profile.to_string())
}; };
if !dir_exists { if !dir_exists {
warn(&format!("Directory target/{} not found", target_dir)); warn!("Directory target/{target_dir} not found");
} else { } else {
println!(" Profile: {}", colored(profile, BOLD_GREEN)); println!(" Profile: {}", colored(profile, BOLD_GREEN));
if let Some(t) = target { if let Some(t) = target {
@@ -253,7 +254,7 @@ fn clean_project_at(
colored("\n ✔", BOLD_GREEN) colored("\n ✔", BOLD_GREEN)
); );
} else { } else {
warn("Directory target not found"); warn!("Directory target not found");
} }
clean_custom_paths(&config, "debug")?; clean_custom_paths(&config, "debug")?;
clean_custom_paths(&config, "release")?; clean_custom_paths(&config, "release")?;

View File

@@ -15,7 +15,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::utils::log::{error, warn}; use crate::prelude::*;
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, printc}; use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, printc};
use serde::Deserialize; use serde::Deserialize;
use std::fs; use std::fs;
@@ -64,21 +65,21 @@ pub fn flag_update(args: &[String]) -> i32 {
} }
if !args.is_empty() { if !args.is_empty() {
warn("Command does not support additional arguments"); warn!("Command does not support additional arguments");
return 1; return 1;
} }
let current_exe = match std::env::current_exe() { let current_exe = match std::env::current_exe() {
Ok(path) => path, Ok(path) => path,
Err(_) => { Err(_) => {
error("Failed to resolve current binary path"); error!("Failed to resolve current binary path");
return 1; return 1;
} }
}; };
// Refuse self-update when the binary is owned by pacman/AUR. // Refuse self-update when the binary is owned by pacman/AUR.
if let Some(package_name) = pacman_owned_package(&current_exe) { if let Some(package_name) = pacman_owned_package(&current_exe) {
warn("This dcr binary is managed by pacman/AUR"); warn!("This dcr binary is managed by pacman/AUR");
println!( println!(
"Update via package manager: yay/paru -Syu {package_name} or sudo pacman -Syu {package_name}" "Update via package manager: yay/paru -Syu {package_name} or sudo pacman -Syu {package_name}"
); );
@@ -91,7 +92,7 @@ pub fn flag_update(args: &[String]) -> i32 {
let release = match fetch_latest_release() { let release = match fetch_latest_release() {
Ok(release) => release, Ok(release) => release,
Err(err) => { Err(err) => {
error(&format!("Failed to check for updates: {err}")); error!("Failed to check for updates: {err}");
return 1; return 1;
} }
}; };
@@ -109,14 +110,14 @@ pub fn flag_update(args: &[String]) -> i32 {
.iter() .iter()
.find(|asset| candidate_names.iter().any(|name| name == &asset.name)) .find(|asset| candidate_names.iter().any(|name| name == &asset.name))
else { else {
error(&format!("Binary for target {target} not found")); error!("Binary for target {target} not found");
return 1; return 1;
}; };
let bytes = match download_asset(&asset.browser_download_url) { let bytes = match download_asset(&asset.browser_download_url) {
Ok(bytes) => bytes, Ok(bytes) => bytes,
Err(err) => { Err(err) => {
error(&format!("Failed to download update: {err}")); error!("Failed to download update: {err}");
return 1; return 1;
} }
}; };
@@ -124,7 +125,7 @@ pub fn flag_update(args: &[String]) -> i32 {
let temp_path = temp_binary_path(&current_exe); let temp_path = temp_binary_path(&current_exe);
if fs::write(&temp_path, &bytes).is_err() { if fs::write(&temp_path, &bytes).is_err() {
error("Failed to write temporary binary"); error!("Failed to write temporary binary");
return 1; return 1;
} }
set_executable_permissions(&temp_path); set_executable_permissions(&temp_path);
@@ -132,7 +133,7 @@ pub fn flag_update(args: &[String]) -> i32 {
// Replace the running executable in place, then clean up the temp file. // Replace the running executable in place, then clean up the temp file.
if self_replace::self_replace(&temp_path).is_err() { if self_replace::self_replace(&temp_path).is_err() {
let _ = fs::remove_file(&temp_path); let _ = fs::remove_file(&temp_path);
error("Failed to replace current binary"); error!("Failed to replace current binary");
return 1; return 1;
} }

View File

@@ -15,8 +15,9 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::prelude::*;
use crate::config::{PROFILE, flags}; use crate::config::{PROFILE, flags};
use crate::utils::log::warn;
/// Flags shared by the `build` and `run` CLI commands. /// Flags shared by the `build` and `run` CLI commands.
pub struct BuildRunFlags { pub struct BuildRunFlags {
@@ -82,7 +83,7 @@ pub fn parse_build_run_flags(args: &[String]) -> Result<BuildRunFlags, i32> {
while let Some(arg) = iter.next() { while let Some(arg) = iter.next() {
// DCR build/run options are long flags only (`--name`). // DCR build/run options are long flags only (`--name`).
if !arg.starts_with("--") { if !arg.starts_with("--") {
warn("Unknown argument"); warn!("Unknown argument");
return Err(1); return Err(1);
} }
let candidate = arg.trim_start_matches("--"); let candidate = arg.trim_start_matches("--");
@@ -106,7 +107,7 @@ pub fn parse_build_run_flags(args: &[String]) -> Result<BuildRunFlags, i32> {
if let Some(w) = iter.next() { if let Some(w) = iter.next() {
workspace = Some(w.clone()); workspace = Some(w.clone());
} else { } else {
warn("--workspace requires a value"); warn!("--workspace requires a value");
return Err(1); return Err(1);
} }
continue; continue;
@@ -115,7 +116,7 @@ pub fn parse_build_run_flags(args: &[String]) -> Result<BuildRunFlags, i32> {
if let Some(t) = iter.next() { if let Some(t) = iter.next() {
target = Some(t.clone()); target = Some(t.clone());
} else { } else {
warn("--target requires a value"); warn!("--target requires a value");
return Err(1); return Err(1);
} }
continue; continue;
@@ -123,13 +124,13 @@ pub fn parse_build_run_flags(args: &[String]) -> Result<BuildRunFlags, i32> {
// Profile names come from config::flags; only one profile may be set. // Profile names come from config::flags; only one profile may be set.
if flags(candidate).is_some() { if flags(candidate).is_some() {
if profile != PROFILE { if profile != PROFILE {
warn("Duplicate profile flag"); warn!("Duplicate profile flag");
return Err(1); return Err(1);
} }
profile = candidate.to_string(); profile = candidate.to_string();
continue; continue;
} }
warn("Unknown build flag"); warn!("Unknown build flag");
return Err(1); return Err(1);
} }

View File

@@ -15,7 +15,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::utils::log::error; use crate::prelude::*;
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc}; use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc};
use glob::glob; use glob::glob;
use std::process::Command; use std::process::Command;
@@ -88,11 +89,11 @@ pub fn fmt(args: &[String]) -> i32 {
0 0
} }
Ok(s) => { Ok(s) => {
error(&format!("clang-format failed with status: {}", s)); error!("clang-format failed with status: {}", s);
1 1
} }
Err(e) => { Err(e) => {
error(&format!("Failed to execute clang-format: {}", e)); error!("Failed to execute clang-format: {}", e);
1 1
} }
} }

View File

@@ -15,6 +15,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::prelude::*;
use crate::core::build::builder::BuildContext; use crate::core::build::builder::BuildContext;
use crate::core::build::builder::artifact::{absolute_artifact_path, resolve_artifact_path}; use crate::core::build::builder::artifact::{absolute_artifact_path, resolve_artifact_path};
use crate::core::build::builder::collect_sources; use crate::core::build::builder::collect_sources;
@@ -29,7 +31,6 @@ use crate::utils::build::{
use crate::utils::fs::{ use crate::utils::fs::{
absolute_join, atomic_write, canonicalize_path, ensure_dcr_dir, find_project_root, absolute_join, atomic_write, canonicalize_path, ensure_dcr_dir, find_project_root,
}; };
use crate::utils::log::error;
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, printc}; use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, printc};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
@@ -290,7 +291,7 @@ pub fn r#gen(args: &[String]) -> i32 {
"vscode" => gen_vscode(rest), "vscode" => gen_vscode(rest),
"clion" => gen_clion(rest), "clion" => gen_clion(rest),
_ => { _ => {
error(&format!("Unknown gen subcommand: {subcommand}")); error!("Unknown gen subcommand: {subcommand}");
1 1
} }
} }
@@ -853,7 +854,7 @@ fn gen_project_info(args: &[String]) -> i32 {
let all = match collect_all(&root, &profile) { let all = match collect_all(&root, &profile) {
Ok(v) => v, Ok(v) => v,
Err(e) => { Err(e) => {
error(&e); error!("{e}");
return 1; return 1;
} }
}; };
@@ -975,7 +976,7 @@ fn gen_compile_commands(args: &[String]) -> i32 {
let all = match collect_all(&root, &profile) { let all = match collect_all(&root, &profile) {
Ok(v) => v, Ok(v) => v,
Err(e) => { Err(e) => {
error(&e); error!("{e}");
return 1; return 1;
} }
}; };
@@ -988,7 +989,7 @@ fn gen_compile_commands(args: &[String]) -> i32 {
/// Used by `compile-commands`, `vscode`, and `clion`. /// Used by `compile-commands`, `vscode`, and `clion`.
fn gen_compile_commands_inner(root: &Path, profile: &str, all: &[ProjectInfo], quiet: bool) -> i32 { fn gen_compile_commands_inner(root: &Path, profile: &str, all: &[ProjectInfo], quiet: bool) -> i32 {
if let Err(e) = ensure_dcr_dir(root) { if let Err(e) = ensure_dcr_dir(root) {
error(&format!("Failed to create .dcr/: {e}")); error!("Failed to create .dcr/: {e}");
return 1; return 1;
} }
@@ -1009,7 +1010,7 @@ fn gen_compile_commands_inner(root: &Path, profile: &str, all: &[ProjectInfo], q
0 0
} }
Err(e) => { Err(e) => {
error(&format!("Failed to write compile_commands.json: {e}")); error!("Failed to write compile_commands.json: {e}");
1 1
} }
} }
@@ -1163,7 +1164,7 @@ fn gen_vscode(args: &[String]) -> i32 {
let all = match collect_all(&root, &profile) { let all = match collect_all(&root, &profile) {
Ok(v) => v, Ok(v) => v,
Err(e) => { Err(e) => {
error(&e); error!("{e}");
return 1; return 1;
} }
}; };
@@ -1176,13 +1177,13 @@ fn gen_vscode(args: &[String]) -> i32 {
let vscode_dir = root.join(".vscode"); let vscode_dir = root.join(".vscode");
if let Err(e) = std::fs::create_dir_all(&vscode_dir) { if let Err(e) = std::fs::create_dir_all(&vscode_dir) {
error(&format!("Failed to create .vscode/: {e}")); error!("Failed to create .vscode/: {e}");
return 1; return 1;
} }
// tasks.json // tasks.json
if let Err(e) = std::fs::write(vscode_dir.join("tasks.json"), gen_tasks_json()) { if let Err(e) = std::fs::write(vscode_dir.join("tasks.json"), gen_tasks_json()) {
error(&format!("Failed to write tasks.json: {e}")); error!("Failed to write tasks.json: {e}");
return 1; return 1;
} }
println!("Generated {}", vscode_dir.join("tasks.json").display()); println!("Generated {}", vscode_dir.join("tasks.json").display());
@@ -1190,7 +1191,7 @@ fn gen_vscode(args: &[String]) -> i32 {
// launch.json — one entry per binary target // launch.json — one entry per binary target
let launch = gen_launch_json(&all, &root); let launch = gen_launch_json(&all, &root);
if let Err(e) = std::fs::write(vscode_dir.join("launch.json"), launch) { if let Err(e) = std::fs::write(vscode_dir.join("launch.json"), launch) {
error(&format!("Failed to write launch.json: {e}")); error!("Failed to write launch.json: {e}");
return 1; return 1;
} }
println!("Generated {}", vscode_dir.join("launch.json").display()); println!("Generated {}", vscode_dir.join("launch.json").display());
@@ -1198,14 +1199,14 @@ fn gen_vscode(args: &[String]) -> i32 {
// settings.json (clangd compile-commands-dir) // settings.json (clangd compile-commands-dir)
let settings = gen_settings_json(&root); let settings = gen_settings_json(&root);
if let Err(e) = std::fs::write(vscode_dir.join("settings.json"), settings) { if let Err(e) = std::fs::write(vscode_dir.join("settings.json"), settings) {
error(&format!("Failed to write settings.json: {e}")); error!("Failed to write settings.json: {e}");
return 1; return 1;
} }
println!("Generated {}", vscode_dir.join("settings.json").display()); println!("Generated {}", vscode_dir.join("settings.json").display());
// extensions.json — disable cpptools, recommend clangd // extensions.json — disable cpptools, recommend clangd
if let Err(e) = std::fs::write(vscode_dir.join("extensions.json"), gen_extensions_json()) { if let Err(e) = std::fs::write(vscode_dir.join("extensions.json"), gen_extensions_json()) {
error(&format!("Failed to write extensions.json: {e}")); error!("Failed to write extensions.json: {e}");
return 1; return 1;
} }
println!("Generated {}", vscode_dir.join("extensions.json").display()); println!("Generated {}", vscode_dir.join("extensions.json").display());
@@ -1453,7 +1454,7 @@ fn gen_clion(args: &[String]) -> i32 {
let all = match collect_all(&root, &profile) { let all = match collect_all(&root, &profile) {
Ok(v) => v, Ok(v) => v,
Err(e) => { Err(e) => {
error(&e); error!("{e}");
return 1; return 1;
} }
}; };
@@ -1466,19 +1467,19 @@ fn gen_clion(args: &[String]) -> i32 {
let idea_dir = root.join(".idea"); let idea_dir = root.join(".idea");
if let Err(e) = std::fs::create_dir_all(&idea_dir) { if let Err(e) = std::fs::create_dir_all(&idea_dir) {
error(&format!("Failed to create .idea/: {e}")); error!("Failed to create .idea/: {e}");
return 1; return 1;
} }
let run_configs_dir = idea_dir.join("runConfigurations"); let run_configs_dir = idea_dir.join("runConfigurations");
if let Err(e) = std::fs::create_dir_all(&run_configs_dir) { if let Err(e) = std::fs::create_dir_all(&run_configs_dir) {
error(&format!("Failed to create .idea/runConfigurations/: {e}")); error!("Failed to create .idea/runConfigurations/: {e}");
return 1; return 1;
} }
// externalTools.xml // externalTools.xml
let ext_tools = gen_clion_external_tools(); let ext_tools = gen_clion_external_tools();
if let Err(e) = std::fs::write(idea_dir.join("externalTools.xml"), ext_tools) { if let Err(e) = std::fs::write(idea_dir.join("externalTools.xml"), ext_tools) {
error(&format!("Failed to write externalTools.xml: {e}")); error!("Failed to write externalTools.xml: {e}");
return 1; return 1;
} }
println!("Generated {}", idea_dir.join("externalTools.xml").display()); println!("Generated {}", idea_dir.join("externalTools.xml").display());
@@ -1486,7 +1487,7 @@ fn gen_clion(args: &[String]) -> i32 {
// customTargets.xml // customTargets.xml
let targets = gen_clion_custom_targets(); let targets = gen_clion_custom_targets();
if let Err(e) = std::fs::write(idea_dir.join("customTargets.xml"), targets) { if let Err(e) = std::fs::write(idea_dir.join("customTargets.xml"), targets) {
error(&format!("Failed to write customTargets.xml: {e}")); error!("Failed to write customTargets.xml: {e}");
return 1; return 1;
} }
println!("Generated {}", idea_dir.join("customTargets.xml").display()); println!("Generated {}", idea_dir.join("customTargets.xml").display());
@@ -1494,7 +1495,7 @@ fn gen_clion(args: &[String]) -> i32 {
// misc.xml — point CLion at compile_commands.json // misc.xml — point CLion at compile_commands.json
let misc = gen_clion_misc_xml(&root); let misc = gen_clion_misc_xml(&root);
if let Err(e) = std::fs::write(idea_dir.join("misc.xml"), misc) { if let Err(e) = std::fs::write(idea_dir.join("misc.xml"), misc) {
error(&format!("Failed to write misc.xml: {e}")); error!("Failed to write misc.xml: {e}");
return 1; return 1;
} }
println!("Generated {}", idea_dir.join("misc.xml").display()); println!("Generated {}", idea_dir.join("misc.xml").display());
@@ -1502,7 +1503,7 @@ fn gen_clion(args: &[String]) -> i32 {
// .idea/.gitignore // .idea/.gitignore
let gitignore = "# CLion generated files\nworkspace.xml\n*.iml\n"; let gitignore = "# CLion generated files\nworkspace.xml\n*.iml\n";
if let Err(e) = std::fs::write(idea_dir.join(".gitignore"), gitignore) { if let Err(e) = std::fs::write(idea_dir.join(".gitignore"), gitignore) {
error(&format!("Failed to write .idea/.gitignore: {e}")); error!("Failed to write .idea/.gitignore: {e}");
return 1; return 1;
} }
println!("Generated {}", idea_dir.join(".gitignore").display()); println!("Generated {}", idea_dir.join(".gitignore").display());
@@ -1516,7 +1517,7 @@ fn gen_clion(args: &[String]) -> i32 {
let fname = format!("{}.xml", sanitize_filename(&info.name)); let fname = format!("{}.xml", sanitize_filename(&info.name));
let path = run_configs_dir.join(&fname); let path = run_configs_dir.join(&fname);
if let Err(e) = std::fs::write(&path, xml) { if let Err(e) = std::fs::write(&path, xml) {
error(&format!("Failed to write runConfigurations/{fname}: {e}")); error!("Failed to write runConfigurations/{fname}: {e}");
return 1; return 1;
} }
println!("Generated {}", path.display()); println!("Generated {}", path.display());
@@ -1720,18 +1721,18 @@ fn parse_gen_args(args: &[String]) -> Result<(PathBuf, String, bool), i32> {
} }
let start = std::env::current_dir().map_err(|_| { let start = std::env::current_dir().map_err(|_| {
error("Failed to determine current directory"); error!("Failed to determine current directory");
1i32 1i32
})?; })?;
let root = match find_project_root(&start) { let root = match find_project_root(&start) {
Ok(Some(r)) => canonicalize_path(&r), Ok(Some(r)) => canonicalize_path(&r),
Ok(None) => { Ok(None) => {
error("dcr.toml not found"); error!("dcr.toml not found");
return Err(1); return Err(1);
} }
Err(_) => { Err(_) => {
error("Failed to find project root"); error!("Failed to find project root");
return Err(1); return Err(1);
} }
}; };

View File

@@ -15,11 +15,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::prelude::*;
use crate::config::FILE_MAIN_C; use crate::config::FILE_MAIN_C;
use crate::core::build_config::{Config, validate_package_name}; use crate::core::build_config::{Config, validate_package_name};
use crate::core::vcs::VcsKind; use crate::core::vcs::VcsKind;
use crate::utils::fs::check_dir; use crate::utils::fs::check_dir;
use crate::utils::log::{error, warn};
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc}; use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc};
use std::fs; use std::fs;
use std::io::Write; use std::io::Write;
@@ -48,7 +49,7 @@ pub fn init(args: &[String]) -> i32 {
if let Some(val) = iter.next() { if let Some(val) = iter.next() {
vcs_str = Some(val.clone()); vcs_str = Some(val.clone());
} else { } else {
error("--vcs requires a value"); error!("--vcs requires a value");
return 1; return 1;
} }
} else if let Some(stripped) = arg.strip_prefix("--vcs=") { } else if let Some(stripped) = arg.strip_prefix("--vcs=") {
@@ -59,7 +60,7 @@ pub fn init(args: &[String]) -> i32 {
} }
if !clean_args.is_empty() { if !clean_args.is_empty() {
warn("Command does not support additional arguments"); warn!("Command does not support additional arguments");
return 1; return 1;
} }
@@ -71,16 +72,15 @@ pub fn init(args: &[String]) -> i32 {
.unwrap_or_else(|| "project".to_string()); .unwrap_or_else(|| "project".to_string());
if !items.is_empty() { if !items.is_empty() {
error("Directory not empty"); error!("Directory not empty");
return 1; return 1;
} }
if let Err(e) = validate_package_name(&project_name) { if let Err(e) = validate_package_name(&project_name) {
error(&format!( error!(
"Invalid project name `{}`: {}", "Invalid project name `{}`: {e}",
colored(&project_name, BOLD_CYAN), colored(&project_name, BOLD_CYAN),
e );
));
return 1; return 1;
} }
@@ -91,7 +91,7 @@ pub fn init(args: &[String]) -> i32 {
// Create and initialize default manifest (dcr.toml). // Create and initialize default manifest (dcr.toml).
if Config::create("./dcr.toml", Some(&project_name)).is_err() { if Config::create("./dcr.toml", Some(&project_name)).is_err() {
error("Failed to create dcr.toml"); error!("Failed to create dcr.toml");
return 1; return 1;
} }
println!( println!(
@@ -102,18 +102,18 @@ pub fn init(args: &[String]) -> i32 {
// Create src directory and write template main.c file. // Create src directory and write template main.c file.
if fs::create_dir("src").is_err() { if fs::create_dir("src").is_err() {
error("Failed to create src/"); error!("Failed to create src/");
return 1; return 1;
} }
let mut main_c = match fs::File::create("./src/main.c") { let mut main_c = match fs::File::create("./src/main.c") {
Ok(file) => file, Ok(file) => file,
Err(_) => { Err(_) => {
error("Failed to create src/main.c"); error!("Failed to create src/main.c");
return 1; return 1;
} }
}; };
if main_c.write_all(FILE_MAIN_C.as_bytes()).is_err() { if main_c.write_all(FILE_MAIN_C.as_bytes()).is_err() {
error("Failed to write src/main.c"); error!("Failed to write src/main.c");
return 1; return 1;
} }
println!( println!(
@@ -128,7 +128,7 @@ pub fn init(args: &[String]) -> i32 {
match VcsKind::parse(vcs_val) { match VcsKind::parse(vcs_val) {
Ok(kind) => vcs_kind = kind, Ok(kind) => vcs_kind = kind,
Err(e) => { Err(e) => {
error(&e); error!("{e}");
return 1; return 1;
} }
} }
@@ -142,7 +142,7 @@ pub fn init(args: &[String]) -> i32 {
if crate::utils::git::is_git_available() { if crate::utils::git::is_git_available() {
let project_path = std::path::Path::new("."); let project_path = std::path::Path::new(".");
if let Err(e) = crate::core::vcs::init_vcs(vcs_kind, project_path) { if let Err(e) = crate::core::vcs::init_vcs(vcs_kind, project_path) {
warn(&format!("Failed to initialize git repository: {}", e)); warn!("Failed to initialize git repository: {e}");
} else { } else {
println!( println!(
" {} Initialized git repository", " {} Initialized git repository",
@@ -150,14 +150,14 @@ pub fn init(args: &[String]) -> i32 {
); );
} }
} else { } else {
warn( warn!(
"Git is not installed or not found in PATH. Skipping Git repository initialization.", "Git is not installed or not found in PATH. Skipping Git repository initialization.",
); );
} }
} }
if let Err(e) = crate::utils::fs::ensure_gitignore_has_dcr(std::path::Path::new(".")) { if let Err(e) = crate::utils::fs::ensure_gitignore_has_dcr(std::path::Path::new(".")) {
warn(&format!("Failed to update .gitignore: {e}")); warn!("Failed to update .gitignore: {e}");
} }
println!( println!(

View File

@@ -15,11 +15,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::prelude::*;
use crate::core::build::common; use crate::core::build::common;
use crate::core::build_config::Config; use crate::core::build_config::Config;
use crate::utils::build::{get_bool_with_profile, get_list_with_profile}; use crate::utils::build::{get_bool_with_profile, get_list_with_profile};
use crate::utils::fs::find_project_root; use crate::utils::fs::find_project_root;
use crate::utils::log::error;
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, BOLD_YELLOW, colored, printc}; use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, BOLD_YELLOW, colored, printc};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::Command; use std::process::Command;
@@ -46,7 +47,7 @@ pub fn lint(args: &[String]) -> i32 {
let start_dir = match std::env::current_dir() { let start_dir = match std::env::current_dir() {
Ok(dir) => dir, Ok(dir) => dir,
Err(_) => { Err(_) => {
error("Failed to determine current directory"); error!("Failed to determine current directory");
return 1; return 1;
} }
}; };
@@ -54,11 +55,11 @@ pub fn lint(args: &[String]) -> i32 {
let root = match find_project_root(&start_dir) { let root = match find_project_root(&start_dir) {
Ok(Some(r)) => r, Ok(Some(r)) => r,
Ok(None) => { Ok(None) => {
error("dcr.toml not found"); error!("dcr.toml not found");
return 1; return 1;
} }
Err(_) => { Err(_) => {
error("Failed to find project root"); error!("Failed to find project root");
return 1; return 1;
} }
}; };
@@ -66,7 +67,7 @@ pub fn lint(args: &[String]) -> i32 {
let config = match Config::open(&root.join("dcr.toml").to_string_lossy()) { let config = match Config::open(&root.join("dcr.toml").to_string_lossy()) {
Ok(c) => c, Ok(c) => c,
Err(e) => { Err(e) => {
error(&format!("Failed to load dcr.toml: {e}")); error!("Failed to load dcr.toml: {e}");
return 1; return 1;
} }
}; };
@@ -98,7 +99,7 @@ pub fn lint(args: &[String]) -> i32 {
match common::collect_sources(&roots, &cxx_extensions, &exclude_dirs, &include_paths) { match common::collect_sources(&roots, &cxx_extensions, &exclude_dirs, &include_paths) {
Ok(f) => f, Ok(f) => f,
Err(e) => { Err(e) => {
error(&format!("Failed to collect source files: {e}")); error!("Failed to collect source files: {e}");
return 1; return 1;
} }
}; };
@@ -142,7 +143,7 @@ pub fn lint(args: &[String]) -> i32 {
let output = match cmd.output() { let output = match cmd.output() {
Ok(o) => o, Ok(o) => o,
Err(e) => { Err(e) => {
error(&format!("Failed to execute clang-tidy: {}", e)); error!("Failed to execute clang-tidy: {e}");
return 1; return 1;
} }
}; };

View File

@@ -15,11 +15,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::prelude::*;
use crate::config::FILE_MAIN_C; use crate::config::FILE_MAIN_C;
use crate::core::build_config::{Config, validate_package_name}; use crate::core::build_config::{Config, validate_package_name};
use crate::core::vcs::VcsKind; use crate::core::vcs::VcsKind;
use crate::utils::fs::check_dir; use crate::utils::fs::check_dir;
use crate::utils::log::{error, warn};
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc}; use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc};
use std::fs; use std::fs;
use std::io::Write; use std::io::Write;
@@ -50,7 +51,7 @@ pub fn new(args: &[String]) -> i32 {
if let Some(val) = iter.next() { if let Some(val) = iter.next() {
vcs_str = Some(val.clone()); vcs_str = Some(val.clone());
} else { } else {
error("--vcs requires a value"); error!("--vcs requires a value");
return 1; return 1;
} }
} else if let Some(stripped) = arg.strip_prefix("--vcs=") { } else if let Some(stripped) = arg.strip_prefix("--vcs=") {
@@ -61,11 +62,11 @@ pub fn new(args: &[String]) -> i32 {
} }
if clean_args.is_empty() { if clean_args.is_empty() {
error("Project name not specified"); error!("Project name not specified");
return 1; return 1;
} }
if clean_args.len() > 1 { if clean_args.len() > 1 {
warn("Command does not support additional arguments"); warn!("Command does not support additional arguments");
return 1; return 1;
} }
@@ -76,19 +77,18 @@ pub fn new(args: &[String]) -> i32 {
); );
if let Err(e) = validate_package_name(project_name) { if let Err(e) = validate_package_name(project_name) {
error(&format!( error!(
"Invalid project name `{}`: {}", "Invalid project name `{}`: {e}",
colored(project_name, BOLD_CYAN), colored(project_name, BOLD_CYAN),
e );
));
return 1; return 1;
} }
if items.contains(project_name) { if items.contains(project_name) {
error(&format!( error!(
"Directory `{}` already exists\n", "Directory `{}` already exists\n",
colored(project_name, BOLD_CYAN) colored(project_name, BOLD_CYAN)
)); );
printc("Hint:", BOLD_CYAN); printc("Hint:", BOLD_CYAN);
println!( println!(
" Use `{}` to initialize an existing project\n or specify a different project name", " Use `{}` to initialize an existing project\n or specify a different project name",
@@ -98,7 +98,7 @@ pub fn new(args: &[String]) -> i32 {
} }
if fs::create_dir(project_name).is_err() { if fs::create_dir(project_name).is_err() {
error("Failed to create directory"); error!("Failed to create directory");
return 1; return 1;
} }
println!( println!(
@@ -110,7 +110,7 @@ pub fn new(args: &[String]) -> i32 {
// Initialize and write project configuration manifest (dcr.toml). // Initialize and write project configuration manifest (dcr.toml).
let toml_path = format!("./{project_name}/dcr.toml"); let toml_path = format!("./{project_name}/dcr.toml");
if Config::create(&toml_path, Some(project_name)).is_err() { if Config::create(&toml_path, Some(project_name)).is_err() {
error("Failed to create dcr.toml"); error!("Failed to create dcr.toml");
return 1; return 1;
} }
println!( println!(
@@ -121,19 +121,19 @@ pub fn new(args: &[String]) -> i32 {
// Generate src directory and populate initial main.c file. // Generate src directory and populate initial main.c file.
if fs::create_dir_all(format!("./{project_name}/src")).is_err() { if fs::create_dir_all(format!("./{project_name}/src")).is_err() {
error("Failed to create src/"); error!("Failed to create src/");
return 1; return 1;
} }
let main_c_path = format!("./{project_name}/src/main.c"); let main_c_path = format!("./{project_name}/src/main.c");
let mut main_c = match fs::File::create(&main_c_path) { let mut main_c = match fs::File::create(&main_c_path) {
Ok(file) => file, Ok(file) => file,
Err(_) => { Err(_) => {
error("Failed to create src/main.c"); error!("Failed to create src/main.c");
return 1; return 1;
} }
}; };
if main_c.write_all(FILE_MAIN_C.as_bytes()).is_err() { if main_c.write_all(FILE_MAIN_C.as_bytes()).is_err() {
error("Failed to write src/main.c"); error!("Failed to write src/main.c");
return 1; return 1;
} }
println!( println!(
@@ -148,7 +148,8 @@ pub fn new(args: &[String]) -> i32 {
match VcsKind::parse(vcs_val) { match VcsKind::parse(vcs_val) {
Ok(kind) => vcs_kind = kind, Ok(kind) => vcs_kind = kind,
Err(e) => { Err(e) => {
error(&e); error!("{e}");
return 1; return 1;
} }
} }
@@ -162,7 +163,7 @@ pub fn new(args: &[String]) -> i32 {
if crate::utils::git::is_git_available() { if crate::utils::git::is_git_available() {
let project_path = std::path::Path::new(project_name); let project_path = std::path::Path::new(project_name);
if let Err(e) = crate::core::vcs::init_vcs(vcs_kind, project_path) { if let Err(e) = crate::core::vcs::init_vcs(vcs_kind, project_path) {
warn(&format!("Failed to initialize git repository: {}", e)); warn!("Failed to initialize git repository: {e}");
} else { } else {
println!( println!(
" {} Initialized git repository", " {} Initialized git repository",
@@ -170,7 +171,7 @@ pub fn new(args: &[String]) -> i32 {
); );
} }
} else { } else {
warn( warn!(
"Git is not installed or not found in PATH. Skipping Git repository initialization.", "Git is not installed or not found in PATH. Skipping Git repository initialization.",
); );
} }
@@ -178,7 +179,7 @@ pub fn new(args: &[String]) -> i32 {
let project_path = std::path::Path::new(project_name); let project_path = std::path::Path::new(project_name);
if let Err(e) = crate::utils::fs::ensure_gitignore_has_dcr(project_path) { if let Err(e) = crate::utils::fs::ensure_gitignore_has_dcr(project_path) {
warn(&format!("Failed to update .gitignore: {e}")); warn!("Failed to update .gitignore: {e}");
} }
println!( println!(

View File

@@ -15,6 +15,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::prelude::*;
use crate::cli::build::build; use crate::cli::build::build;
use crate::cli::flags::parse_build_run_flags; use crate::cli::flags::parse_build_run_flags;
use crate::core::build_config::Config; use crate::core::build_config::Config;
@@ -22,7 +24,6 @@ use crate::core::runner::run_binary;
use crate::utils::build::{normalize_target_os, parse_version_info, substitute_vars}; use crate::utils::build::{normalize_target_os, parse_version_info, substitute_vars};
use crate::utils::fs::find_project_root; use crate::utils::fs::find_project_root;
use crate::utils::fs::with_dir; use crate::utils::fs::with_dir;
use crate::utils::log::error;
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc}; use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc};
use std::path::Path; use std::path::Path;
use std::process::Command; use std::process::Command;
@@ -91,18 +92,18 @@ pub fn run(args: &[String]) -> i32 {
let start_dir = match std::env::current_dir() { let start_dir = match std::env::current_dir() {
Ok(dir) => dir, Ok(dir) => dir,
Err(_) => { Err(_) => {
error("Failed to determine current directory"); error!("Failed to determine current directory");
return 1; return 1;
} }
}; };
let root = match find_project_root(&start_dir) { let root = match find_project_root(&start_dir) {
Ok(Some(dir)) => dir, Ok(Some(dir)) => dir,
Ok(None) => { Ok(None) => {
error("dcr.toml file not found"); error!("dcr.toml file not found");
return 1; return 1;
} }
Err(_) => { Err(_) => {
error("Failed to find project root"); error!("Failed to find project root");
return 1; return 1;
} }
}; };
@@ -111,7 +112,8 @@ pub fn run(args: &[String]) -> i32 {
}) { }) {
Ok(cfg) => cfg, Ok(cfg) => cfg,
Err(err) => { Err(err) => {
error(&err); error!("{err}");
return 1; return 1;
} }
}; };
@@ -143,11 +145,12 @@ pub fn run(args: &[String]) -> i32 {
) { ) {
Ok(Some(ws)) => ws, Ok(Some(ws)) => ws,
Ok(None) => { Ok(None) => {
error("Workspace root has no members defined"); error!("Workspace root has no members defined");
return 1; return 1;
} }
Err(e) => { Err(e) => {
error(&e); error!("{e}");
return 1; return 1;
} }
}; };
@@ -159,9 +162,9 @@ pub fn run(args: &[String]) -> i32 {
Some(m) => m, Some(m) => m,
None => { None => {
if let Some(name) = &flags.workspace { if let Some(name) = &flags.workspace {
error(&format!("Workspace member '{name}' not found")); error!("Workspace member '{name}' not found");
} else { } else {
error("No workspace member to run (set `main = true` on one member)"); error!("No workspace member to run (set `main = true` on one member)");
} }
return 1; return 1;
} }
@@ -172,7 +175,8 @@ pub fn run(args: &[String]) -> i32 {
}) { }) {
Ok(code) => code, Ok(code) => code,
Err(e) => { Err(e) => {
error(&e); error!("{e}");
1 1
} }
}; };
@@ -181,7 +185,7 @@ pub fn run(args: &[String]) -> i32 {
match run_project(&root, &flags, None) { match run_project(&root, &flags, None) {
Ok(code) => code, Ok(code) => code,
Err(e) => { Err(e) => {
error(&e); error!("{e}");
1 1
} }
} }

View File

@@ -15,6 +15,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::prelude::*;
use crate::cli::build; use crate::cli::build;
use crate::config::{FILE_DCR_TEST_H, FILE_TEST_C, flags}; use crate::config::{FILE_DCR_TEST_H, FILE_TEST_C, flags};
use crate::core::build_config::Config; use crate::core::build_config::Config;
@@ -23,7 +25,6 @@ use crate::utils::build::{
get_string_with_profile, resolve_compiler, resolve_pkg_config_flags, get_string_with_profile, resolve_compiler, resolve_pkg_config_flags,
}; };
use crate::utils::fs::{find_project_root, with_dir}; use crate::utils::fs::{find_project_root, with_dir};
use crate::utils::log::error;
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, BOLD_RED, RESET, colored, printc}; use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, BOLD_RED, RESET, colored, printc};
use std::fs; use std::fs;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@@ -60,25 +61,25 @@ pub fn test(args: &[String]) -> i32 {
profile = arg.trim_start_matches("--"); profile = arg.trim_start_matches("--");
continue; continue;
} }
error("Unknown argument"); error!("Unknown argument");
return 1; return 1;
} }
let start_dir = match std::env::current_dir() { let start_dir = match std::env::current_dir() {
Ok(dir) => dir, Ok(dir) => dir,
Err(_) => { Err(_) => {
error("Failed to determine current directory"); error!("Failed to determine current directory");
return 1; return 1;
} }
}; };
let root = match find_project_root(&start_dir) { let root = match find_project_root(&start_dir) {
Ok(Some(dir)) => dir, Ok(Some(dir)) => dir,
Ok(None) => { Ok(None) => {
error("dcr.toml file not found"); error!("dcr.toml file not found");
return 1; return 1;
} }
Err(_) => { Err(_) => {
error("Failed to find project root"); error!("Failed to find project root");
return 1; return 1;
} }
}; };
@@ -87,7 +88,8 @@ pub fn test(args: &[String]) -> i32 {
match with_dir(&root, ensure_test_header) { match with_dir(&root, ensure_test_header) {
Ok(()) => {} Ok(()) => {}
Err(msg) => { Err(msg) => {
error(&msg); error!("{msg}");
return 1; return 1;
} }
} }
@@ -96,7 +98,7 @@ pub fn test(args: &[String]) -> i32 {
match with_dir(&root, || run_testsuite(profile)) { match with_dir(&root, || run_testsuite(profile)) {
Ok(code) => code, Ok(code) => code,
Err(msg) => { Err(msg) => {
error(&msg); error!("{msg}");
1 1
} }
} }

View File

@@ -15,8 +15,9 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::prelude::*;
use crate::core::build_config::Config; use crate::core::build_config::Config;
use crate::utils::log::error;
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, printc}; use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, printc};
use std::collections::HashSet; use std::collections::HashSet;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@@ -40,7 +41,7 @@ pub fn tree(args: &[String]) -> i32 {
let config = match Config::open("dcr.toml") { let config = match Config::open("dcr.toml") {
Ok(c) => c, Ok(c) => c,
Err(_) => { Err(_) => {
error("dcr.toml not found in current directory"); error!("dcr.toml not found in current directory");
return 1; return 1;
} }
}; };

View File

@@ -15,6 +15,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::prelude::*;
use serde::Deserialize; use serde::Deserialize;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::fs; use std::fs;
@@ -334,35 +336,35 @@ impl Config {
.map(str::trim) .map(str::trim)
.filter(|s| !s.is_empty()); .filter(|s| !s.is_empty());
let Some(required) = required else { let Some(required) = required else {
crate::utils::log::warn(&format!( warn!(
"package.dcr-version is missing in {}. Add e.g. dcr-version = \"{tool}\" \ "package.dcr-version is missing in {}. Add e.g. dcr-version = \"{tool}\" \
so collaborators know which dcr this project targets \ so collaborators know which dcr this project targets \
(written automatically by `dcr new` / `dcr init`).", (written automatically by `dcr new` / `dcr init`).",
self.path.display() self.path.display(),
)); );
return; return;
}; };
match crate::utils::build::compare_semver(tool, required) { match crate::utils::build::compare_semver(tool, required) {
Some(std::cmp::Ordering::Less) => { Some(std::cmp::Ordering::Less) => {
crate::utils::log::warn(&format!( warn!(
"this project requires dcr {required} (package.dcr-version), \ "this project requires dcr {required} (package.dcr-version), \
but you are running dcr {tool}. Some features may be missing or misbehave. \ but you are running dcr {tool}. Some features may be missing or misbehave. \
Upgrade dcr (e.g. `dcr --update`) or lower package.dcr-version if intentional." Upgrade dcr (e.g. `dcr --update`) or lower package.dcr-version if intentional."
)); );
} }
Some(std::cmp::Ordering::Greater) => { Some(std::cmp::Ordering::Greater) => {
crate::utils::log::warn(&format!( warn!(
"this project pins dcr {required} (package.dcr-version), \ "this project pins dcr {required} (package.dcr-version), \
but you are running newer dcr {tool}. Config/defaults may be outdated. \ but you are running newer dcr {tool}. Config/defaults may be outdated. \
Review the changelog and bump package.dcr-version when the project is verified." Review the changelog and bump package.dcr-version when the project is verified.",
)); );
} }
Some(std::cmp::Ordering::Equal) => {} Some(std::cmp::Ordering::Equal) => {}
None => { None => {
crate::utils::log::warn(&format!( warn!(
"package.dcr-version = \"{required}\" is not a valid semver (expected X.Y.Z); ignoring" "package.dcr-version = \"{required}\" is not a valid semver (expected X.Y.Z); ignoring",
)); );
} }
} }
} }

View File

@@ -15,8 +15,9 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::prelude::*;
use crate::core::build_config::Config; use crate::core::build_config::Config;
use crate::utils::log::warn;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
/// Version information parsed from a version string. /// Version information parsed from a version string.
@@ -251,10 +252,10 @@ pub fn normalize_target_os(target: &str) -> &str {
"windows" => "x86_64-pc-windows-msvc", "windows" => "x86_64-pc-windows-msvc",
_ if target.contains('-') => target, _ if target.contains('-') => target,
_ => { _ => {
warn(&format!( warn!(
"Unknown target '{}', using as-is. Supported short names: linux, macos, windows", "Unknown target '{}', using as-is. Supported short names: linux, macos, windows",
target target
)); );
target target
} }
} }

View File

@@ -15,9 +15,6 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
pub fn warn(_: &str) {}
pub fn error(_: &str) {}
use anstyle::{AnsiColor, Style}; use anstyle::{AnsiColor, Style};
use env_logger::*; use env_logger::*;
use log::*; use log::*;