rumtk_core/cli.rs
1/*
2 * rumtk attempts to implement HL7 and medical protocols for interoperability in medicine.
3 * This toolkit aims to be reliable, simple, performant, and standards compliant.
4 * Copyright (C) 2025 Luis M. Santos, M.D. <lsantos@medicalmasses.com>
5 * Copyright (C) 2025 MedicalMasses L.L.C. <contact@medicalmasses.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21///
22/// Tools for handling reading and writing from the standard I/O/E.
23///
24/// Per this [stackoverflow discussion](https://unix.stackexchange.com/questions/37508/in-what-order-do-piped-commands-run).
25/// Note:
26///```text
27/// Piped commands run concurrently. When you run ps | grep …, it's the luck of the draw (or a matter of details of the workings of the shell combined with scheduler fine-tuning deep in the bowels of the kernel) as to whether ps or grep starts first, and in any case they continue to execute concurrently.
28///
29/// This is very commonly used to allow the second program to process data as it comes out from the first program, before the first program has completed its operation. For example
30///
31/// grep pattern very-large-file | tr a-z A-Z
32/// begins to display the matching lines in uppercase even before grep has finished traversing the large file.
33///
34/// grep pattern very-large-file | head -n 1
35/// displays the first matching line, and may stop processing well before grep has finished reading its input file.
36///
37/// If you read somewhere that piped programs run in sequence, flee this document. Piped programs run concurrently and always have.
38/// ```
39///
40/// I bring the note above because that was my original understanding, but I have had to spend a
41/// crazy amount of time trying to get data flowing from one process to another without the initial
42/// process first exiting.
43///
44pub mod cli_utils {
45 use crate::base::{RUMResult, RUMVec};
46 use crate::cpu::CPU_PAGE_SIZE;
47 use crate::strings::{rumtk_format, RUMString};
48 use crate::types::RUMCLIParser;
49 use rumtk_arena::AsRUMSlice;
50 use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write};
51 #[cfg(any(target_family = "unix", target_os = "linux", target_os = "macos"))]
52 use std::os::fd::{AsRawFd, FromRawFd};
53
54 pub type BufferSlice = RUMVec<u8>;
55 pub type CliSTDInput = RUMVec<u8>;
56 pub type CliSTDOutput<R: AsRUMSlice> = R;
57 pub type BufferChunk = [u8; STD_IN_STEP_SIZE];
58 pub type CliDirectExecutor<Args: RUMCLIParser> = Box<dyn Fn(Args) -> RUMResult<()>>;
59 pub type CliMessageExecutor<Args: RUMCLIParser, R: AsRUMSlice> = Box<dyn Fn(CliSTDInput, &Args) -> RUMResult<CliSTDOutput<R>>>;
60
61 const STD_IN_STEP_SIZE: usize = u16::MAX as usize * 4;
62
63 pub enum CliProcessor<Args>
64 where
65 Args: RUMCLIParser
66 {
67 Direct(CliDirectExecutor<Args>),
68 Message(CliMessageExecutor<Args, RUMString>),
69
70 }
71
72 ///
73 /// Consumes the incoming buffer in chunks of [CPU_PAGE_SIZE](CPU_PAGE_SIZE) bytes size
74 /// until no more bytes are present.
75 ///
76 /// To avoid calling a blocking read, we check if the read yielded an amount of bytes fewer than
77 /// the requested chunk size.
78 ///
79 /// ## Example
80 ///
81 /// ```
82 /// use rumtk_core::cli::cli_utils::{read_stdin};
83 /// use rumtk_core::cpu::CPU_PAGE_SIZE;
84 ///
85 /// let stdin_data = read_stdin(CPU_PAGE_SIZE).unwrap();
86 ///
87 /// assert_eq!(stdin_data.len(), 0, "Returned data with {} size even though we expected 0 bytes!", stdin_data.len())
88 /// ```
89 ///
90 pub fn read_stdin(minimum_size: usize) -> RUMResult<CliSTDInput> {
91 let mut stdin_buffer = CliSTDInput::with_capacity(minimum_size);
92
93 loop {
94 let s = read_some_stdin(&mut stdin_buffer)?;
95
96 // If we attempt the next read, it is likely to be a 0 byte read. Why does this matter?
97 // Well, if the other end of the pipe is still open, the read call will stall in Rust's
98 // std and it is because it expects EOF but that never comes.
99 // If you look at https://man7.org/linux/man-pages/man2/read.2.html, read should return
100 // 0 and simply let us naturally break, but a read < than requested buffer appears to be
101 // an equally valid way to handle terminal and piped data.
102 // We have to check against 0 because the more optimal the buffer size we ask for (e.g.
103 // larger reads for minimum syscall time) the less likely the kernel is ready with the
104 // requested data.
105
106 // Example reads at u16::Max
107 // Read 65535 bytes
108 // Read 61441 bytes
109 // Read 65535 bytes
110 // Read 61441 bytes
111 // Read 8192 bytes
112 // Read 65535 bytes
113 // Read 61441 bytes
114 // Read 65535 bytes
115 // Read 61441 bytes
116 // Read 8192 bytes
117 // Read 65535 bytes
118 // Read 61441 bytes
119 // Read 65535 bytes
120 // Read 61441 bytes
121 // Read 8192 bytes
122 // Read 65535 bytes
123 // Read 61441 bytes
124 // Read 65535 bytes
125 // Read 61441 bytes
126 // Read 8192 bytes
127 // Read 65535 bytes
128 // Read 61441 bytes
129 // Read 65535 bytes
130 // Read 61441 bytes
131 // Read 8192 bytes
132 // Read 65535 bytes
133 // Read 61441 bytes
134 // Read 65535 bytes
135 // Read 61441 bytes
136 // Read 8192 bytes
137 // Read 65535 bytes
138 // Read 61441 bytes
139 // Read 65535 bytes
140 // Read 61441 bytes
141 // Read 8192 bytes
142 // Read 65535 bytes
143 // Read 61441 bytes
144 // Read 65535 bytes
145 // Read 61441 bytes
146 // Read 8192 bytes
147 // Read 65535 bytes
148 // Read 61441 bytes
149 // Read 65535 bytes
150 // Read 41974 bytes
151 // Read 0 bytes
152 // Total: 2331637 => 2.2MB
153 if s == 0 {
154 break;
155 }
156 }
157
158 Ok(stdin_buffer)
159 }
160
161 ///
162 /// Consumes the incoming buffer in chunks of [CPU_SIMD_64_SIZE](crate::cpu::CPU_SIMD_64_SIZE) bytes size.
163 ///
164 /// ## Example
165 ///
166 /// ```
167 /// use std::io::stdin;
168 /// use std::io::prelude::*;
169 /// use std::process::{Command, Stdio};
170 /// use rumtk_core::cli::cli_utils::{read_some_stdin};
171 /// use rumtk_core::cpu::CPU_PAGE_SIZE;
172 /// use rumtk_core::base::RUMVec;
173 ///
174 /// let mut stdin_buffer = RUMVec::with_capacity(CPU_PAGE_SIZE);
175 /// let mut s = read_some_stdin(&mut stdin_buffer).unwrap();
176 /// let mut totas_s = s;
177 /// while s > 0 {
178 /// s = read_some_stdin(&mut stdin_buffer).unwrap();
179 /// totas_s += s;
180 /// }
181 ///
182 /// assert_eq!(totas_s, 0, "Returned data with {} size even though we expected 0 bytes!", totas_s)
183 /// ```
184 ///
185 #[inline]
186 #[cfg(target_os = "windows")]
187 pub fn read_some_stdin(buf: &mut BufferSlice) -> RUMResult<usize> {
188 let mut chunk: BufferChunk = [0; STD_IN_STEP_SIZE];
189
190 match stdin().lock().read(&mut chunk[..]) {
191 Ok(s) => {
192 buf.extend_from_slice(&chunk[..s]);
193 Ok(s)
194 }
195 Err(e) => Err(rumtk_format!("Error reading stdin chunk because {}!", e)),
196 }
197 }
198
199 ///
200 /// Consumes the incoming buffer in chunks of [CPU_SIMD_64_SIZE](crate::cpu::CPU_SIMD_64_SIZE) bytes size.
201 ///
202 /// ## Example
203 ///
204 /// ```
205 /// use std::io::stdin;
206 /// use std::io::prelude::*;
207 /// use std::process::{Command, Stdio};
208 /// use rumtk_core::cli::cli_utils::{read_some_stdin};
209 /// use rumtk_core::cpu::CPU_PAGE_SIZE;
210 /// use rumtk_core::base::RUMVec;
211 ///
212 /// let mut stdin_buffer = RUMVec::with_capacity(CPU_PAGE_SIZE);
213 /// let mut s = read_some_stdin(&mut stdin_buffer).unwrap();
214 /// let mut totas_s = s;
215 /// while s > 0 {
216 /// s = read_some_stdin(&mut stdin_buffer).unwrap();
217 /// totas_s += s;
218 /// }
219 ///
220 /// assert_eq!(totas_s, 0, "Returned data with {} size even though we expected 0 bytes!", totas_s)
221 /// ```
222 ///
223 #[cfg(any(target_family = "unix", target_os = "linux", target_os = "macos"))]
224 pub fn read_some_stdin(buf: &mut BufferSlice) -> RUMResult<usize> {
225 // Create an unbuffered File handle from file descriptor 1 (stdout)
226 let locked = stdin().lock();
227 let stdin_fd = locked.as_raw_fd();
228 let mut chunk: BufferChunk = [0; STD_IN_STEP_SIZE];
229
230 let mut file = BufReader::new(unsafe { std::fs::File::from_raw_fd(stdin_fd) });
231
232 //Read directly from std input
233 let count = match file.read(&mut chunk[..]) {
234 Ok(s) => {
235 buf.extend_from_slice(&chunk[..s]);
236 std::mem::forget(file);
237 s
238 },
239 Err(e) => return Err(rumtk_format!("Error writing to stdout because {}", e)),
240 };
241
242 Ok(count)
243 }
244
245 ///
246 /// Writes [RUMBuffer] to `stdout`.
247 ///
248 #[cfg(target_os = "windows")]
249 pub fn write_stdout<R: AsSlice>(data: CliSTDOutput<R>) -> RUMResult<()> {
250 match stdout().lock().write_all(data.as_rum_slice()) {
251 Ok(_) => {}
252 Err(e) => return Err(rumtk_format!("Error writing to stdout because => {}", e)),
253 };
254 flush_stdout()?;
255 Ok(())
256 }
257
258 #[cfg(any(target_family = "unix", target_os = "linux", target_os = "macos"))]
259 pub fn write_stdout<R: AsRUMSlice>(data: CliSTDOutput<R>) -> RUMResult<()> {
260 // Create an unbuffered File handle from file descriptor 1 (stdout)
261 let locked = stdout().lock();
262 let stdout_fd = locked.as_raw_fd();
263
264 let mut file = BufWriter::new(unsafe { std::fs::File::from_raw_fd(stdout_fd) });
265
266 // Write bytes directly
267 match file.write_all(data.as_rum_slice()) {
268 Ok(_) => {
269 file.flush().unwrap_or_default();
270 std::mem::forget(file);
271 },
272 Err(e) => return Err(rumtk_format!("Error writing to stdout because {}", e)),
273 };
274
275 flush_stdout()?;
276 Ok(())
277 }
278
279 fn flush_stdout() -> RUMResult<()> {
280 match stdout().flush() {
281 Ok(_) => Ok(()),
282 Err(e) => Err(rumtk_format!("Error flushing stdout because => {}", e)),
283 }
284 }
285
286 pub fn process_message<Args, PF, R>(args: &Args, processor: PF) -> RUMResult<()>
287 where
288 Args: RUMCLIParser,
289 R: AsRUMSlice,
290 PF: Fn(CliSTDInput, &Args) -> RUMResult<R>
291 {
292 let stdin_msg = read_stdin(CPU_PAGE_SIZE * CPU_PAGE_SIZE)?;
293 if !stdin_msg.is_empty() {
294 let out_data = processor(stdin_msg, args)?;
295
296 write_stdout(out_data)?;
297 }
298 Ok(())
299 }
300
301 ///
302 /// Runs a closure (or any `Fn`) that owns the whole lifecycle of the program. Unlike
303 /// [CliProcessor::Direct], the closure is not boxed, so it can borrow from its environment.
304 ///
305 pub fn run_direct<Args, F>(args: &Args, logic: F) -> RUMResult<()>
306 where
307 Args: RUMCLIParser,
308 F: Fn(&Args) -> RUMResult<()>
309 {
310 logic(args)
311 }
312
313 pub fn process_message_loop<Args, PF, R>(args: Args, processor: &PF)
314 where
315 Args: RUMCLIParser,
316 R: AsRUMSlice,
317 PF: Fn(CliSTDInput, &Args) -> RUMResult<R>
318 {
319 loop {
320 match process_message(&args, processor) {
321 Ok(()) => continue,
322 Err(e) => println!("{}", e), // TODO: missing log call
323 };
324 }
325 }
326
327 pub fn print_license_notice(program: &str, year: &str, author_list: &Vec<&str>) {
328 let authors = author_list.join(", ");
329 let notice = rumtk_format!(
330 r" {program} Copyright (C) {year} {authors}
331 This program comes with ABSOLUTELY NO WARRANTY.
332 This is free software, and you are welcome to redistribute it
333 under certain conditions."
334 );
335 eprintln!("{}", notice);
336 }
337}
338
339pub mod macros {
340 ///
341 ///
342 ///
343 #[macro_export]
344 macro_rules! rumtk_cli_define_args {
345 (
346 $(
347 $(#[$field_meta:meta])*
348 $field_name:ident : $field_typ:ty
349 ),* $(,)?
350 ) => {
351 #[derive($crate::types::RUMCLIParser, Default, Debug)]
352 #[command(author, version, about, long_about = None)]
353 pub struct RUMTKInterfaceArgs {
354 $(
355 $(#[$field_meta])*
356 pub $field_name: $field_typ,
357 )*
358 ///
359 /// Specifies command line script to execute on message.
360 ///
361 #[arg(short, long, default_value_t = 1)]
362 pub threads: usize,
363 ///
364 /// Don't write to stdout. Mostly used to distinguish between performance issues with parser
365 /// vs. serde's JSON serialization.
366 ///
367 #[arg(short, long)]
368 pub quiet: bool,
369 ///
370 /// Only used if in client/outbound mode. Places the interface into a loop constantly looking
371 /// for messages in stdin to ship to the connected listening interface.
372 ///
373 #[arg(short, long)]
374 pub daemon: bool,
375 }
376 };
377 }
378
379 ///
380 /// Reads STDIN and unescapes the incoming message.
381 /// Return this unescaped message.
382 ///
383 /// # Example
384 ///
385 /// ## Without specifying the minimum read size.
386 /// ```
387 /// use rumtk_core::base::{RUMResult, RUMVec};
388 /// use rumtk_core::buffers::*;
389 /// use rumtk_core::rumtk_read_stdin;
390 ///
391 /// fn test_read_stdin() -> RUMResult<RUMVec<u8>> {
392 /// rumtk_read_stdin!()
393 /// }
394 ///
395 /// match test_read_stdin() {
396 /// Ok(s) => (),
397 /// Err(e) => panic!("Error reading stdin because => {}", e)
398 /// }
399 /// ```
400 ///
401 /// ## With specifying the minimum read size.
402 /// ```
403 /// use rumtk_core::base::{RUMResult, RUMVec};
404 /// use rumtk_core::buffers::*;
405 /// use rumtk_core::rumtk_read_stdin;
406 ///
407 /// fn test_read_stdin() -> RUMResult<RUMVec<u8>> {
408 /// rumtk_read_stdin!(1024)
409 /// }
410 ///
411 /// match test_read_stdin() {
412 /// Ok(s) => (),
413 /// Err(e) => panic!("Error reading stdin because => {}", e)
414 /// }
415 /// ```
416 ///
417 #[macro_export]
418 macro_rules! rumtk_read_stdin {
419 ( ) => {{
420 use $crate::cpu::CPU_PAGE_SIZE;
421 use $crate::cli::cli_utils::{read_stdin};
422 read_stdin(CPU_PAGE_SIZE * CPU_PAGE_SIZE)
423 }};
424 ( $min_expected_size:expr ) => {{
425 use $crate::cli::cli_utils::{read_stdin};
426 read_stdin($min_expected_size)
427 }};
428 }
429
430 ///
431 /// Writes [RUMString](crate::strings::RUMString) or [RUMBuffer](crate::types::RUMBuffer) to `stdout`.
432 ///
433 /// If the `binary` parameter is passed, we push the `message` parameter directly to `stdout`. the
434 /// `message` parameter has to be of type [RUMBuffer](crate::types::RUMBuffer).
435 ///
436 /// ## Example
437 ///
438 /// ### Default / Pushing a String
439 /// ```
440 /// use rumtk_core::rumtk_write_stdout;
441 ///
442 /// rumtk_write_stdout!("I ❤ my wife!");
443 /// ```
444 ///
445 /// ## Pushing Binary Buffer
446 /// ```
447 /// use rumtk_core::rumtk_write_stdout;
448 /// use rumtk_core::buffers::{new_random_rumbuffer, DEFAULT_BUFFER_CHUNK_SIZE};
449 ///
450 /// let buffer = new_random_rumbuffer::<DEFAULT_BUFFER_CHUNK_SIZE>();
451 /// rumtk_write_stdout!(buffer);
452 /// ```
453 ///
454 #[macro_export]
455 macro_rules! rumtk_write_stdout {
456 ( $message:expr ) => {{
457 use $crate::cli::cli_utils::write_stdout;
458 write_stdout(&$message)
459 }};
460 }
461
462 ///
463 /// Prints the mandatory GPL License Notice to terminal!
464 ///
465 /// # Example
466 /// ## Default
467 /// ```
468 /// use rumtk_core::rumtk_print_license_notice;
469 ///
470 /// rumtk_print_license_notice!();
471 /// ```
472 /// ## Program Only
473 /// ```
474 /// use rumtk_core::rumtk_print_license_notice;
475 ///
476 /// rumtk_print_license_notice!("RUMTK");
477 /// ```
478 /// ## Program + Year
479 /// ```
480 /// use rumtk_core::rumtk_print_license_notice;
481 ///
482 /// rumtk_print_license_notice!("RUMTK", "2025");
483 /// ```
484 /// ## Program + Year + Authors
485 /// ```
486 /// use rumtk_core::rumtk_print_license_notice;
487 ///
488 /// rumtk_print_license_notice!("RUMTK", "2025", &vec!["Luis M. Santos, M.D."]);
489 /// ```
490 ///
491 #[macro_export]
492 macro_rules! rumtk_print_license_notice {
493 ( ) => {{
494 use $crate::cli::cli_utils::print_license_notice;
495
496 print_license_notice("RUMTK", "2025", &vec!["Luis M. Santos, M.D."]);
497 }};
498 ( $program:expr ) => {{
499 use $crate::cli::cli_utils::print_license_notice;
500 print_license_notice(&$program, "2025", &vec!["2025", "Luis M. Santos, M.D."]);
501 }};
502 ( $program:expr, $year:expr ) => {{
503 use $crate::cli::cli_utils::print_license_notice;
504 print_license_notice(&$program, &$year, &vec!["Luis M. Santos, M.D."]);
505 }};
506 ( $program:expr, $year:expr, $authors:expr ) => {{
507 use $crate::cli::cli_utils::print_license_notice;
508 print_license_notice(&$program, &$year, &$authors);
509 }};
510 }
511
512 ///
513 /// Defines the CLI arguments of the program, parses the command line, and wires the message
514 /// processing logic.
515 ///
516 /// The macro expects an optional list of CLI argument definitions (same syntax accepted by
517 /// [rumtk_cli_define_args](crate::rumtk_cli_define_args)) followed by either the two message
518 /// handlers:
519 ///
520 /// + `ok` => Called when the incoming message could be deserialized into the expected type.
521 /// + `err` => Called with the raw bytes when deserialization was not possible.
522 ///
523 /// or a single piece of logic receiving the parsed arguments. In the latter case, the logic
524 /// owns the whole interface lifecycle and is called once with a reference to the parsed
525 /// arguments.
526 ///
527 /// The generated argument struct is named `RUMTKInterfaceArgs` and is available to the
528 /// handlers. If the `--daemon` flag is passed, the `ok`/`err` handlers are called in a loop for
529 /// every message coming through `stdin`. Otherwise, a single message is processed.
530 ///
531 /// ## Example
532 ///
533 /// ### Example 1 - With Parsed and Unparsed Message Closures
534 ///
535 /// ```no_run
536 /// use rumtk_core::base::{RUMResult, RUMVec};
537 /// use rumtk_core::strings::RUMString;
538 /// use rumtk_core::types::RUMCLIParser;
539 /// use rumtk_core::rumtk_cli_process;
540 ///
541 /// fn main() {
542 /// rumtk_cli_process!(
543 /// ///
544 /// /// Pretty print the outgoing message.
545 /// ///
546 /// #[arg(short, long)]
547 /// pretty: bool,
548 /// ///
549 /// /// Run in debug mode?
550 /// ///
551 /// #[arg(short, long)]
552 /// debug: bool,
553 /// Message(|data: RUMVec<u8>, args: &RUMTKInterfaceArgs| -> RUMResult<RUMString> {
554 /// Ok(RUMString::default())
555 /// })
556 /// );
557 /// }
558 /// ```
559 ///
560 /// ### Example 2 - With Raw Logic
561 ///
562 /// ```no_run
563 /// use rumtk_core::base::{RUMResult, RUMVec};
564 /// use rumtk_core::strings::RUMString;
565 /// use rumtk_core::types::RUMCLIParser;
566 /// use rumtk_core::rumtk_cli_process;
567 ///
568 /// fn main() {
569 /// rumtk_cli_process!(
570 /// ///
571 /// /// Pretty print the outgoing message.
572 /// ///
573 /// #[arg(short, long)]
574 /// pretty: bool,
575 /// ///
576 /// /// Run in debug mode?
577 /// ///
578 /// #[arg(short, long)]
579 /// debug: bool,
580 /// Direct(|args: &RUMTKInterfaceArgs| -> RUMResult<()> {
581 /// Ok(())
582 /// })
583 /// );
584 /// }
585 /// ```
586 ///
587 /// ## Disclosures
588 ///
589 /// I let `Claude Opus 5` help complete this macro. I did not understand how to wire the
590 /// token tree muncher into the argument pattern to pass to [rumtk_cli_define_args](crate::rumtk_cli_define_args)
591 /// and the two additional arguments representing the closures to be executed if message parsing is successful or not.
592 ///
593 #[macro_export]
594 macro_rules! rumtk_cli_process {
595 (
596 @collect [$($cli_args:tt)*]
597 $(#[$field_meta:meta])+
598 $field_name:ident : $field_typ:ty,
599 $($rest:tt)*
600 ) => {
601 $crate::rumtk_cli_process!(
602 @collect [$($cli_args)* $(#[$field_meta])* $field_name : $field_typ,]
603 $($rest)*
604 )
605 };
606 (
607 @collect [$($cli_args:tt)*]
608 $field_name:ident : $field_typ:ty,
609 $($rest:tt)*
610 ) => {
611 $crate::rumtk_cli_process!(
612 @collect [$($cli_args)* $field_name : $field_typ,]
613 $($rest)*
614 )
615 };
616 (
617 @collect [$($cli_args:tt)*]
618 Direct($logic:expr) $(,)?
619 ) => {{
620 use $crate::cli::cli_utils::run_direct;
621 use $crate::types::RUMCLIParser;
622
623 $crate::rumtk_cli_define_args!($($cli_args)*);
624
625 let args = RUMTKInterfaceArgs::try_parse().unwrap_or_default();
626
627 match run_direct(&args, $logic) {
628 Ok(_) => {},
629 Err(e) => println!("Error: {}", e),
630 };
631 }};
632 (
633 @collect [$($cli_args:tt)*]
634 Message($logic:expr) $(,)?
635 ) => {{
636 use $crate::cli::cli_utils::{process_message_loop, process_message};
637 use $crate::types::RUMCLIParser;
638
639 $crate::rumtk_cli_define_args!($($cli_args)*);
640
641 let args = RUMTKInterfaceArgs::parse();
642 let processor = $logic;
643
644 let r = if args.daemon {
645 process_message_loop(args, &processor);
646 Ok(())
647 } else {
648 process_message(&args, &processor)
649 };
650
651 match r {
652 Ok(_) => {},
653 Err(e) => println!("Error: {}", e),
654 };
655 }};
656 (
657 $($tokens:tt)*
658 ) => {
659 $crate::rumtk_cli_process!(@collect [] $($tokens)*)
660 };
661 }
662}