Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
Signed-off-by: Nikola Hristov <Nikola@PlayForm.Cloud>
  • Loading branch information
NikolaRHristov committed Jul 29, 2024
1 parent b06e117 commit f05e050
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 79 deletions.
51 changes: 44 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
# 🗣️ [Summary] —

`Summary` is a command-line tool that executes commands in multiple directories
simultaneously. It leverages parallel processing and concurrent `I/O` to
efficiently run tasks across directories.
`Summary` is a powerful command-line tool designed for efficient file processing
and summarization. It offers both sequential and parallel processing
capabilities, along with flexible file filtering options.

[Summary]: HTTPS://crates.io/crates/psummary

## Feature

- Directory traversal and file filtering
- Parallel and sequential processing modes
- Customizable file pattern matching
- Exclusion of specified files or directories
- Integration with Pieces OS for enhanced functionality

## Pieces OS Integration

The `Summary` CLI supports Pieces OS, essentially acting as a plugin that can
rewrite the whole system. This integration allows for:

- Enhanced code analysis and summarization.
- Improved context-aware processing.
- Seamless integration with other Pieces OS-compatible tools.
- Potential for AI-driven insights and optimizations.

By leveraging Pieces OS, `Summary` can tap into a broader ecosystem of
development tools and services, significantly expanding its capabilities beyond
basic file processing.

## Installation

