1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
use Regex;
use HashSet;
use Height;
use Width;
use terminal_size;
use crateSize;
/// Parses command line arguments to detect which flags and parameters were passed.
///
/// # Arguments
///
/// * `arguments` - A vector of strings representing command line arguments.
/// * `short_flags` - A slice of characters representing short command line flags (e.g., 'f', 'v').
/// * `long_flags` - A slice of strings representing long command line flags (e.g., "help", "version").
/// * `params` - A slice of strings representing expected parameters (non-flag arguments).
///
/// # Returns
///
/// A tuple containing:
/// - `HashSet<String>`: A set of detected flags (both short and long).
/// - `Vec<String>`: A vector of detected parameters.
///
/// # Example
///
/// ```rust
/// use std::collections::HashSet;
/// use coretilus::tools::parse_args;
///
/// let args = vec![
/// "prog".to_string(),
/// "-f".to_string(),
/// "--help".to_string(),
/// "file.txt".to_string(),
/// ];
///
/// let (flags, params) = parse_args(
/// args.clone(),
/// &['f', 'v'],
/// &["help", "version"],
/// &["file.txt", "file2.txt"]
/// );
///
/// assert!(flags.contains("f"));
/// assert!(flags.contains("help"));
/// assert!(!flags.contains("v"));
/// assert!(!flags.contains("version"));
/// assert_eq!(params, vec!["file.txt"]);
///
/// let (flags, params) = parse_args(
/// args.clone(),
/// &['p', 'r'],
/// &["bad"],
/// &["file.txt", "file2.txt"]
/// );
///
/// assert!(!flags.contains("p"));
/// assert!(!flags.contains("r"));
/// assert!(!flags.contains("bad"));
/// assert_eq!(params, vec!["file.txt"]);
/// ```
/// Filters parameters from a list of arguments based on regular expression patterns.
///
/// # Arguments
///
/// * `arguments` - A vector of strings representing command line arguments.
/// * `patterns` - A slice of string slices representing regular expression patterns.
///
/// # Returns
///
/// A vector of strings containing arguments that match any of the provided regular expression patterns.
///
/// # Examples
///
/// ```rust
/// use regex::Regex;
/// use std::vec;
/// use coretilus::tools::filter_params_regex;
///
/// let args = vec![
/// "file.txt".to_string(),
/// "image.png".to_string(),
/// "data.csv".to_string(),
/// "notes.md".to_string(),
/// ];
///
/// let result = filter_params_regex(args.clone(), &["txt$"]);
/// assert_eq!(result, vec!["file.txt".to_string()]);
///
/// let result = filter_params_regex(args.clone(), &["png$", "md$"]);
/// assert_eq!(result, vec!["image.png".to_string(), "notes.md".to_string()]);
///
/// let result = filter_params_regex(args.clone(), &[".*"]);
/// assert_eq!(result, vec![
/// "file.txt".to_string(),
/// "image.png".to_string(),
/// "data.csv".to_string(),
/// "notes.md".to_string(),
/// ]);
/// ```
///
/// This function ignores invalid regular expressions and will not include arguments that do not match any valid pattern.