6 Commits

Author SHA1 Message Date
92a0e3b1b3 chore(release): v0.3.0 (#89)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
chore(release): 0.3.0

Co-authored-by: cuddle-please <bot@cuddle.sh>
Reviewed-on: https://git.front.kjuulh.io/kjuulh/gitignore/pulls/89
2024-12-22 13:01:48 +01:00
b167b3ebfa feat: make cli look nice
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2024-12-22 13:00:58 +01:00
b78631d6ac chore(release): v0.2.4 (#88)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
chore(release): 0.2.4

Co-authored-by: cuddle-please <bot@cuddle.sh>
Reviewed-on: https://git.front.kjuulh.io/kjuulh/gitignore/pulls/88
2024-12-22 12:44:31 +01:00
00a249978e chore: trigger commit
All checks were successful
continuous-integration/drone/push Build is passing
2024-12-22 12:43:57 +01:00
a86a4197f7 chore(release): v0.2.3 (#87)
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is failing
chore(release): 0.2.3

Co-authored-by: cuddle-please <bot@cuddle.sh>
Reviewed-on: https://git.front.kjuulh.io/kjuulh/gitignore/pulls/87
2024-12-22 12:37:08 +01:00
0397b64e28 chore: trigger commit
All checks were successful
continuous-integration/drone/push Build is passing
2024-12-22 12:36:39 +01:00
4 changed files with 43 additions and 12 deletions

View File

@@ -6,6 +6,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [0.3.0] - 2024-12-22
### Added
- make cli look nice
## [0.2.4] - 2024-12-22
### Other
- trigger commit
## [0.2.3] - 2024-12-22
### Other
- trigger commit
## [0.2.2] - 2024-12-22
### Added

2
Cargo.lock generated
View File

@@ -159,7 +159,7 @@ checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
[[package]]
name = "kignore"
version = "0.2.0"
version = "0.2.3"
dependencies = [
"clap",
"console",

View File

@@ -3,4 +3,4 @@ members = ["crates/*"]
resolver = "2"
[workspace.package]
version = "0.2.2"
version = "0.3.0"

View File

@@ -1,4 +1,5 @@
use clap::{Arg, Command};
use console::style;
use eyre::{Context, ContextCompat};
use std::io::prelude::*;
use std::{env::current_dir, io::Read, path::PathBuf};
@@ -55,7 +56,7 @@ enum GitActions {
}
fn add_gitignore_pattern(term: console::Term, pattern: &String) -> eyre::Result<()> {
term.write_line("git ignore: Add pattern")?;
println!("git ignore: Add pattern");
let curdir = current_dir().context(
"could not find current_dir, you may not have permission to access that directory",
)?;
@@ -75,7 +76,7 @@ fn add_gitignore_pattern(term: console::Term, pattern: &String) -> eyre::Result<
match actions {
GitActions::AddPattern { gitignore_path } => {
term.write_line("Found existing .gitignore")?;
println!("Found existing {}", style(".gitignore").green());
let mut gitignore_file = open_gitignore_file(&gitignore_path)?;
let mut gitignore_content = String::new();
gitignore_file
@@ -85,22 +86,26 @@ fn add_gitignore_pattern(term: console::Term, pattern: &String) -> eyre::Result<
gitignore_path.to_string_lossy()
))?;
if gitignore_content.contains(pattern) {
term.write_line(".gitignore already contains pattern, skipping")?;
println!(
".gitignore already contains pattern, {}",
style("skipping...").blue()
);
return Ok(());
}
term.write_line("adding pattern to file")?;
println!("adding pattern to file");
writeln!(gitignore_file, "{}", pattern).context("could not write contents to file")?;
gitignore_file
.sync_all()
.context("failed to write data to disk")?;
}
GitActions::CreateIgnoreAndAddPattern { git_path } => {
term.write_line(
"could not find .gitignore file, creating one in the root of the git repository",
)?;
println!(
"could not find {} file, creating one in the root of the git repository",
style(".gitignore").yellow()
);
let mut gitignore_file = create_gitignore_file(git_path)?;
term.write_line("adding pattern to file")?;
println!("adding pattern to file");
writeln!(gitignore_file, "{}", pattern).context("could not write contents to file")?;
gitignore_file
.sync_all()
@@ -121,8 +126,19 @@ fn add_gitignore_pattern(term: console::Term, pattern: &String) -> eyre::Result<
String::from_utf8(output.stdout)?
.lines()
.chain(String::from_utf8(output.stderr)?.lines())
.try_for_each(|l| term.write_line(l))
.context("could not print all output to terminal")?;
.map(|l| {
// make rm 'path' look nice
if l.contains("rm") {
if let Some((_, pruned_first)) = l.split_once("'") {
if let Some((content, _)) = pruned_first.rsplit_once("'") {
return content;
}
}
}
l
})
.for_each(|l| println!("removed from git history: {}", style(l).yellow()));
if !output.status.success() {
return Err(eyre::anyhow!("failed to run git index command"));