Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaRHristov committed Oct 5, 2024
1 parent beb2f65 commit d5db810
Show file tree
Hide file tree
Showing 17 changed files with 332 additions and 208 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ processing capabilities, along with flexible file filtering options.
Summary -P > Summary.diff
```

[Summary] will now generate the following [Summary.diff](./Summary.diff) for all the
commits and tags between the first and the last commit.
[Summary] will now generate the following [Summary.diff](./Summary.diff) for all
the commits and tags between the first and the last commit.

## Features

Expand Down
30 changes: 19 additions & 11 deletions Source/Fn/Binary/Command.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
/// Creates and returns the command-line argument matches for the `Summary` application.
/// Creates and returns the command-line argument matches for the `Summary`
/// application.
///
/// This function sets up the command-line interface using the `clap` crate, defining various
/// arguments and their properties such as short and long names, help messages, default values,
/// and whether they are required.
/// This function sets up the command-line interface using the `clap` crate,
/// defining various arguments and their properties such as short and long
/// names, help messages, default values, and whether they are required.
///
/// # Returns
///
/// Returns an `ArgMatches` instance containing the parsed command-line arguments.
/// Returns an `ArgMatches` instance containing the parsed command-line
/// arguments.
///
/// # Arguments
///
/// * `Exclude` - An optional argument to specify patterns to exclude. Default is "node_modules".
/// * `Omit` - An optional argument to specify patterns to omit. Default values are:
/// * `Exclude` - An optional argument to specify patterns to exclude. Default
/// is "node_modules".
/// * `Omit` - An optional argument to specify patterns to omit. Default values
/// are:
/// - "(?i)documentation"
/// - "(?i)target"
/// - "(?i)changelog\.md$"
/// - "(?i)summary\.md$"
/// * `Parallel` - An optional flag to enable parallel processing.
/// * `Pattern` - An optional argument to specify a pattern to match. Default is ".git".
/// * `Root` - An optional argument to specify the root directory. Default is ".".
/// * `Pattern` - An optional argument to specify a pattern to match. Default is
/// ".git".
/// * `Root` - An optional argument to specify the root directory. Default is
/// ".".
///
/// # Example
///
/// ```rust
/// let matches = Fn();
/// let exclude = matches.value_of("Exclude").unwrap_or("node_modules");
/// let omit = matches.values_of("Omit").unwrap_or_default().collect::<Vec<_>>();
/// let omit =
/// matches.values_of("Omit").unwrap_or_default().collect::<Vec<_>>();
/// let parallel = matches.is_present("Parallel");
/// let pattern = matches.value_of("Pattern").unwrap_or(".git");
/// let root = matches.value_of("Root").unwrap_or(".");
/// ```
///
/// # Errors
///
/// This function will panic if there are issues with the argument definitions or parsing.
/// This function will panic if there are issues with the argument definitions
/// or parsing.
pub fn Fn() -> ArgMatches {
Command::new("Summary")
.version(env!("CARGO_PKG_VERSION"))
Expand Down
45 changes: 28 additions & 17 deletions Source/Fn/Binary/Command/Entry.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,47 @@
/// Generates a list of file paths from the specified root directory, excluding paths that match
/// any of the specified exclude patterns.
/// Generates a list of file paths from the specified root directory, excluding
/// paths that match any of the specified exclude patterns.
///
/// # Arguments
///
/// * `Option` - A reference to an `Option` struct containing the following fields:
/// * `Option` - A reference to an `Option` struct containing the following
/// fields:
/// - `Exclude`: A vector of strings representing patterns to exclude.
/// - `Pattern`: A string pattern to match against the last element of each entry.
/// - `Pattern`: A string pattern to match against the last element of each
/// entry.
/// - `Root`: The root directory to start the walk from.
/// - `Separator`: The separator used for splitting file paths.
///
/// # Returns
///
/// Returns a vector of vectors, where each inner vector contains the components of a file path
/// split by the specified separator.
/// Returns a vector of vectors, where each inner vector contains the components
/// of a file path split by the specified separator.
///
/// # Panics
///
/// This function will panic if it encounters an error while reading a directory entry.
/// This function will panic if it encounters an error while reading a directory
/// entry.
///
/// # Example
///
/// ```
/// let options = Option {
/// Exclude: vec!["node_modules".to_string(), "target".to_string()],
/// Pattern: ".git".to_string(),
/// Root: ".".to_string(),
/// Separator: '/',
/// Exclude:vec!["node_modules".to_string(), "target".to_string()],
/// Pattern:".git".to_string(),
/// Root:".".to_string(),
/// Separator:'/',
/// };
/// let paths = Fn(&options);
/// for path in paths {
/// println!("{:?}", path);
/// println!("{:?}", path);
/// }
/// ```
pub fn Fn(Option { Exclude, Pattern, Root, Separator, .. }: &Option) -> Return {
pub fn Fn(Option { Exclude, Pattern, Root, Separator, .. }:&Option) -> Return {
WalkDir::new(Root)
.follow_links(false)
.into_iter()
.filter_map(|Entry| {
let Path = Entry.expect("Cannot Entry.").path().display().to_string();
let Path =
Entry.expect("Cannot Entry.").path().display().to_string();

// TODO: Separate this into Entry/Exclude.rs
if !Exclude
Expand All @@ -46,14 +50,21 @@ pub fn Fn(Option { Exclude, Pattern, Root, Separator, .. }: &Option) -> Return {
.filter(|Exclude| *Pattern != *Exclude)
.any(|Exclude| Path.contains(&Exclude))
{
Some(Path.split(*Separator).map(|Entry| Entry.to_string()).collect())
Some(
Path.split(*Separator)
.map(|Entry| Entry.to_string())
.collect(),
)
} else {
None
}
})
.collect::<Vec<_>>()
}

use crate::Struct::Binary::Command::{Entry::Type as Return, Option::Struct as Option};

use walkdir::WalkDir;

use crate::Struct::Binary::Command::{
Entry::Type as Return,
Option::Struct as Option,
};
35 changes: 23 additions & 12 deletions Source/Fn/Binary/Command/Parallel.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
/// Asynchronously processes entries to generate summaries and outputs the results.
/// Asynchronously processes entries to generate summaries and outputs the
/// results.
///
/// This function performs the following steps:
/// 1. Filters and processes the provided entries based on the given pattern and separator.
/// 1. Filters and processes the provided entries based on the given pattern and
/// separator.
/// 2. Spawns asynchronous tasks to generate summaries for each entry.
/// 3. Collects the results and outputs them.
///
/// # Arguments
///
/// * `Option` - A struct containing the following fields:
/// - `Entry`: A vector of vectors, where each inner vector contains the components of a file path.
/// - `Entry`: A vector of vectors, where each inner vector contains the
/// components of a file path.
/// - `Separator`: A character used to join the components of the file path.
/// - `Pattern`: A string pattern to match against the last element of each entry.
/// - `Pattern`: A string pattern to match against the last element of each
/// entry.
/// - `Omit`: A vector of strings representing patterns to omit.
///
/// # Example
///
/// ```rust
/// let options = Option {
/// Entry: vec![vec!["path".to_string(), "to".to_string(), "file.git".to_string()]],
/// Separator: '/',
/// Pattern: ".git".to_string(),
/// Omit: vec!["target".to_string()],
/// Entry:vec![vec![
/// "path".to_string(),
/// "to".to_string(),
/// "file.git".to_string(),
/// ]],
/// Separator:'/',
/// Pattern:".git".to_string(),
/// Omit:vec!["target".to_string()],
/// };
/// Fn(options).await;
/// ```
///
/// # Errors
///
/// This function will log errors if it fails to generate summaries or send results.
pub async fn Fn(Option { Entry, Separator, Pattern, Omit, .. }: Option) {
/// This function will log errors if it fails to generate summaries or send
/// results.
pub async fn Fn(Option { Entry, Separator, Pattern, Omit, .. }:Option) {
let (Allow, mut Mark) = tokio::sync::mpsc::unbounded_channel();
let Queue = futures::stream::FuturesUnordered::new();

Expand Down Expand Up @@ -57,9 +66,11 @@ pub async fn Fn(Option { Entry, Separator, Pattern, Omit, .. }: Option) {
if let Err(_Error) = Allow.send((Entry, Summary)) {
eprintln!("Cannot Allow: {}", _Error);
}
}
},

Err(_Error) => eprintln!("Cannot Summary for {}: {}", Entry, _Error),
Err(_Error) => {
eprintln!("Cannot Summary for {}: {}", Entry, _Error)
},
}
}));
}
Expand Down
47 changes: 30 additions & 17 deletions Source/Fn/Binary/Command/Sequential.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,50 @@
/// Asynchronously processes entries to generate summaries and outputs the results sequentially.
/// Asynchronously processes entries to generate summaries and outputs the
/// results sequentially.
///
/// This function performs the following steps:
/// 1. Filters and processes the provided entries based on the given pattern and separator.
/// 1. Filters and processes the provided entries based on the given pattern and
/// separator.
/// 2. Spawns asynchronous tasks to generate summaries for each entry.
/// 3. Collects the results and outputs them.
///
/// # Arguments
///
/// * `Option` - A struct containing the following fields:
/// - `Entry`: A vector of vectors, where each inner vector contains the components of a file path.
/// - `Entry`: A vector of vectors, where each inner vector contains the
/// components of a file path.
/// - `Separator`: A character used to join the components of the file path.
/// - `Pattern`: A string pattern to match against the last element of each entry.
/// - `Pattern`: A string pattern to match against the last element of each
/// entry.
/// - `Omit`: A vector of strings representing patterns to omit.
///
/// # Example
///
/// ```rust
/// let options = Option {
/// Entry: vec![vec!["path".to_string(), "to".to_string(), "file.git".to_string()]],
/// Separator: '/',
/// Pattern: ".git".to_string(),
/// Omit: vec!["target".to_string()],
/// Entry:vec![vec![
/// "path".to_string(),
/// "to".to_string(),
/// "file.git".to_string(),
/// ]],
/// Separator:'/',
/// Pattern:".git".to_string(),
/// Omit:vec!["target".to_string()],
/// };
/// Fn(options).await;
/// ```
///
/// # Errors
///
/// This function will log errors if it fails to generate summaries or send results.
pub async fn Fn(Option { Entry, Pattern, Separator, Omit, .. }: Option) {
/// This function will log errors if it fails to generate summaries or send
/// results.
pub async fn Fn(Option { Entry, Pattern, Separator, Omit, .. }:Option) {
let Queue = futures::future::join_all(
Entry
.into_iter()
.filter_map(|Entry| {
Entry
.last()
.filter(|Last| *Last == &Pattern)
.map(|_| Entry[0..Entry.len() - 1].join(&Separator.to_string()))
Entry.last().filter(|Last| *Last == &Pattern).map(|_| {
Entry[0..Entry.len() - 1].join(&Separator.to_string())
})
})
.map(|Entry| {
let Omit = Omit.clone();
Expand All @@ -50,15 +58,20 @@ pub async fn Fn(Option { Entry, Pattern, Separator, Omit, .. }: Option) {
{
Ok(Summary) => Ok((Entry, Summary)),
Err(_Error) => {
Err(format!("Error generating summary for {}: {}", Entry, _Error))
}
Err(format!(
"Error generating summary for {}: {}",
Entry, _Error
))
},
}
}
}),
)
.await;

crate::Fn::Summary::Group::Fn(Queue.into_iter().filter_map(Result::ok).collect::<Vec<_>>());
crate::Fn::Summary::Group::Fn(
Queue.into_iter().filter_map(Result::ok).collect::<Vec<_>>(),
);
}

use crate::Struct::Binary::Command::Entry::Struct as Option;
Loading

0 comments on commit d5db810

Please sign in to comment.