```sh
Expand All @@ -14,6 +36,18 @@ cargo install psummary

## Usage

The `Summary` tool can be used with various options:

- `--Root` or `-R`: Set the current working directory
- `--Parallel` or `-P`: Run commands in parallel
- `--Exclude`: Exclude certain files or directories
- `--Pattern`: Specify a custom pattern for matching
- `--Separator`: Define a custom separator

For Pieces OS integration, refer to the Pieces OS documentation for specific
flags and configuration options.
[Pieces](HTTPS://GitHub.Com/PlayForm/Pieces.git)

```sh
Summary
```
Expand Down Expand Up @@ -60,10 +94,13 @@ Define a custom separator

`Summary` relies on several Rust crates to provide its functionality:

- `clap` - Parses command-line arguments
- `rayon` - Enables parallel processing
- `tokio` - Provides an asynchronous runtime
- `walkdir` - Facilitates efficient filesystem traversal
- `clap` - For parsing command-line arguments.
- `rayon` - For parallel processing.
- `tokio` - For asynchronous runtime.
- `walkdir` - For efficient filesystem traversal.

[Pieces OS](HTTPS://Pieces.App): For extended functionality and system
integration.

[Summary]: HTTPS://crates.io/crates/psummary

Expand Down
48 changes: 30 additions & 18 deletions Source/Fn/Binary/Command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ pub fn Fn() -> ArgMatches {
.version(env!("CARGO_PKG_VERSION"))
.author("🖋️ Source — 👐🏻 Open — <Source/Open@PlayForm.Cloud>")
.about("🗣️ Summary —")
.arg(
Arg::new("Exclude")
.short('E')
.long("Exclude")
.display_order(4)
.value_name("EXCLUDE")
.required(false)
.help("🚫 Exclude —")
.default_value("node_modules"),
)
.arg(
Arg::new("Omit")
.short('O')
.long("Omit")
.display_order(6)
.value_name("OMIT")
.required(false)
.help("🚫 Omit —")
.action(clap::ArgAction::Append)
.default_value("Documentation"),
)
.arg(
Arg::new("Parallel")
.short('P')
Expand All @@ -26,6 +47,15 @@ pub fn Fn() -> ArgMatches {
.required(false)
.help("⏩ Parallel —"),
)
.arg(
Arg::new("Pattern")
.long("Pattern")
.display_order(5)
.value_name("PATTERN")
.required(false)
.help("🔍 Pattern —")
.default_value(".git"),
)
.arg(
Arg::new("Root")
.short('R')
Expand All @@ -36,24 +66,6 @@ pub fn Fn() -> ArgMatches {
.help("📂 Root —")
.default_value("."),
)
.arg(
Arg::new("Exclude")
.short('E')
.long("Exclude")
.display_order(4)
.value_name("EXCLUDE")
.required(false)
.help("🚫 Exclude —")
.default_value("node_modules"),
)
.arg(
Arg::new("Pattern")
.display_order(5)
.value_name("PATTERN")
.required(false)
.help("🔍 Pattern —")
.default_value(".git"),
)
.get_matches()
}

Expand Down
25 changes: 13 additions & 12 deletions Source/Fn/Binary/Command/Parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
/// };
/// Fn(option).await;
/// ```
pub async fn Fn(Option { Entry, Separator, Pattern, .. }: Option) {
let Queue: Vec<_> = stream::iter(
pub async fn Fn(Option { Entry, Separator, Pattern, Omit, .. }: Option) {
stream::iter(
Entry
.into_par_iter()
.filter_map(|Entry| {
Expand All @@ -29,20 +29,21 @@ pub async fn Fn(Option { Entry, Separator, Pattern, .. }: Option) {
})
.collect::<Vec<String>>(),
)
.map(|Entry| async move {
match crate::Fn::Summary::Fn(&Entry).await {
Ok(summary) => Ok(summary),
Err(e) => Err(format!("Error generating summary for {}: {}", Entry, e)),
.map(|Entry| {
let Omit = Omit.clone();

async move {
match crate::Fn::Summary::Fn(&Entry, &crate::Fn::Summary::Difference::Option { Omit })
.await
{
Ok(Summary) => Ok(Summary),
Err(_Error) => Err(format!("Error generating summary for {}: {}", Entry, _Error)),
}
}
})
.buffer_unordered(num_cpus::get())
.collect()
.collect::<Vec<_>>()
.await;

Queue.par_iter().for_each(|Output| match Output {
Ok(Summary) => println!("Summary: {:?}", Summary),
Err(Error) => eprintln!("Error: {}", Error),
});
}

use crate::Struct::Binary::Command::Entry::Struct as Option;
Expand Down
48 changes: 21 additions & 27 deletions Source/Fn/Summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,34 @@
/// };
/// let summary = Fn(&option);
/// ```
pub async fn Fn(Entry: &str) -> Result<(), Box<dyn std::error::Error>> {
let Repository = Repository::open(Entry)?;

let Tag = Repository.tag_names(None)?;
let mut Start = None;

let Summary = "Summary";
fs::create_dir_all(Summary)?;

for i in 0..Tag.len() {
if let Some(Tag) = Tag.get(i) {
if let Some(Start) = Start {
let Difference = crate::Fn::Summary::Difference::Fn(&Repository, Start, Tag)?;

File::create(&format!("{}/Difference_{}_{}.txt", Summary, Start, Tag))?.write_all(
crate::Fn::Summary::Difference::Fn(&Repository, Start, Tag)?.as_bytes(),
)?;

File::create(&format!("{}/Release_{}_{}.txt", Summary, Start, Tag))?
.write_all(crate::Fn::Summary::Release::Fn(&Difference).as_bytes())?;
pub async fn Fn(
Entry: &str,
Option: &crate::Fn::Summary::Difference::Option,
) -> Result<(), Box<dyn std::error::Error>> {
match Repository::open(Entry) {
Ok(Repository) => {
let Tag = Repository.tag_names(None)?;

let Tags: Vec<_> = Tag.iter().filter_map(|Tag| Tag).collect();

for (Index, &Current) in Tags.iter().enumerate() {
for (_, &Next) in Tags.iter().enumerate().skip(Index + 1) {
let Difference =
crate::Fn::Summary::Difference::Fn(&Repository, Current, Next, Option)?;

println!("{}", Difference);
}
}

Start = Some(Tag);
}
Err(_Error) => {
println!("Failed to open repository: {}", _Error);
return Err(_Error.into());
}
}

Ok(())
}

use git2::Repository;
use std::{
fs::{self, File},
io::Write,
};

pub mod Difference;
pub mod Release;
42 changes: 32 additions & 10 deletions Source/Fn/Summary/Difference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,40 @@
/// };
/// let difference = Fn(&option);
/// ```
pub fn Fn(Repo: &git2::Repository, Start: &str, End: &str) -> Result<String, git2::Error> {
pub fn Fn(
Repository: &git2::Repository,
Start: &str,
End: &str,
Option: &Option,
) -> Result<String, git2::Error> {
let mut Difference = String::new();

Repo.diff_tree_to_tree(
Some(&Repo.revparse_single(Start)?.peel_to_commit()?.tree()?),
Some(&Repo.revparse_single(End)?.peel_to_commit()?.tree()?),
Some(&mut git2::DiffOptions::new()),
)?
.print(git2::DiffFormat::Patch, |_, _, line| {
Difference.push_str(std::str::from_utf8(line.content()).unwrap());
true
})?;
Repository
.diff_tree_to_tree(
Some(&Repository.revparse_single(Start)?.peel_to_commit()?.tree()?),
Some(&Repository.revparse_single(End)?.peel_to_commit()?.tree()?),
Some(
&mut git2::DiffOptions::new().pathspec(
std::ffi::CString::new(
Option
.Omit
.iter()
.map(|Omit| format!("!{}", Omit))
.collect::<Vec<String>>()
.join("\0"),
)
.expect("Cannot create CString"),
),
),
)?
.print(git2::DiffFormat::Patch, |_, _, line| {
Difference.push_str(std::str::from_utf8(line.content()).unwrap());
true
})?;

Ok(Difference)
}

pub struct Option {
pub Omit: Vec<String>,
}
8 changes: 7 additions & 1 deletion Source/Struct/Binary/Command/Entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,26 @@ pub struct Struct {

/// The path separator character.
pub Separator: Separator,

/// List of items to omit from processing.
pub Omit: Omit,
}

impl Struct {
pub fn Fn(Option: &Option) -> Self {
Self {
Entry: crate::Fn::Binary::Command::Entry::Fn(Option),
Omit: Option.Omit.clone(),
Parallel: Option.Parallel,
Pattern: Option.Pattern.clone(),
Separator: Option.Separator,
}
}
}

use crate::Struct::Binary::Command::Option::{Parallel, Pattern, Separator, Struct as Option};
use crate::Struct::Binary::Command::Option::{
Omit, Parallel, Pattern, Separator, Struct as Option,
};

/// Defines a type alias for a vector of vectors of strings.
pub type Type = Vec<Vec<String>>;
11 changes: 10 additions & 1 deletion Source/Struct/Binary/Command/Option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ pub struct Struct {
/// List of patterns to exclude from processing.
pub Exclude: Vec<String>,

/// List of items to omit from processing.
pub Omit: Vec<String>,

/// Flag indicating whether to use parallel processing.
pub Parallel: Parallel,

Expand All @@ -24,12 +27,17 @@ impl Struct {
.get_one::<String>("Exclude")
.expect("Cannot Exclude.")
.split(" ")
.map(|Command| Command.to_string())
.map(|Exclude| Exclude.to_string())
.collect::<Vec<_>>(),
Parallel: Fn().get_flag("Parallel"),
Pattern: Fn().get_one::<String>("Pattern").expect("Cannot Pattern.").to_owned(),
Root: Fn().get_one::<String>("Root").expect("Cannot Root.").to_owned(),
Separator,
Omit: Fn()
.get_many::<String>("Omit")
.expect("Cannot Omit.")
.map(|Omit| Omit.to_string())
.collect(),
}
}
}
Expand All @@ -40,3 +48,4 @@ pub type Command = Vec<String>;
pub type Parallel = bool;
pub type Pattern = String;
pub type Separator = char;
pub type Omit = Vec<String>;
Binary file modified Target/release/PSummary.exe
Binary file not shown.
Binary file modified Target/release/Summary.exe
Binary file not shown.
6 changes: 3 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#![allow(non_snake_case)]

use serde::Deserialize;
use std::fs;

#[derive(Deserialize)]
struct Toml {
package: Package,
Expand All @@ -24,3 +21,6 @@ fn main() {
.version
);
}

use serde::Deserialize;
use std::fs;

0 comments on commit f05e050

Please sign in to comment.