codefetch-cli 1.2.0__py3-none-any.whl → 1.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
codefetch/__init__.py CHANGED
@@ -2,4 +2,4 @@
2
2
  CodeFetch - CLI tool to fetch code files from GitHub repositories.
3
3
  """
4
4
 
5
- __version__ = "1.2.0"
5
+ __version__ = "1.2.1"
codefetch/cli.py CHANGED
@@ -18,13 +18,84 @@ DEFAULT_BRANCH = "main"
18
18
 
19
19
  CONFIG_FILE = Path.home() / ".codefetch.json"
20
20
 
21
- # Supported code extensions
21
+ # Supported code, data, and config extensions
22
22
  CODE_EXTENSIONS = {
23
- ".py", ".c", ".cpp", ".h", ".hpp", ".java", ".js", ".ts",
24
- ".sql", ".html", ".css", ".txt", ".asm", ".s", ".hex",
25
- ".json", ".sh", ".rs", ".go", ".cs", ".ipynb", ".md"
23
+ # Data & Tables
24
+ ".csv", ".tsv", ".json", ".jsonl", ".yaml", ".yml", ".toml",
25
+ ".xml", ".ini", ".cfg", ".conf", ".env", ".properties",
26
+ # Python & Data Science
27
+ ".py", ".pyw", ".ipynb", ".r", ".rmd", ".m",
28
+ # C / C++ / Systems
29
+ ".c", ".cpp", ".cc", ".cxx", ".h", ".hpp", ".hxx", ".rs", ".go",
30
+ # JVM & .NET
31
+ ".java", ".kt", ".kts", ".scala", ".cs", ".fs", ".vb",
32
+ # Web & Frontend
33
+ ".html", ".htm", ".css", ".scss", ".sass", ".less",
34
+ ".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx", ".vue", ".svelte", ".php",
35
+ # Mobile & Apple
36
+ ".swift", ".dart",
37
+ # Scripts & Shells
38
+ ".sh", ".bash", ".zsh", ".fish", ".bat", ".cmd", ".ps1", ".psm1",
39
+ ".lua", ".rb", ".pl", ".pm",
40
+ # Assembly & Hardware
41
+ ".asm", ".s", ".hex", ".v", ".sv", ".vhdl", ".vhd",
42
+ # Database & Schema
43
+ ".sql", ".graphql", ".gql", ".proto",
44
+ # Documents & Text
45
+ ".txt", ".text", ".md", ".markdown", ".rst", ".tex", ".log"
26
46
  }
27
47
 
48
+ # Recognized extensionless or special build files
49
+ NAMED_FILES = {
50
+ "dockerfile", "makefile", "gemfile", "procfile", "vagrantfile",
51
+ "cmakelists.txt", "jenkinsfile", "license"
52
+ }
53
+
54
+ HELP_MESSAGE = """\
55
+ CodeFetch - Download single code files from GitHub without cloning entire repos.
56
+
57
+ USAGE:
58
+ codefetch <filename> Download a file from default repo (MPL)
59
+ codefetch <repo> <filename> Download from another repo (e.g. DS EXP1.c)
60
+ codefetch <user>/<repo> <filename> Download from any GitHub user/repo
61
+
62
+ QUICK EXAMPLES:
63
+ Download a file:
64
+ codefetch 8.1.py Save 8.1.py to current directory
65
+ codefetch data.csv Save data.csv to current directory
66
+ codefetch DS EXP1.c Save EXP1.c from repo 'DS'
67
+ codefetch DS EXP1.c -o my_code.c Save with a custom output filename
68
+ codefetch InzamamulQureshi/Codefetch setup.py
69
+
70
+ View code in terminal (without downloading):
71
+ codefetch -s 8.1.py Display 8.1.py in terminal
72
+ codefetch -s DS EXP1.c Display EXP1.c in terminal
73
+
74
+ Browse files and repositories:
75
+ codefetch -l List all code files in default repo (MPL)
76
+ codefetch -l DS List all code files in repo 'DS'
77
+ codefetch -l user/repo List code files in any user repository
78
+ codefetch -R List all repositories of default user (Reaver101)
79
+ codefetch -R -u <username> List all repositories of any GitHub user
80
+
81
+ SETTINGS & DEFAULTS:
82
+ codefetch --set-default <repo> Set permanent default repo (e.g. DS)
83
+ codefetch --set-default-user <user> Set permanent default GitHub user
84
+ codefetch --config View current active settings
85
+ codefetch --reset-config Reset all settings back to default
86
+
87
+ OPTIONS:
88
+ -s, --show View file contents in terminal instead of saving
89
+ -o, --output <file> Custom filename or path to save the downloaded file
90
+ -l, --list List available code files in the repository
91
+ -R, --repos List all public repositories for the user
92
+ -r, --repo <name> Specify repository name or URL
93
+ -u, --user <name> Specify GitHub username (default: Reaver101)
94
+ -b, --branch <name> Specify branch name (default: main)
95
+ -v, --version Show version number
96
+ -h, --help Show this help guide
97
+ """
98
+
28
99
 
29
100
  def load_config():
30
101
  """Load configuration from environment variables and local config file."""
@@ -171,11 +242,12 @@ def list_files(owner, repo, branch="main"):
171
242
  continue
172
243
 
173
244
  path = item.get("path", "")
245
+ base_name = path.rsplit("/", 1)[-1].lower()
174
246
  suffix = ""
175
- if "." in path.rsplit("/", 1)[-1]:
176
- suffix = "." + path.rsplit("/", 1)[-1].rsplit(".", 1)[-1].lower()
247
+ if "." in base_name:
248
+ suffix = "." + base_name.rsplit(".", 1)[-1]
177
249
 
178
- if suffix in CODE_EXTENSIONS:
250
+ if suffix in CODE_EXTENSIONS or base_name in NAMED_FILES:
179
251
  files.append(path)
180
252
 
181
253
  files.sort(key=str.lower)
@@ -335,38 +407,22 @@ def fetch_file(filename, owner=DEFAULT_OWNER, repo=DEFAULT_REPO, branch=DEFAULT_
335
407
  print(f"Error saving file '{out_name}': {e}")
336
408
 
337
409
 
410
+ class CodefetchParser(argparse.ArgumentParser):
411
+ """Custom parser providing clean, intuitive help formatting."""
412
+
413
+ def format_help(self):
414
+ return HELP_MESSAGE
415
+
416
+ def error(self, message):
417
+ sys.stderr.write(f"Error: {message}\n\nRun 'codefetch --help' for usage instructions.\n")
418
+ sys.exit(2)
419
+
420
+
338
421
  def build_parser():
339
422
  """Build argument parser with full CLI options."""
340
- parser = argparse.ArgumentParser(
423
+ parser = CodefetchParser(
341
424
  prog="codefetch",
342
- description="Quickly fetch code files from GitHub repositories with simple commands.",
343
- formatter_class=argparse.RawDescriptionHelpFormatter,
344
- epilog="""
345
- Usage Examples:
346
-
347
- Fetch from default repository:
348
- codefetch 8.1.py
349
- codefetch --show 8.1.py
350
- codefetch --list
351
-
352
- Fetch from other repositories:
353
- codefetch -r DS EXP1.c
354
- codefetch DS EXP1.c
355
- codefetch DS/EXP1.c
356
- codefetch -r DS --list
357
-
358
- Fetch from any GitHub user and repository:
359
- codefetch InzamamulQureshi/Codefetch setup.py
360
- codefetch -u InzamamulQureshi -r Codefetch setup.py
361
- codefetch --list InzamamulQureshi/Codefetch
362
- codefetch --repos -u InzamamulQureshi
363
-
364
- Configuration:
365
- codefetch --set-default DS
366
- codefetch --set-default-user InzamamulQureshi
367
- codefetch --config
368
- codefetch --reset-config
369
- """
425
+ add_help=True,
370
426
  )
371
427
  parser.add_argument(
372
428
  "args",
@@ -431,7 +487,7 @@ Usage Examples:
431
487
  parser.add_argument(
432
488
  "-v", "--version",
433
489
  action="version",
434
- version="codefetch 1.2.0",
490
+ version="codefetch 1.2.1",
435
491
  )
436
492
  return parser
437
493
 
@@ -560,7 +616,7 @@ def main():
560
616
  list_files(owner=target_owner, repo=target_repo, branch=branch)
561
617
  return
562
618
 
563
- # Handle fetching or viewing file
619
+ # If no action and no files provided, print the clean help guide
564
620
  if not args.args and not args.repo:
565
621
  parser.print_help()
566
622
  return
@@ -579,8 +635,11 @@ def main():
579
635
  )
580
636
 
581
637
  if not resolved_filename:
582
- print("Error: No filename specified.")
583
- parser.print_help()
638
+ print("Error: No filename specified.\n")
639
+ print("Usage:")
640
+ print(" codefetch <filename> Download a file")
641
+ print(" codefetch <repo> <filename> Download from a repository")
642
+ print(" codefetch --help View full guide and examples")
584
643
  return
585
644
 
586
645
  fetch_file(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codefetch-cli
3
- Version: 1.2.0
3
+ Version: 1.2.1
4
4
  Summary: Quickly fetch code files from GitHub repositories with simple commands
5
5
  Home-page: https://github.com/InzamamulQureshi/Codefetch
6
6
  Author: Inzamamul Qureshi
@@ -171,9 +171,14 @@ codefetch --reset-config
171
171
 
172
172
  ## Supported File Extensions
173
173
 
174
- CodeFetch recognizes and lists common source and document files:
175
-
176
- `.py`, `.c`, `.cpp`, `.h`, `.hpp`, `.java`, `.js`, `.ts`, `.sql`, `.html`, `.css`, `.txt`, `.asm`, `.s`, `.hex`, `.json`, `.sh`, `.rs`, `.go`, `.cs`, `.ipynb`, `.md`
174
+ - **Data & Tables**: `.csv`, `.tsv`, `.json`, `.jsonl`, `.yaml`, `.yml`, `.toml`, `.xml`, `.ini`, `.cfg`, `.conf`, `.env`
175
+ - **Data Science**: `.ipynb`, `.py`, `.r`, `.rmd`, `.m`
176
+ - **Languages**: `.c`, `.cpp`, `.h`, `.hpp`, `.rs`, `.go`, `.java`, `.kt`, `.cs`, `.swift`, `.dart`, `.php`
177
+ - **Web**: `.html`, `.css`, `.scss`, `.js`, `.jsx`, `.ts`, `.tsx`, `.vue`, `.svelte`
178
+ - **Scripts & Systems**: `.sh`, `.bash`, `.zsh`, `.fish`, `.bat`, `.cmd`, `.ps1`, `.lua`, `.rb`, `.asm`, `.s`, `.hex`
179
+ - **Database & Schemas**: `.sql`, `.graphql`, `.gql`, `.proto`
180
+ - **Documentation**: `.md`, `.markdown`, `.rst`, `.txt`, `.tex`, `.log`
181
+ - **Build Files**: `Dockerfile`, `Makefile`, `CMakeLists.txt`, `Gemfile`, `Procfile`
177
182
 
178
183
  ---
179
184
 
@@ -0,0 +1,8 @@
1
+ codefetch/__init__.py,sha256=hbpjJJOuxVjNlJ4ZVpsQEyhLAepknLr6ugsa01sVVCU,98
2
+ codefetch/cli.py,sha256=-Eg3K81jid2uXQ-sGA943HWHL92-WYNi3-Q6putdlEQ,22588
3
+ codefetch_cli-1.2.1.dist-info/licenses/LICENSE,sha256=eztogQOJbUv4rWzTBEaVeMVQYzoaP1Ehs_vg-CqlpsM,1066
4
+ codefetch_cli-1.2.1.dist-info/METADATA,sha256=LMZvjcTMWpMb6B3Qciy4hEoZXAFhAHJJ-Shxev11nrs,6117
5
+ codefetch_cli-1.2.1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
6
+ codefetch_cli-1.2.1.dist-info/entry_points.txt,sha256=jFLRsBB_USeSdqjewcXZfnOzY56s0PZat7mnYkYdrXg,49
7
+ codefetch_cli-1.2.1.dist-info/top_level.txt,sha256=kHrftHbyqugb8LQXjW1dR9uI-JFjZQJ0sUReIa45yXQ,10
8
+ codefetch_cli-1.2.1.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- codefetch/__init__.py,sha256=moQvfngOVj4i_LyONh3xRINv728-UvtH5LtTK5VVRcE,98
2
- codefetch/cli.py,sha256=pSaTPdqH0CwV5L2XipbeuL54q5AcmmLp9S6yrqno_TQ,19543
3
- codefetch_cli-1.2.0.dist-info/licenses/LICENSE,sha256=eztogQOJbUv4rWzTBEaVeMVQYzoaP1Ehs_vg-CqlpsM,1066
4
- codefetch_cli-1.2.0.dist-info/METADATA,sha256=iQlUxKlaagL3N79ycXo5TgSwt_rACGok8vnmBDm-MWE,5635
5
- codefetch_cli-1.2.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
6
- codefetch_cli-1.2.0.dist-info/entry_points.txt,sha256=jFLRsBB_USeSdqjewcXZfnOzY56s0PZat7mnYkYdrXg,49
7
- codefetch_cli-1.2.0.dist-info/top_level.txt,sha256=kHrftHbyqugb8LQXjW1dR9uI-JFjZQJ0sUReIa45yXQ,10
8
- codefetch_cli-1.2.0.dist-info/RECORD,,