aboutsummaryrefslogtreecommitdiff
path: root/mling
diff options
context:
space:
mode:
Diffstat (limited to 'mling')
-rw-r--r--mling/res/template_0.2/command/Cargo.toml.tmpl (renamed from mling/res/template_0.2/command/Cargo.toml)0
-rw-r--r--mling/res/template_0.2/flat/Cargo.toml.tmpl (renamed from mling/res/template_0.2/flat/Cargo.toml)0
-rw-r--r--mling/res/template_0.2/modularity/Cargo.toml.tmpl (renamed from mling/res/template_0.2/modularity/Cargo.toml)0
-rw-r--r--mling/src/cli.rs30
-rw-r--r--mling/src/errors/io_error.rs96
-rw-r--r--mling/src/lib.rs2
-rw-r--r--mling/src/pkg_mgr/installer.rs1
-rw-r--r--mling/src/proj_mgr/checklist_reader.rs35
-rw-r--r--mling/src/proj_mgr/generator.rs25
-rw-r--r--mling/src/proj_mgr/show_binaries.rs17
-rw-r--r--mling/src/proj_mgr/show_directories.rs17
11 files changed, 133 insertions, 90 deletions
diff --git a/mling/res/template_0.2/command/Cargo.toml b/mling/res/template_0.2/command/Cargo.toml.tmpl
index e69de29..e69de29 100644
--- a/mling/res/template_0.2/command/Cargo.toml
+++ b/mling/res/template_0.2/command/Cargo.toml.tmpl
diff --git a/mling/res/template_0.2/flat/Cargo.toml b/mling/res/template_0.2/flat/Cargo.toml.tmpl
index e69de29..e69de29 100644
--- a/mling/res/template_0.2/flat/Cargo.toml
+++ b/mling/res/template_0.2/flat/Cargo.toml.tmpl
diff --git a/mling/res/template_0.2/modularity/Cargo.toml b/mling/res/template_0.2/modularity/Cargo.toml.tmpl
index e69de29..e69de29 100644
--- a/mling/res/template_0.2/modularity/Cargo.toml
+++ b/mling/res/template_0.2/modularity/Cargo.toml.tmpl
diff --git a/mling/src/cli.rs b/mling/src/cli.rs
index 3000645..67d2ef0 100644
--- a/mling/src/cli.rs
+++ b/mling/src/cli.rs
@@ -8,13 +8,13 @@ use crate::{
};
use colored::Colorize;
use mingling::{
- Groupped, Program,
+ Groupped, Program, RenderResult,
hook::ProgramHook,
- macros::{chain, help, pack, program_setup, r_println, renderer},
+ macros::{chain, help, pack, program_setup, renderer},
res::ResExitCode,
setup::{ExitCodeSetup, HelpFlagSetup, QuietFlagSetup, StructuralRendererSetup},
};
-use std::{env::current_dir, path::PathBuf, process::exit, str::FromStr};
+use std::{env::current_dir, io::Write, path::PathBuf, process::exit, str::FromStr};
pub fn run() {
#[cfg(windows)]
@@ -167,21 +167,29 @@ pub fn handle_error_dispatcher_not_found(err: ErrorDispatcherNotFound) -> Next {
}
#[renderer]
-pub fn render_mling_help(_prev: ResultMlingHelp, ec: &mut ResExitCode) {
- r_println!("{}", markdown(include_str!("helps/mling_help.txt")));
+pub fn render_mling_help(_prev: ResultMlingHelp, ec: &mut ResExitCode) -> RenderResult {
+ let mut result = RenderResult::default();
+ writeln!(result, "{}", markdown(include_str!("helps/mling_help.txt"))).ok();
ec.exit_code = 0;
+ result
}
#[renderer]
-pub fn render_unknown_command(prev: ResultUnknownCommand, ec: &mut ResExitCode) {
- r_println!(
+pub fn render_unknown_command(prev: ResultUnknownCommand, ec: &mut ResExitCode) -> RenderResult {
+ let mut result = RenderResult::default();
+ writeln!(
+ result,
"{}",
eformat_cargo!("no such command: `{}`", prev.bright_yellow().bold())
- );
- r_println!();
- r_println!(
+ )
+ .ok();
+ writeln!(result).ok();
+ writeln!(
+ result,
"{}",
hformat_cargo!("view all commands with `cargo help mling`")
- );
+ )
+ .ok();
ec.exit_code = 101;
+ result
}
diff --git a/mling/src/errors/io_error.rs b/mling/src/errors/io_error.rs
index 9f93ad7..ac503cc 100644
--- a/mling/src/errors/io_error.rs
+++ b/mling/src/errors/io_error.rs
@@ -1,4 +1,9 @@
-use mingling::{macros::{group, r_println, renderer}, res::ResExitCode};
+use mingling::{
+ RenderResult,
+ macros::{group, renderer},
+ res::ResExitCode,
+};
+use std::io::Write as _;
use crate::eformat_cargo;
@@ -46,167 +51,174 @@ pub const EC_IO_ERR_OUT_OF_MEMORY: i32 = 1037;
pub const EC_IO_ERR_OTHER: i32 = 1038;
#[renderer]
-pub fn render_error_io(err: ErrorIo, ec: &mut ResExitCode) {
+pub fn render_error_io(err: ErrorIo, ec: &mut ResExitCode) -> RenderResult {
+ let mut result = RenderResult::default();
match err.kind() {
std::io::ErrorKind::NotFound => {
- r_println!("{}", eformat_cargo!("file or directory not found"));
+ writeln!(result, "{}", eformat_cargo!("file or directory not found")).ok();
ec.exit_code = EC_IO_ERR_NOT_FOUND;
}
std::io::ErrorKind::PermissionDenied => {
- r_println!("{}", eformat_cargo!("permission denied"));
+ writeln!(result, "{}", eformat_cargo!("permission denied")).ok();
ec.exit_code = EC_IO_ERR_PERMISSION_DENIED;
}
std::io::ErrorKind::ConnectionRefused => {
- r_println!("{}", eformat_cargo!("connection refused"));
+ writeln!(result, "{}", eformat_cargo!("connection refused")).ok();
ec.exit_code = EC_IO_ERR_CONNECTION_REFUSED;
}
std::io::ErrorKind::ConnectionReset => {
- r_println!("{}", eformat_cargo!("connection reset"));
+ writeln!(result, "{}", eformat_cargo!("connection reset")).ok();
ec.exit_code = EC_IO_ERR_CONNECTION_RESET;
}
std::io::ErrorKind::HostUnreachable => {
- r_println!("{}", eformat_cargo!("host unreachable"));
+ writeln!(result, "{}", eformat_cargo!("host unreachable")).ok();
ec.exit_code = EC_IO_ERR_HOST_UNREACHABLE;
}
std::io::ErrorKind::NetworkUnreachable => {
- r_println!("{}", eformat_cargo!("network unreachable"));
+ writeln!(result, "{}", eformat_cargo!("network unreachable")).ok();
ec.exit_code = EC_IO_ERR_NETWORK_UNREACHABLE;
}
std::io::ErrorKind::ConnectionAborted => {
- r_println!("{}", eformat_cargo!("connection aborted"));
+ writeln!(result, "{}", eformat_cargo!("connection aborted")).ok();
ec.exit_code = EC_IO_ERR_CONNECTION_ABORTED;
}
std::io::ErrorKind::NotConnected => {
- r_println!("{}", eformat_cargo!("not connected"));
+ writeln!(result, "{}", eformat_cargo!("not connected")).ok();
ec.exit_code = EC_IO_ERR_NOT_CONNECTED;
}
std::io::ErrorKind::AddrInUse => {
- r_println!("{}", eformat_cargo!("address in use"));
+ writeln!(result, "{}", eformat_cargo!("address in use")).ok();
ec.exit_code = EC_IO_ERR_ADDR_IN_USE;
}
std::io::ErrorKind::AddrNotAvailable => {
- r_println!("{}", eformat_cargo!("address not available"));
+ writeln!(result, "{}", eformat_cargo!("address not available")).ok();
ec.exit_code = EC_IO_ERR_ADDR_NOT_AVAILABLE;
}
std::io::ErrorKind::NetworkDown => {
- r_println!("{}", eformat_cargo!("network down"));
+ writeln!(result, "{}", eformat_cargo!("network down")).ok();
ec.exit_code = EC_IO_ERR_NETWORK_DOWN;
}
std::io::ErrorKind::BrokenPipe => {
- r_println!("{}", eformat_cargo!("broken pipe"));
+ writeln!(result, "{}", eformat_cargo!("broken pipe")).ok();
ec.exit_code = EC_IO_ERR_BROKEN_PIPE;
}
std::io::ErrorKind::AlreadyExists => {
- r_println!("{}", eformat_cargo!("file or directory already exists"));
+ writeln!(
+ result,
+ "{}",
+ eformat_cargo!("file or directory already exists")
+ )
+ .ok();
ec.exit_code = EC_IO_ERR_ALREADY_EXISTS;
}
std::io::ErrorKind::WouldBlock => {
- r_println!("{}", eformat_cargo!("operation would block"));
+ writeln!(result, "{}", eformat_cargo!("operation would block")).ok();
ec.exit_code = EC_IO_ERR_WOULD_BLOCK;
}
std::io::ErrorKind::NotADirectory => {
- r_println!("{}", eformat_cargo!("not a directory"));
+ writeln!(result, "{}", eformat_cargo!("not a directory")).ok();
ec.exit_code = EC_IO_ERR_NOT_A_DIRECTORY;
}
std::io::ErrorKind::IsADirectory => {
- r_println!("{}", eformat_cargo!("is a directory"));
+ writeln!(result, "{}", eformat_cargo!("is a directory")).ok();
ec.exit_code = EC_IO_ERR_IS_A_DIRECTORY;
}
std::io::ErrorKind::DirectoryNotEmpty => {
- r_println!("{}", eformat_cargo!("directory not empty"));
+ writeln!(result, "{}", eformat_cargo!("directory not empty")).ok();
ec.exit_code = EC_IO_ERR_DIRECTORY_NOT_EMPTY;
}
std::io::ErrorKind::ReadOnlyFilesystem => {
- r_println!("{}", eformat_cargo!("read-only filesystem"));
+ writeln!(result, "{}", eformat_cargo!("read-only filesystem")).ok();
ec.exit_code = EC_IO_ERR_READ_ONLY_FILESYSTEM;
}
std::io::ErrorKind::StaleNetworkFileHandle => {
- r_println!("{}", eformat_cargo!("stale network file handle"));
+ writeln!(result, "{}", eformat_cargo!("stale network file handle")).ok();
ec.exit_code = EC_IO_ERR_STALE_NETWORK_FILE_HANDLE;
}
std::io::ErrorKind::InvalidInput => {
- r_println!("{}", eformat_cargo!("invalid input"));
+ writeln!(result, "{}", eformat_cargo!("invalid input")).ok();
ec.exit_code = EC_IO_ERR_INVALID_INPUT;
}
std::io::ErrorKind::InvalidData => {
- r_println!("{}", eformat_cargo!("invalid data"));
+ writeln!(result, "{}", eformat_cargo!("invalid data")).ok();
ec.exit_code = EC_IO_ERR_INVALID_DATA;
}
std::io::ErrorKind::TimedOut => {
- r_println!("{}", eformat_cargo!("timed out"));
+ writeln!(result, "{}", eformat_cargo!("timed out")).ok();
ec.exit_code = EC_IO_ERR_TIMED_OUT;
}
std::io::ErrorKind::WriteZero => {
- r_println!("{}", eformat_cargo!("write zero"));
+ writeln!(result, "{}", eformat_cargo!("write zero")).ok();
ec.exit_code = EC_IO_ERR_WRITE_ZERO;
}
std::io::ErrorKind::StorageFull => {
- r_println!("{}", eformat_cargo!("storage full"));
+ writeln!(result, "{}", eformat_cargo!("storage full")).ok();
ec.exit_code = EC_IO_ERR_STORAGE_FULL;
}
std::io::ErrorKind::NotSeekable => {
- r_println!("{}", eformat_cargo!("not seekable"));
+ writeln!(result, "{}", eformat_cargo!("not seekable")).ok();
ec.exit_code = EC_IO_ERR_NOT_SEEKABLE;
}
std::io::ErrorKind::QuotaExceeded => {
- r_println!("{}", eformat_cargo!("quota exceeded"));
+ writeln!(result, "{}", eformat_cargo!("quota exceeded")).ok();
ec.exit_code = EC_IO_ERR_QUOTA_EXCEEDED;
}
std::io::ErrorKind::FileTooLarge => {
- r_println!("{}", eformat_cargo!("file too large"));
+ writeln!(result, "{}", eformat_cargo!("file too large")).ok();
ec.exit_code = EC_IO_ERR_FILE_TOO_LARGE;
}
std::io::ErrorKind::ResourceBusy => {
- r_println!("{}", eformat_cargo!("resource busy"));
+ writeln!(result, "{}", eformat_cargo!("resource busy")).ok();
ec.exit_code = EC_IO_ERR_RESOURCE_BUSY;
}
std::io::ErrorKind::ExecutableFileBusy => {
- r_println!("{}", eformat_cargo!("executable file busy"));
+ writeln!(result, "{}", eformat_cargo!("executable file busy")).ok();
ec.exit_code = EC_IO_ERR_EXECUTABLE_FILE_BUSY;
}
std::io::ErrorKind::Deadlock => {
- r_println!("{}", eformat_cargo!("deadlock"));
+ writeln!(result, "{}", eformat_cargo!("deadlock")).ok();
ec.exit_code = EC_IO_ERR_DEADLOCK;
}
std::io::ErrorKind::CrossesDevices => {
- r_println!("{}", eformat_cargo!("crosses devices"));
+ writeln!(result, "{}", eformat_cargo!("crosses devices")).ok();
ec.exit_code = EC_IO_ERR_CROSSES_DEVICES;
}
std::io::ErrorKind::TooManyLinks => {
- r_println!("{}", eformat_cargo!("too many links"));
+ writeln!(result, "{}", eformat_cargo!("too many links")).ok();
ec.exit_code = EC_IO_ERR_TOO_MANY_LINKS;
}
std::io::ErrorKind::InvalidFilename => {
- r_println!("{}", eformat_cargo!("invalid filename"));
+ writeln!(result, "{}", eformat_cargo!("invalid filename")).ok();
ec.exit_code = EC_IO_ERR_INVALID_FILENAME;
}
std::io::ErrorKind::ArgumentListTooLong => {
- r_println!("{}", eformat_cargo!("argument list too long"));
+ writeln!(result, "{}", eformat_cargo!("argument list too long")).ok();
ec.exit_code = EC_IO_ERR_ARGUMENT_LIST_TOO_LONG;
}
std::io::ErrorKind::Interrupted => {
- r_println!("{}", eformat_cargo!("interrupted"));
+ writeln!(result, "{}", eformat_cargo!("interrupted")).ok();
ec.exit_code = EC_IO_ERR_INTERRUPTED;
}
std::io::ErrorKind::Unsupported => {
- r_println!("{}", eformat_cargo!("unsupported"));
+ writeln!(result, "{}", eformat_cargo!("unsupported")).ok();
ec.exit_code = EC_IO_ERR_UNSUPPORTED;
}
std::io::ErrorKind::UnexpectedEof => {
- r_println!("{}", eformat_cargo!("unexpected end of file"));
+ writeln!(result, "{}", eformat_cargo!("unexpected end of file")).ok();
ec.exit_code = EC_IO_ERR_UNEXPECTED_EOF;
}
std::io::ErrorKind::OutOfMemory => {
- r_println!("{}", eformat_cargo!("out of memory"));
+ writeln!(result, "{}", eformat_cargo!("out of memory")).ok();
ec.exit_code = EC_IO_ERR_OUT_OF_MEMORY;
}
std::io::ErrorKind::Other => {
- r_println!("{}", eformat_cargo!(err.to_string()));
+ writeln!(result, "{}", eformat_cargo!(err.to_string())).ok();
ec.exit_code = EC_IO_ERR_OTHER;
}
_ => {
- r_println!("{}", eformat_cargo!(err.to_string()));
+ writeln!(result, "{}", eformat_cargo!(err.to_string())).ok();
ec.exit_code = EC_IO_ERR_OTHER;
}
}
+ result
}
diff --git a/mling/src/lib.rs b/mling/src/lib.rs
index 1bf38a7..1de1228 100644
--- a/mling/src/lib.rs
+++ b/mling/src/lib.rs
@@ -1,7 +1,7 @@
#![allow(unused_imports)]
use mingling::{
- macros::{chain, gen_program, pack, r_println, renderer},
+ macros::{chain, gen_program, pack, renderer},
res::ResExitCode,
};
diff --git a/mling/src/pkg_mgr/installer.rs b/mling/src/pkg_mgr/installer.rs
index e69de29..8b13789 100644
--- a/mling/src/pkg_mgr/installer.rs
+++ b/mling/src/pkg_mgr/installer.rs
@@ -0,0 +1 @@
+
diff --git a/mling/src/proj_mgr/checklist_reader.rs b/mling/src/proj_mgr/checklist_reader.rs
index 6d115bb..558d303 100644
--- a/mling/src/proj_mgr/checklist_reader.rs
+++ b/mling/src/proj_mgr/checklist_reader.rs
@@ -1,4 +1,4 @@
-use std::{collections::HashMap, path::Path, io};
+use std::{collections::HashMap, io, path::Path};
/// Reads and parses a `CHECKLIST.md` file, extracting both *values* (from
/// fenced code blocks) and *toggles* (from checkbox lines).
@@ -56,27 +56,28 @@ impl CheckListReader {
let line = lines[i];
if let Some(key) = line.strip_prefix("```").map(|s| s.trim())
- && !key.is_empty() && !key.starts_with(' ') {
- let mut block_lines = Vec::new();
+ && !key.is_empty()
+ && !key.starts_with(' ')
+ {
+ let mut block_lines = Vec::new();
+ i += 1;
+ while i < lines.len() && !lines[i].trim_start().starts_with("```") {
+ block_lines.push(lines[i]);
i += 1;
- while i < lines.len() && !lines[i].trim_start().starts_with("```") {
- block_lines.push(lines[i]);
- i += 1;
- }
- let value = block_lines
- .into_iter()
- .find(|l| !l.trim().is_empty())
- .map(|l| l.trim().to_string());
- if let Some(val) = value {
- self.values.insert(key.to_string(), val);
- }
- continue;
}
+ let value = block_lines
+ .into_iter()
+ .find(|l| !l.trim().is_empty())
+ .map(|l| l.trim().to_string());
+ if let Some(val) = value {
+ self.values.insert(key.to_string(), val);
+ }
+ continue;
+ }
if let Some(toggle_key) = Self::parse_toggle_line(line) {
let is_checked = line.contains("[x]") || line.contains("[X]");
- self.all_toggles
- .insert(toggle_key.clone(), is_checked);
+ self.all_toggles.insert(toggle_key.clone(), is_checked);
if is_checked {
self.toggles.insert(toggle_key, true);
}
diff --git a/mling/src/proj_mgr/generator.rs b/mling/src/proj_mgr/generator.rs
index 48a1753..4f965d9 100644
--- a/mling/src/proj_mgr/generator.rs
+++ b/mling/src/proj_mgr/generator.rs
@@ -1,9 +1,10 @@
use std::path::{self, PathBuf};
use mingling::{
- Groupped,
- macros::{chain, pack, r_println, renderer, route},
+ Groupped, RenderResult,
+ macros::{chain, pack, renderer, route},
};
+use std::io::Write as _;
use crate::{Next, proj_mgr::EntryGenerateProject, res::ResCurrentDir};
@@ -35,12 +36,22 @@ pub fn handle_state_gen_proj_ready(prev: StateGenerateProjectReady) -> Next {
}
#[renderer]
-pub fn render_gen_proj_checklist_created(result: ResultGenerateProjectChecklistCreated) {
- r_println!(
+pub fn render_gen_proj_checklist_created(
+ result: ResultGenerateProjectChecklistCreated,
+) -> RenderResult {
+ let mut res = RenderResult::default();
+ writeln!(
+ res,
"Successfully create {} at \"{}\"",
CHECK_LIST_NAME,
result.to_string_lossy()
- );
- r_println!("");
- r_println!("Please fill in {CHECK_LIST_NAME} and run `mling gen` again to continue generating");
+ )
+ .ok();
+ writeln!(res).ok();
+ writeln!(
+ res,
+ "Please fill in {CHECK_LIST_NAME} and run `mling gen` again to continue generating"
+ )
+ .ok();
+ res
}
diff --git a/mling/src/proj_mgr/show_binaries.rs b/mling/src/proj_mgr/show_binaries.rs
index d6872cf..9d5caf0 100644
--- a/mling/src/proj_mgr/show_binaries.rs
+++ b/mling/src/proj_mgr/show_binaries.rs
@@ -2,10 +2,11 @@ use std::path::PathBuf;
use colored::Colorize;
use mingling::{
- Groupped,
- macros::{chain, pack, r_print, r_println, renderer},
+ Groupped, RenderResult,
+ macros::{chain, pack, renderer},
};
use serde::Serialize;
+use std::io::Write as _;
use crate::{
Next,
@@ -58,16 +59,20 @@ pub fn handle_show_binaries(_args: EntryShowBinaries, manifest_path: &ResManifes
}
#[renderer]
-pub fn render_binaries(binaries: ResultBinaries) -> String {
- r_println!("{}", "Binaries:".bright_cyan().bold());
+pub fn render_binaries(binaries: ResultBinaries) -> RenderResult {
+ let mut result = RenderResult::default();
+ writeln!(result, "{}", "Binaries:".bright_cyan().bold()).ok();
if let Some(max_name_len) = binaries.binaries.iter().map(|b| b.name.len()).max() {
for binary in &binaries.binaries {
- r_println!(
+ writeln!(
+ result,
" {:width$} `{}`",
binary.name.bright_yellow().bold(),
binary.path.display().to_string().italic(),
width = max_name_len
- );
+ )
+ .ok();
}
}
+ result
}
diff --git a/mling/src/proj_mgr/show_directories.rs b/mling/src/proj_mgr/show_directories.rs
index e84bf69..7d7c074 100644
--- a/mling/src/proj_mgr/show_directories.rs
+++ b/mling/src/proj_mgr/show_directories.rs
@@ -1,9 +1,10 @@
use colored::Colorize;
use mingling::{
- Groupped,
- macros::{chain, pack, r_println, renderer},
+ Groupped, RenderResult,
+ macros::{chain, pack, renderer},
};
use serde::Serialize;
+use std::io::Write as _;
use crate::{
Next,
@@ -46,11 +47,15 @@ pub fn handle_show_target_directory(
}
#[renderer]
-pub fn render_workspace_directory(prev: ResultWorkspaceDirectory) {
- r_println!("{}", prev.path.bright_cyan().bold());
+pub fn render_workspace_directory(prev: ResultWorkspaceDirectory) -> RenderResult {
+ let mut result = RenderResult::default();
+ writeln!(result, "{}", prev.path.bright_cyan().bold()).ok();
+ result
}
#[renderer]
-pub fn render_target_directory(prev: ResultTargetDirectory) {
- r_println!("{}", prev.path.bright_cyan().bold());
+pub fn render_target_directory(prev: ResultTargetDirectory) -> RenderResult {
+ let mut result = RenderResult::default();
+ writeln!(result, "{}", prev.path.bright_cyan().bold()).ok();
+ result
}