Skip to content

Commit 9891198

Browse files
unhappychoiceclaude
andcommitted
refactor(cli): remove unused config.rs and update CLI structure
- Remove unused cli/config.rs file - Update CLI commands and arguments structure - Clean up chunk model definitions and other minor refactoring 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3b89dee commit 9891198

File tree

5 files changed

+98
-84
lines changed

5 files changed

+98
-84
lines changed

src/cli/args.rs

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,49 @@ use std::path::PathBuf;
44
#[derive(Parser)]
55
#[command(name = "gittype")]
66
#[command(
7-
about = "A typing practice tool using your own code repositories - extracts all code chunks (functions, classes, methods, etc.)"
7+
about = "A typing practice tool using your own code repositories - extracts all code chunks (functions, classes, methods, etc.)",
8+
long_about = "GitType turns your own source code into typing challenges. \
9+
Practice typing by using functions, classes, and methods from your actual projects. \
10+
\n\nExamples:\n \
11+
gittype # Use current directory\n \
12+
gittype /path/to/repo # Use specific repository\n \
13+
gittype --repo owner/repo # Clone and use GitHub repository\n \
14+
gittype --langs rust,python # Filter by languages"
815
)]
9-
#[command(version = "0.1.0")]
16+
#[command(version = env!("CARGO_PKG_VERSION"))]
1017
pub struct Cli {
11-
/// Repository path to extract code from
12-
#[arg(value_name = "REPO_PATH")]
18+
/// Repository path to extract code from (defaults to current directory if not specified)
19+
#[arg(
20+
value_name = "REPO_PATH",
21+
help = "Repository path to extract code from"
22+
)]
1323
pub repo_path: Option<PathBuf>,
1424

15-
/// GitHub repository URL or path to clone and play with (e.g., owner/repo, https://github.com/owner/repo, git@github.com:owner/repo.git)
16-
#[arg(long)]
25+
/// GitHub repository URL or path to clone and play with
26+
#[arg(
27+
long,
28+
help = "GitHub repository URL or path to clone and play with",
29+
long_help = "GitHub repository URL or path to clone and play with. \
30+
Supports formats:\n \
31+
- owner/repo\n \
32+
- https://github.com/owner/repo\n \
33+
- git@github.com:owner/repo.git"
34+
)]
1735
pub repo: Option<String>,
1836

19-
/// Filter by programming languages
20-
#[arg(long, value_delimiter = ',')]
37+
/// Filter by programming languages (comma-separated)
38+
#[arg(
39+
long,
40+
value_delimiter = ',',
41+
help = "Filter by programming languages (comma-separated)",
42+
long_help = "Filter by programming languages (comma-separated). \
43+
Supported languages:\n \
44+
rust, typescript, javascript, python, ruby, go, swift, \
45+
kotlin, java, php, csharp, c, cpp, haskell, dart\n \
46+
Example: --langs rust,python,typescript"
47+
)]
2148
pub langs: Option<Vec<String>>,
2249

23-
/// Number of stages for normal mode
24-
#[arg(long, default_value_t = 3)]
25-
pub stages: usize,
26-
27-
/// Glob patterns for files to include
28-
#[arg(long)]
29-
pub include: Option<Vec<String>>,
30-
31-
/// Glob patterns for files to exclude
32-
#[arg(long)]
33-
pub exclude: Option<Vec<String>>,
34-
3550
/// Path to config file
3651
#[arg(long)]
3752
pub config: Option<PathBuf>,

