Skip to main content

Library/Struct/Binary/Command/
Option.rs

1/// Represents the options for binary command execution.
2///
3/// This struct holds various fields related to the command options, including
4/// exclude patterns, omit patterns, parallel execution flag, pattern to match,
5
6/// root directory, and separator for file paths.
7pub struct Struct {
8	/// A vector of strings representing patterns to exclude.
9	pub Exclude:Vec<String>,
10
11	/// A flag indicating whether to execute commands in parallel.
12	pub Parallel:Parallel,
13
14	/// A string pattern to match against the last element of each entry.
15	pub Pattern:Pattern,
16
17	/// The root directory to start the walk from.
18	pub Root:String,
19
20	/// The separator used for file paths.
21	pub Separator:Separator,
22}
23
24impl Struct {
25	/// Creates a new instance of the Struct.
26	///
27	/// This function initializes the Struct with the provided options,
28	/// generating the exclude patterns, omit patterns, parallel flag, pattern,
29	/// root directory, and separator from the options.
30	///
31	/// # Argument
32	///
33	/// * `Option` - A reference to an Option struct containing initialization
34	///   parameters.
35	///
36	/// # Returns
37	///
38	/// Returns a new instance of Struct.
39	pub fn Fn(Option { Separator, .. }:Option) -> Self {
40		Self {
41			Exclude:Command()
42				.get_one::<String>("Exclude")
43				.expect("Cannot Exclude.")
44				.split(" ")
45				.map(|Exclude| Exclude.to_string())
46				.collect::<Vec<_>>(),
47
48			Parallel:Command().get_flag("Parallel"),
49
50			Pattern:Command().get_one::<String>("Pattern").expect("Cannot Pattern.").to_owned(),
51
52			Root:Command().get_one::<String>("Root").expect("Cannot Root.").to_owned(),
53
54			Separator,
55		}
56	}
57}
58
59use crate::{Fn::Binary::Command::Fn as Command, Struct::Binary::Command::Struct as Option};
60
61/// Type alias for a vector of strings representing command options.
62pub type Command = Vec<String>;
63
64/// Type alias for a boolean flag indicating parallel execution.
65pub type Parallel = bool;
66
67/// Type alias for a string pattern to match.
68pub type Pattern = String;
69
70/// Type alias for a character used as a separator for file paths.
71pub type Separator = char;