Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
92a0e3b1b3 | |||
b167b3ebfa | |||
b78631d6ac | |||
00a249978e | |||
a86a4197f7 | |||
0397b64e28 | |||
77901c6ac9 | |||
a1eadd67e1 | |||
d5271807f7 | |||
947e05e573 |
25
CHANGELOG.md
25
CHANGELOG.md
@@ -6,6 +6,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [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
|
||||||
|
- trigger commit
|
||||||
|
|
||||||
|
## [0.2.1] - 2024-12-22
|
||||||
|
|
||||||
|
### Other
|
||||||
|
- fix cargo toml
|
||||||
|
|
||||||
## [0.2.0] - 2024-12-22
|
## [0.2.0] - 2024-12-22
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -159,7 +159,7 @@ checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kignore"
|
name = "kignore"
|
||||||
version = "0.1.3"
|
version = "0.2.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"console",
|
"console",
|
||||||
|
@@ -3,4 +3,4 @@ members = ["crates/*"]
|
|||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
|
@@ -3,10 +3,10 @@ name = "kignore"
|
|||||||
version.workspace = true
|
version.workspace = true
|
||||||
authors = ["Kasper J. Hermansen <contact@kjuulh.io>"]
|
authors = ["Kasper J. Hermansen <contact@kjuulh.io>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
readme = "README.md"
|
readme = "../../README.md"
|
||||||
keywords = ["git", "ignore", "clap", "interactive"]
|
keywords = ["git", "ignore", "clap", "interactive"]
|
||||||
repository = "https://github.com/kjuulh/gitignore"
|
repository = "https://git.front.kjuulh.io/kjuulh/gitignore"
|
||||||
documentation = "https://docs.rs/gitignore"
|
documentation = "https://docs.rs/kignore"
|
||||||
description = """
|
description = """
|
||||||
kignore is a tool for easily adding patterns to .gitignore and cleaning up afterwards
|
kignore is a tool for easily adding patterns to .gitignore and cleaning up afterwards
|
||||||
"""
|
"""
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
use clap::{Arg, Command};
|
use clap::{Arg, Command};
|
||||||
|
use console::style;
|
||||||
use eyre::{Context, ContextCompat};
|
use eyre::{Context, ContextCompat};
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::{env::current_dir, io::Read, path::PathBuf};
|
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<()> {
|
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(
|
let curdir = current_dir().context(
|
||||||
"could not find current_dir, you may not have permission to access that directory",
|
"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 {
|
match actions {
|
||||||
GitActions::AddPattern { gitignore_path } => {
|
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_file = open_gitignore_file(&gitignore_path)?;
|
||||||
let mut gitignore_content = String::new();
|
let mut gitignore_content = String::new();
|
||||||
gitignore_file
|
gitignore_file
|
||||||
@@ -85,22 +86,26 @@ fn add_gitignore_pattern(term: console::Term, pattern: &String) -> eyre::Result<
|
|||||||
gitignore_path.to_string_lossy()
|
gitignore_path.to_string_lossy()
|
||||||
))?;
|
))?;
|
||||||
if gitignore_content.contains(pattern) {
|
if gitignore_content.contains(pattern) {
|
||||||
term.write_line(".gitignore already contains pattern, skipping")?;
|
println!(
|
||||||
|
".gitignore already contains pattern, {}",
|
||||||
|
style("skipping...").blue()
|
||||||
|
);
|
||||||
return Ok(());
|
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")?;
|
writeln!(gitignore_file, "{}", pattern).context("could not write contents to file")?;
|
||||||
gitignore_file
|
gitignore_file
|
||||||
.sync_all()
|
.sync_all()
|
||||||
.context("failed to write data to disk")?;
|
.context("failed to write data to disk")?;
|
||||||
}
|
}
|
||||||
GitActions::CreateIgnoreAndAddPattern { git_path } => {
|
GitActions::CreateIgnoreAndAddPattern { git_path } => {
|
||||||
term.write_line(
|
println!(
|
||||||
"could not find .gitignore file, creating one in the root of the git repository",
|
"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)?;
|
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")?;
|
writeln!(gitignore_file, "{}", pattern).context("could not write contents to file")?;
|
||||||
gitignore_file
|
gitignore_file
|
||||||
.sync_all()
|
.sync_all()
|
||||||
@@ -121,8 +126,19 @@ fn add_gitignore_pattern(term: console::Term, pattern: &String) -> eyre::Result<
|
|||||||
String::from_utf8(output.stdout)?
|
String::from_utf8(output.stdout)?
|
||||||
.lines()
|
.lines()
|
||||||
.chain(String::from_utf8(output.stderr)?.lines())
|
.chain(String::from_utf8(output.stderr)?.lines())
|
||||||
.try_for_each(|l| term.write_line(l))
|
.map(|l| {
|
||||||
.context("could not print all output to terminal")?;
|
// 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() {
|
if !output.status.success() {
|
||||||
return Err(eyre::anyhow!("failed to run git index command"));
|
return Err(eyre::anyhow!("failed to run git index command"));
|
||||||
|
Reference in New Issue
Block a user