Skip to content

Commit d2278a3

Browse files
committed
v0.0.2
1 parent f981a19 commit d2278a3

File tree

6 files changed

+97
-36
lines changed

6 files changed

+97
-36
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "gitig"
3-
version = "0.0.1"
3+
version = "0.0.2"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

README.md

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,56 @@
1+
<div>
2+
<img src="images/gitig.png">
3+
</div>
4+
15
# gitig
26

7+
<img src="https://img.shields.io/github/v/release/gold24park/gitig">
8+
9+
Creates a `.gitignore` file for the configured project!
10+
11+
It is provided based on the `.gitignore` template available at [https://github.com/github/gitignore](https://github.com/github/gitignore)
12+
13+
## Installation
14+
15+
```
16+
brew install gitig
17+
```
18+
19+
## Quick Start
20+
21+
```
22+
# Creates .gitignore for Android Project
23+
gitig android
24+
```
25+
26+
```
27+
# Creates .gitignore for NodeJs Project to ~/my-node-js-project
28+
gitig node ~/my-node-js-project
29+
```
30+
31+
```
32+
# Show available project list
33+
gitig --list
334
```
4-
gitig [<options>] [project] [path]
535

36+
```
37+
# Show available projects starts with "no"
38+
gitig --list no
39+
```
40+
41+
## Usage
42+
43+
```
644
USAGE:
7-
gitig <project> [path]
45+
gitig [FLAGS] [ARGS]
846
947
FLAGS:
10-
-h, --help Prints help information
11-
-V, --version Prints version information
48+
-h, --help Prints help information
49+
-l, --list
50+
-V, --version Prints version information
1251
1352
ARGS:
14-
<project> gitignore를 생성할 project
15-
<path> 지정한 경로에 .gitignore 생성 [default: .]
53+
<project> The project for which to create a .gitignore [default: ]
54+
<path> The path to create the .gitignore [default: .]
55+
1656
```

src/cli.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ use structopt::StructOpt;
55
#[derive(Debug, StructOpt)]
66
#[structopt(
77
name = "gitig",
8-
about = "Creates a gitignore for the configured project.",
8+
about = "Creates a gitignore boilerplate for the configured project.",
99
author = "gold24park"
1010
)]
1111
pub struct CmdArgs {
1212
/// The project for which to create a .gitignore.
13+
#[structopt(default_value = "")]
1314
pub project: String,
1415

1516
/// The path to create the .gitignore.
1617
#[structopt(parse(from_os_str), default_value = ".")]
1718
pub path: PathBuf,
19+
20+
//// List available projects
21+
#[structopt(short, long)]
22+
pub list: bool,
1823
}

src/git.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub struct FlattenGitTree {
4242
#[derive(Debug, Deserialize)]
4343
pub struct Element {
4444
#[serde(skip)]
45-
project: String,
45+
pub project: String,
4646
path: String,
4747
sha: String,
4848
}
@@ -85,6 +85,10 @@ impl ProjectMatcher for Element {
8585
}
8686

8787
impl FlattenGitTree {
88+
pub fn iter(&self) -> core::slice::Iter<'_, Element> {
89+
self.elements.iter()
90+
}
91+
8892
pub fn init(client: &impl HttpClient) -> Option<FlattenGitTree> {
8993
let url = "https://api.github.com/repos/github/gitignore/git/trees/main?recursive=0";
9094
let body = client.get(url).ok()?;

src/main.rs

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,51 @@ fn main() -> anyhow::Result<()> {
1818

1919
let git_tree = FlattenGitTree::init(&client).ok_or(anyhow!("Failed to init project list."))?;
2020

21-
match git_tree.get(&args.project) {
22-
Some(element) => {
23-
let content = element
24-
.download(&client)
25-
.ok_or(anyhow!("Failed to download gitignore."))?;
21+
if args.list {
22+
git_tree
23+
.iter()
24+
.filter(|e| {
25+
e.project
26+
.to_lowercase()
27+
.starts_with(&args.project.to_lowercase())
28+
})
29+
.for_each(|e| println!("- {}", e.project))
30+
} else {
31+
match git_tree.get(&args.project) {
32+
Some(element) => {
33+
let content = element
34+
.download(&client)
35+
.ok_or(anyhow!("Failed to download gitignore."))?;
2636

27-
let file_path = args.path.as_path().join(".gitignore");
37+
let file_path = args.path.as_path().join(".gitignore");
2838

29-
if file_path.exists() {
30-
// ask user to overwrite
31-
println!("File already exists. Overwrite? [y/n]");
39+
if file_path.exists() {
40+
// ask user to overwrite
41+
println!("File already exists. Overwrite? [y/n]");
3242

33-
let mut input = String::new();
34-
io::stdin().read_line(&mut input)?;
43+
let mut input = String::new();
44+
io::stdin().read_line(&mut input)?;
3545

36-
if input.to_lowercase().trim() != "y" {
37-
return Ok(());
46+
if input.to_lowercase().trim() != "y" {
47+
return Ok(());
48+
}
3849
}
39-
}
4050

41-
fs::write(file_path, content).map_err(|e| anyhow!("Failed to write file: {}", e))?;
51+
fs::write(file_path, content)
52+
.map_err(|e| anyhow!("Failed to write file: {}", e))?;
4253

43-
println!("Successfully created .gitignore for {}", args.project);
44-
}
45-
None => {
46-
let suggest_keywords = git_tree.suggest_keywords(&args.project);
47-
println!(
48-
"No project found for \"{}\". Did you mean one of these?",
49-
args.project
50-
);
51-
52-
for keyword in suggest_keywords {
53-
println!("- {}", keyword);
54+
println!("Successfully created .gitignore for {}", args.project);
55+
}
56+
None => {
57+
let suggest_keywords = git_tree.suggest_keywords(&args.project);
58+
println!(
59+
"No project found for \"{}\". Did you mean one of these?",
60+
args.project
61+
);
62+
63+
for keyword in suggest_keywords {
64+
println!("- {}", keyword);
65+
}
5466
}
5567
}
5668
}

0 commit comments

Comments
 (0)