src/cli/commands/game.rs

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,27 @@ use std::path::PathBuf;
88
pub fn run_game_session(cli: Cli) -> Result<()> {
99
let mut options = ExtractionOptions::default();
1010

11-
if let Some(include_patterns) = cli.include {
12-
options.include_patterns = include_patterns;
13-
}
11+
if let Some(langs) = cli.langs {
12+
if let Err(unsupported_langs) =
13+
crate::extractor::models::language::LanguageRegistry::validate_languages(&langs)
14+
{
15+
eprintln!(
16+
"❌ Unsupported language(s): {}",
17+
unsupported_langs.join(", ")
18+
);
19+
eprintln!("💡 Supported languages:");
20+
let supported =
21+
crate::extractor::models::language::LanguageRegistry::get_supported_languages();
22+
let mut supported_display = supported.clone();
23+
supported_display.dedup();
24+
for chunk in supported_display.chunks(6) {
25+
eprintln!(" {}", chunk.join(", "));
26+
}
27+
std::process::exit(1);
28+
}
1429

15-
if let Some(exclude_patterns) = cli.exclude {
16-
options.exclude_patterns = exclude_patterns;
30+
options.languages = Some(langs);
31+
options.apply_language_filter();
1732
}
1833

1934
let repo_spec = cli.repo.as_deref();
@@ -59,45 +74,72 @@ pub fn run_game_session(cli: Cli) -> Result<()> {
5974
fn handle_game_error(e: GitTypeError) -> Result<()> {
6075
match e {
6176
GitTypeError::NoSupportedFiles => {
62-
panic!("No code chunks found in the repository");
77+
eprintln!("❌ No code chunks found in the repository");
78+
eprintln!("💡 Try:");
79+
eprintln!(" • Using a different repository path");
80+
eprintln!(" • Adjusting --langs filter (e.g., --langs rust,python)");
81+
std::process::exit(1);
6382
}
6483
GitTypeError::RepositoryNotFound(path) => {
65-
panic!("Repository not found at path: {}", path.display());
84+
eprintln!("❌ Repository not found at path: {}", path.display());
85+
eprintln!("💡 Ensure the path exists and is a valid repository");
86+
std::process::exit(1);
6687
}
6788
GitTypeError::RepositoryCloneError(git_error) => {
68-
panic!("Failed to clone repository: {}", git_error);
89+
eprintln!("❌ Failed to clone repository: {}", git_error);
90+
eprintln!("💡 Check:");
91+
eprintln!(" • Repository URL is correct");
92+
eprintln!(" • You have access to the repository");
93+
eprintln!(" • Internet connection is available");
94+
std::process::exit(1);
6995
}
7096
GitTypeError::ExtractionFailed(msg) => {
71-
panic!("Code extraction failed: {}", msg);
97+
eprintln!("❌ Code extraction failed: {}", msg);
98+
eprintln!("💡 Try using different --langs filter");
99+
std::process::exit(1);
72100
}
73101
GitTypeError::InvalidRepositoryFormat(msg) => {
74-
panic!("Invalid repository format: {}", msg);
102+
eprintln!("❌ Invalid repository format: {}", msg);
103+
eprintln!("💡 Supported formats:");
104+
eprintln!(" • owner/repo");
105+
eprintln!(" • https://github.com/owner/repo");
106+
eprintln!(" • git@github.com:owner/repo.git");
107+
std::process::exit(1);
75108
}
76109
GitTypeError::IoError(io_error) => {
77-
panic!("IO error: {}", io_error);
110+
eprintln!("❌ IO error: {}", io_error);
111+
std::process::exit(1);
78112
}
79113
GitTypeError::DatabaseError(db_error) => {
80-
panic!("Database error: {}", db_error);
114+
eprintln!("❌ Database error: {}", db_error);
115+
std::process::exit(1);
81116
}
82117
GitTypeError::GlobPatternError(glob_error) => {
83-
panic!("Glob pattern error: {}", glob_error);
118+
eprintln!("❌ Invalid glob pattern: {}", glob_error);
119+
eprintln!("💡 Check your glob patterns in ExtractionOptions");
120+
std::process::exit(1);
84121
}
85122
GitTypeError::SerializationError(json_error) => {
86-
panic!("Serialization error: {}", json_error);
123+
eprintln!("❌ Serialization error: {}", json_error);
124+
std::process::exit(1);
87125
}
88126
GitTypeError::TerminalError(msg) => {
89-
eprintln!("Terminal error: {}", msg);
127+
eprintln!("Terminal error: {}", msg);
90128
if msg.contains("No such device or address") {
91-
eprintln!("\nHint: This error often occurs in WSL or SSH environments where terminal features are limited.");
92-
eprintln!("Try running GitType in a native terminal or GUI terminal emulator.");
129+
eprintln!("💡 This error often occurs in WSL or SSH environments where terminal features are limited.");
130+
eprintln!(" Try running GitType in a native terminal or GUI terminal emulator.");
93131
}
94-
panic!("Terminal error: {}", msg);
132+
std::process::exit(1);
95133
}
96134
GitTypeError::WalkDirError(walk_error) => {
97-
panic!("Directory walk error: {}", walk_error);
135+
eprintln!("❌ Directory walk error: {}", walk_error);
136+
eprintln!("💡 Check directory permissions and try again");
137+
std::process::exit(1);
98138
}
99139
GitTypeError::TreeSitterLanguageError(lang_error) => {
100-
panic!("Tree-sitter language error: {}", lang_error);
140+
eprintln!("❌ Language parsing error: {}", lang_error);
141+
eprintln!("💡 This might be caused by unsupported language features");
142+
std::process::exit(1);
101143
}
102144
}
103145
}

src/cli/config.rs

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/cli/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
pub mod args;
22
pub mod commands;
3-
pub mod config;
43
pub mod runner;
54

65
pub use args::{Cli, Commands};
7-
pub use config::Config;
86
pub use runner::{run_cli, setup_signal_handlers};

src/extractor/models/chunk.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use super::Language;
21
use std::path::PathBuf;
32

43
#[derive(Debug, Clone)]
@@ -24,7 +23,7 @@ pub struct CodeChunk {
2423
pub file_path: PathBuf,
2524
pub start_line: usize,
2625
pub end_line: usize,
27-
pub language: Language,
26+
pub language: String,
2827
pub chunk_type: ChunkType,
2928
pub name: String,
3029
pub comment_ranges: Vec<(usize, usize)>, // Character-based ranges for comments relative to content

0 commit comments

Comments
 (0)