codefetch-cli 1.2.0__py3-none-any.whl → 1.2.2__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.2"
codefetch/cli.py CHANGED
@@ -12,19 +12,85 @@ import urllib.error
12
12
  import urllib.request
13
13
  from pathlib import Path
14
14
 
15
- DEFAULT_OWNER = "Reaver101"
16
- DEFAULT_REPO = "MPL"
15
+ DEFAULT_OWNER = None
16
+ DEFAULT_REPO = None
17
17
  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 <owner>/<repo> <filename> Download a file from any GitHub repository
59
+ codefetch <filename> Download a file (requires default repository)
60
+
61
+ QUICK EXAMPLES:
62
+ Download a file:
63
+ codefetch torvalds/linux Makefile Save Makefile to current directory
64
+ codefetch owner/repo main.py Save main.py from a repository
65
+ codefetch owner/repo data.csv -o out.csv Save with a custom output filename
66
+
67
+ View code in terminal (without downloading):
68
+ codefetch -s owner/repo main.py Display main.py in terminal
69
+ codefetch -s torvalds/linux Makefile Display Makefile in terminal
70
+
71
+ Browse files and repositories:
72
+ codefetch -l owner/repo List all code files in a repository
73
+ codefetch -R -u <username> List all public repositories of a user
74
+ codefetch -R <username> List all public repositories of a user
75
+
76
+ SETTINGS & DEFAULTS (Optional):
77
+ codefetch --set-default <owner/repo> Set a permanent default repository
78
+ codefetch --set-default-user <username> Set a permanent default GitHub user
79
+ codefetch --config View current saved settings
80
+ codefetch --reset-config Clear saved settings
81
+
82
+ OPTIONS:
83
+ -s, --show View file contents in terminal instead of saving
84
+ -o, --output <file> Custom filename or path to save the downloaded file
85
+ -l, --list [repo] List available code files in a repository
86
+ -R, --repos [user] List all public repositories for a user
87
+ -r, --repo <name> Specify repository name or URL
88
+ -u, --user <name> Specify GitHub username
89
+ -b, --branch <name> Specify branch name (default: main)
90
+ -v, --version Show version number
91
+ -h, --help Show this help guide
92
+ """
93
+
28
94
 
29
95
  def load_config():
30
96
  """Load configuration from environment variables and local config file."""
@@ -86,7 +152,7 @@ def get_json(url):
86
152
  return json.loads(response.read().decode("utf-8"))
87
153
 
88
154
 
89
- def parse_repo_identifier(repo_str, default_owner=DEFAULT_OWNER):
155
+ def parse_repo_identifier(repo_str, default_owner=None):
90
156
  """Extract (owner, repo) from a repository flag, name, or URL."""
91
157
  if not repo_str:
92
158
  return default_owner, None
@@ -128,8 +194,15 @@ def get_user_repos(owner):
128
194
  return []
129
195
 
130
196
 
131
- def list_repos(owner=DEFAULT_OWNER, default_repo=DEFAULT_REPO):
197
+ def list_repos(owner=None, default_repo=None):
132
198
  """List all public repositories for the owner."""
199
+ if not owner:
200
+ print("Error: No GitHub user specified.\n")
201
+ print("Usage:")
202
+ print(" codefetch -R <username>")
203
+ print(" codefetch -R -u <username>")
204
+ return
205
+
133
206
  try:
134
207
  repos = get_user_repos(owner)
135
208
  if not repos:
@@ -140,15 +213,15 @@ def list_repos(owner=DEFAULT_OWNER, default_repo=DEFAULT_REPO):
140
213
  for r in repos:
141
214
  name = r.get("name", "")
142
215
  desc = r.get("description") or ""
143
- is_def = " (default)" if name.lower() == default_repo.lower() else ""
216
+ is_def = " (default)" if default_repo and name.lower() == default_repo.lower() else ""
144
217
  marker = "*" if is_def else "-"
145
218
  desc_text = f" - {desc}" if desc else ""
146
219
  print(f" {marker} {name}{is_def}{desc_text}")
147
220
 
148
221
  print("\nCommands:")
149
- print(f" codefetch -u {owner} -r <repo> --list List files in a repository")
150
- print(f" codefetch -u {owner} -r <repo> <filename> Download a file from a repository")
151
- print(f" codefetch --set-default <repo> Set default repository")
222
+ print(f" codefetch -l {owner}/<repo> List files in a repository")
223
+ print(f" codefetch {owner}/<repo> <filename> Download a file from a repository")
224
+ print(f" codefetch --set-default {owner}/<repo> Set default repository")
152
225
 
153
226
  except urllib.error.HTTPError as e:
154
227
  print(f"Could not list repositories: HTTP {e.code}")
@@ -160,6 +233,13 @@ def list_repos(owner=DEFAULT_OWNER, default_repo=DEFAULT_REPO):
160
233
 
161
234
  def list_files(owner, repo, branch="main"):
162
235
  """List code files in a repository."""
236
+ if not owner or not repo:
237
+ print("Error: No repository specified to list.\n")
238
+ print("Usage:")
239
+ print(" codefetch -l <owner>/<repo>")
240
+ print(" codefetch -u <owner> -r <repo> -l")
241
+ return
242
+
163
243
  try:
164
244
  data = get_repo_tree(owner, repo, branch)
165
245
  if data.get("truncated"):
@@ -171,11 +251,12 @@ def list_files(owner, repo, branch="main"):
171
251
  continue
172
252
 
173
253
  path = item.get("path", "")
254
+ base_name = path.rsplit("/", 1)[-1].lower()
174
255
  suffix = ""
175
- if "." in path.rsplit("/", 1)[-1]:
176
- suffix = "." + path.rsplit("/", 1)[-1].rsplit(".", 1)[-1].lower()
256
+ if "." in base_name:
257
+ suffix = "." + base_name.rsplit(".", 1)[-1]
177
258
 
178
- if suffix in CODE_EXTENSIONS:
259
+ if suffix in CODE_EXTENSIONS or base_name in NAMED_FILES:
179
260
  files.append(path)
180
261
 
181
262
  files.sort(key=str.lower)
@@ -212,7 +293,7 @@ def resolve_file_in_tree(tree_data, target_filename):
212
293
  Search tree for target_filename:
213
294
  1. Exact match (case-insensitive) on full path
214
295
  2. Exact match (case-insensitive) on basename
215
- 3. Match without extension (e.g. 'exp1' -> 'EXP1.c')
296
+ 3. Match without extension (e.g. 'main' -> 'main.py')
216
297
  """
217
298
  blobs = [item["path"] for item in tree_data.get("tree", []) if item.get("type") == "blob"]
218
299
  target_clean = target_filename.strip("/\\").lower()
@@ -246,11 +327,13 @@ def resolve_file_in_tree(tree_data, target_filename):
246
327
 
247
328
  def find_file_in_other_repos(owner, current_repo, target_filename):
248
329
  """Search other public repositories of the user for the target file."""
330
+ if not owner:
331
+ return None, None
249
332
  try:
250
333
  repos_data = get_user_repos(owner)
251
334
  for r in repos_data:
252
335
  r_name = r.get("name")
253
- if not r_name or r_name.lower() == current_repo.lower():
336
+ if not r_name or (current_repo and r_name.lower() == current_repo.lower()):
254
337
  continue
255
338
  default_branch = r.get("default_branch", "main")
256
339
  try:
@@ -265,9 +348,19 @@ def find_file_in_other_repos(owner, current_repo, target_filename):
265
348
  return None, None
266
349
 
267
350
 
268
- def fetch_file(filename, owner=DEFAULT_OWNER, repo=DEFAULT_REPO, branch=DEFAULT_BRANCH,
351
+ def fetch_file(filename, owner=None, repo=None, branch=DEFAULT_BRANCH,
269
352
  show=False, output=None):
270
353
  """Fetch or download a file from GitHub."""
354
+ if not owner or not repo:
355
+ print("Error: No GitHub repository specified.\n")
356
+ print("Usage:")
357
+ print(" codefetch <owner>/<repo> <filename>")
358
+ print(" codefetch -u <owner> -r <repo> <filename>\n")
359
+ print("To set a default repository:")
360
+ print(" codefetch --set-default <owner>/<repo>\n")
361
+ print("Run 'codefetch --help' for more options.")
362
+ return
363
+
271
364
  clean_filename = filename.strip("/\\")
272
365
 
273
366
  def download_url(url):
@@ -301,11 +394,11 @@ def fetch_file(filename, owner=DEFAULT_OWNER, repo=DEFAULT_REPO, branch=DEFAULT_
301
394
  if other_repo:
302
395
  print(f"File not found: '{clean_filename}' in {owner}/{repo}.")
303
396
  print(f"\n[Tip] Found '{other_match}' in repository '{other_repo}'!")
304
- print(f"To fetch it, run:\n codefetch -u {owner} -r {other_repo} {other_match}")
397
+ print(f"To fetch it, run:\n codefetch {owner}/{other_repo} {other_match}")
305
398
  return
306
399
  else:
307
400
  print(f"File not found: '{clean_filename}' in {owner}/{repo}.")
308
- print(f"Run 'codefetch -u {owner} -r {repo} --list' to see available files.")
401
+ print(f"Run 'codefetch -l {owner}/{repo}' to see available files.")
309
402
  return
310
403
  except Exception:
311
404
  print(f"File not found: '{clean_filename}' in {owner}/{repo}.")
@@ -335,53 +428,37 @@ def fetch_file(filename, owner=DEFAULT_OWNER, repo=DEFAULT_REPO, branch=DEFAULT_
335
428
  print(f"Error saving file '{out_name}': {e}")
336
429
 
337
430
 
431
+ class CodefetchParser(argparse.ArgumentParser):
432
+ """Custom parser providing clean, intuitive help formatting."""
433
+
434
+ def format_help(self):
435
+ return HELP_MESSAGE
436
+
437
+ def error(self, message):
438
+ sys.stderr.write(f"Error: {message}\n\nRun 'codefetch --help' for usage instructions.\n")
439
+ sys.exit(2)
440
+
441
+
338
442
  def build_parser():
339
443
  """Build argument parser with full CLI options."""
340
- parser = argparse.ArgumentParser(
444
+ parser = CodefetchParser(
341
445
  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
- """
446
+ add_help=True,
370
447
  )
371
448
  parser.add_argument(
372
449
  "args",
373
450
  nargs="*",
374
- help="Target specification: [user/repo] [filename] or [filename]",
451
+ help="Target specification: <owner>/<repo> <filename> or <filename>",
375
452
  )
376
453
  parser.add_argument(
377
454
  "-r", "--repo",
378
455
  default=None,
379
- help="Repository name or URL (e.g. DS, Codefetch, or user/repo)",
456
+ help="Repository name or URL (e.g. repo or owner/repo)",
380
457
  )
381
458
  parser.add_argument(
382
459
  "-u", "--user",
383
460
  default=None,
384
- help=f"GitHub user/org (default: {DEFAULT_OWNER})",
461
+ help="GitHub user/org name",
385
462
  )
386
463
  parser.add_argument(
387
464
  "-b", "--branch",
@@ -396,7 +473,7 @@ Usage Examples:
396
473
  parser.add_argument(
397
474
  "-R", "--repos",
398
475
  action="store_true",
399
- help="List all public repositories for the user",
476
+ help="List all public repositories for a user",
400
477
  )
401
478
  parser.add_argument(
402
479
  "-s", "--show",
@@ -431,13 +508,13 @@ Usage Examples:
431
508
  parser.add_argument(
432
509
  "-v", "--version",
433
510
  action="version",
434
- version="codefetch 1.2.0",
511
+ version="codefetch 1.2.2",
435
512
  )
436
513
  return parser
437
514
 
438
515
 
439
516
  def resolve_invocation(positional_args, repo_flag, user_flag, branch_flag,
440
- default_owner, default_repo, default_branch, known_repos=None):
517
+ default_owner, default_repo, default_branch):
441
518
  """
442
519
  Resolve arguments into (owner, repo, branch, filename).
443
520
  """
@@ -474,7 +551,7 @@ def resolve_invocation(positional_args, repo_flag, user_flag, branch_flag,
474
551
  if m:
475
552
  return m.group(1), m.group(2), m.group(3), m.group(4)
476
553
 
477
- # 3. Colon syntax: user/repo:filename or repo:filename
554
+ # 3. Colon syntax: user/repo:filename
478
555
  if ":" in target:
479
556
  repo_part, file_part = target.split(":", 1)
480
557
  p_owner, p_repo = parse_repo_identifier(repo_part, default_owner=owner)
@@ -486,9 +563,12 @@ def resolve_invocation(positional_args, repo_flag, user_flag, branch_flag,
486
563
  return parts[0], parts[1], branch, "/".join(parts[2:])
487
564
 
488
565
  if len(parts) == 2:
489
- return owner, parts[0], branch, parts[1]
566
+ if owner:
567
+ return owner, parts[0], branch, parts[1]
568
+ else:
569
+ return parts[0], parts[1], branch, None
490
570
 
491
- # Single filename, e.g. 8.1.py
571
+ # Single filename, e.g. main.py (requires default_owner and default_repo)
492
572
  return owner, repo, branch, target
493
573
 
494
574
 
@@ -509,7 +589,7 @@ def main():
509
589
  except Exception as e:
510
590
  print(f"Error removing config file: {e}")
511
591
  return
512
- print(f"Configuration reset to defaults (User: {DEFAULT_OWNER}, Repo: {DEFAULT_REPO}).")
592
+ print("Configuration reset to defaults (no default repository or user).")
513
593
  return
514
594
 
515
595
  # Handle --set-default-user
@@ -521,9 +601,10 @@ def main():
521
601
 
522
602
  # Handle --set-default
523
603
  if args.set_default:
524
- owner_to_save = args.user if args.user else None
525
- save_config(owner=owner_to_save, repo=args.set_default)
526
- print(f"Default repository updated to: '{args.set_default}'")
604
+ owner_part, repo_part = parse_repo_identifier(args.set_default, default_owner=args.user)
605
+ owner_to_save = owner_part or (args.user if args.user else None)
606
+ save_config(owner=owner_to_save, repo=repo_part)
607
+ print(f"Default repository updated to: '{repo_part}'")
527
608
  if owner_to_save:
528
609
  print(f"Default user updated to: '{owner_to_save}'")
529
610
  print(f"Saved to: {CONFIG_FILE}")
@@ -532,8 +613,8 @@ def main():
532
613
  # Handle --config
533
614
  if args.config:
534
615
  print("CodeFetch Configuration:")
535
- print(f" Default User: {default_owner}")
536
- print(f" Default Repository: {default_repo}")
616
+ print(f" Default User: {default_owner or 'None (not set)'}")
617
+ print(f" Default Repository: {default_repo or 'None (not set)'}")
537
618
  print(f" Default Branch: {default_branch}")
538
619
  print(f" Config File: {CONFIG_FILE}")
539
620
  return
@@ -546,6 +627,12 @@ def main():
546
627
  target_owner = owner
547
628
  if args.args:
548
629
  target_owner = args.args[0]
630
+ if not target_owner:
631
+ print("Error: No GitHub user specified.\n")
632
+ print("Usage:")
633
+ print(" codefetch --repos <username>")
634
+ print(" codefetch -R -u <username>")
635
+ return
549
636
  list_repos(owner=target_owner, default_repo=default_repo)
550
637
  return
551
638
 
@@ -557,16 +644,20 @@ def main():
557
644
  target_owner, target_repo = parse_repo_identifier(args.repo, default_owner=owner)
558
645
  elif args.args:
559
646
  target_owner, target_repo = parse_repo_identifier(args.args[0], default_owner=owner)
647
+ if not target_owner or not target_repo:
648
+ print("Error: No repository specified to list.\n")
649
+ print("Usage:")
650
+ print(" codefetch -l <owner>/<repo>")
651
+ print(" codefetch -u <owner> -r <repo> -l")
652
+ return
560
653
  list_files(owner=target_owner, repo=target_repo, branch=branch)
561
654
  return
562
655
 
563
- # Handle fetching or viewing file
656
+ # If no action and no files provided, print the clean help guide
564
657
  if not args.args and not args.repo:
565
658
  parser.print_help()
566
659
  return
567
660
 
568
- known_repos = [default_repo, "DS", "MPL", "Discord-Chatbot", "Codefetch"]
569
-
570
661
  resolved_owner, resolved_repo, resolved_branch, resolved_filename = resolve_invocation(
571
662
  args.args,
572
663
  args.repo,
@@ -575,12 +666,13 @@ def main():
575
666
  default_owner,
576
667
  default_repo,
577
668
  default_branch,
578
- known_repos=known_repos,
579
669
  )
580
670
 
581
671
  if not resolved_filename:
582
- print("Error: No filename specified.")
583
- parser.print_help()
672
+ print("Error: No filename specified.\n")
673
+ print("Usage:")
674
+ print(" codefetch <owner>/<repo> <filename>")
675
+ print(" codefetch --help View full guide and examples")
584
676
  return
585
677
 
586
678
  fetch_file(
@@ -0,0 +1,170 @@
1
+ Metadata-Version: 2.4
2
+ Name: codefetch-cli
3
+ Version: 1.2.2
4
+ Summary: Quickly fetch code files from GitHub repositories with simple commands
5
+ Home-page: https://github.com/InzamamulQureshi/Codefetch
6
+ Author: Inzamamul Qureshi
7
+ Author-email: Inzamamul Qureshi <inzamamulqureshi@gmail.com>
8
+ License-Expression: MIT
9
+ Project-URL: Homepage, https://github.com/InzamamulQureshi/Codefetch
10
+ Project-URL: Repository, https://github.com/InzamamulQureshi/Codefetch
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Environment :: Console
14
+ Classifier: Topic :: Utilities
15
+ Requires-Python: >=3.8
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Dynamic: author
19
+ Dynamic: home-page
20
+ Dynamic: license-file
21
+ Dynamic: requires-python
22
+
23
+ # CodeFetch
24
+
25
+ Quickly fetch code files from GitHub repositories with simple commands.
26
+
27
+ CodeFetch is a lightweight command-line utility designed to quickly inspect, preview, and download individual source code files directly from any GitHub repository without needing to clone full repositories.
28
+
29
+ ---
30
+
31
+ ## Features
32
+
33
+ - **Any User & Repository**: Fetch files from any public GitHub repository using intuitive syntax (`codefetch <owner>/<repo> <filename>`).
34
+ - **Terminal Preview**: Inspect code directly in your console with `--show` without saving it to disk.
35
+ - **Automatic Path & Case Resolution**: Automatically resolves case mismatches and finds files nested inside subdirectories.
36
+ - **Repository Discovery**: List all public repositories for any GitHub user with `--repos`.
37
+ - **Tree Exploration**: List all supported code files within a repository with `--list`.
38
+ - **Optional Persistent Defaults**: Save a default repository or user with `--set-default` if you frequently work with the same repository.
39
+ - **Zero Runtime Dependencies**: Built using only the Python standard library with zero third-party dependencies.
40
+
41
+ ---
42
+
43
+ ## Installation
44
+
45
+ ### From PyPI
46
+
47
+ ```bash
48
+ pip install codefetch-cli
49
+ ```
50
+
51
+ ### From GitHub
52
+
53
+ ```bash
54
+ pip install git+https://github.com/InzamamulQureshi/Codefetch.git
55
+ ```
56
+
57
+ ### From Local Source
58
+
59
+ Clone the repository and install locally:
60
+
61
+ ```bash
62
+ git clone https://github.com/InzamamulQureshi/Codefetch.git
63
+ cd Codefetch
64
+ pip install .
65
+ ```
66
+
67
+ ---
68
+
69
+ ## Quick Start & Usage
70
+
71
+ ### 1. Download Files
72
+
73
+ Fetch a single file from any GitHub repository:
74
+
75
+ ```bash
76
+ # Fetch a file from any user and repository
77
+ codefetch owner/repo main.py
78
+
79
+ # Download a configuration or dataset
80
+ codefetch owner/repo data.csv
81
+ codefetch owner/repo config.yaml
82
+
83
+ # Download using explicit flags
84
+ codefetch -u owner -r repo main.py
85
+
86
+ # Save with a custom filename or destination path
87
+ codefetch owner/repo main.py -o custom_name.py
88
+ ```
89
+
90
+ ### 2. Preview in Terminal (Without Downloading)
91
+
92
+ Display the contents of a file directly in stdout with `-s` / `--show`:
93
+
94
+ ```bash
95
+ # Preview file content in terminal
96
+ codefetch -s owner/repo main.py
97
+ codefetch -s torvalds/linux Makefile
98
+ ```
99
+
100
+ ### 3. Explore Repositories and Files
101
+
102
+ ```bash
103
+ # List all code files in a repository
104
+ codefetch -l owner/repo
105
+ codefetch --list owner/repo
106
+
107
+ # List all public repositories for any GitHub user
108
+ codefetch -R -u username
109
+ codefetch --repos username
110
+ ```
111
+
112
+ ### 4. Configuration and Defaults (Optional)
113
+
114
+ By default, CodeFetch has no preset repository or user. If you frequently fetch files from the same repository, you can optionally configure defaults:
115
+
116
+ ```bash
117
+ # Set a default repository (saves both user and repo)
118
+ codefetch --set-default owner/repo
119
+
120
+ # Now you can fetch files directly without typing the repo name!
121
+ codefetch main.py
122
+ codefetch -l
123
+
124
+ # View current saved configuration
125
+ codefetch --config
126
+
127
+ # Reset all configuration back to defaults (no default repository)
128
+ codefetch --reset-config
129
+ ```
130
+
131
+ ---
132
+
133
+ ## Command Reference
134
+
135
+ | Flag | Description | Example |
136
+ |---|---|---|
137
+ | `-s`, `--show` | Print file contents to terminal | `codefetch -s owner/repo main.py` |
138
+ | `-o`, `--output` | Specify destination output filename | `codefetch owner/repo main.py -o script.py` |
139
+ | `-l`, `--list` | List available code files in a repository | `codefetch -l owner/repo` |
140
+ | `-R`, `--repos` | List public repositories for a user | `codefetch -R -u username` |
141
+ | `-r`, `--repo` | Specify repository name or URL | `codefetch -r repo main.py` |
142
+ | `-u`, `--user` | Specify GitHub username or organization | `codefetch -u username -r repo main.py` |
143
+ | `-b`, `--branch` | Branch name (default: `main`) | `codefetch -b master owner/repo Makefile` |
144
+ | `--set-default` | Set persistent default repository | `codefetch --set-default owner/repo` |
145
+ | `--set-default-user` | Set persistent default user | `codefetch --set-default-user username` |
146
+ | `--config` | Display active configuration | `codefetch --config` |
147
+ | `--reset-config` | Reset configuration back to defaults | `codefetch --reset-config` |
148
+ | `-v`, `--version` | Display version information | `codefetch --version` |
149
+ | `-h`, `--help` | Display help and usage message | `codefetch --help` |
150
+
151
+ ---
152
+
153
+ ## Supported File Extensions
154
+
155
+ CodeFetch recognizes and lists common source and document files:
156
+
157
+ - **Data & Tables**: `.csv`, `.tsv`, `.json`, `.jsonl`, `.yaml`, `.yml`, `.toml`, `.xml`, `.ini`, `.cfg`, `.conf`, `.env`
158
+ - **Data Science**: `.ipynb`, `.py`, `.r`, `.rmd`, `.m`
159
+ - **Languages**: `.c`, `.cpp`, `.h`, `.hpp`, `.rs`, `.go`, `.java`, `.kt`, `.cs`, `.swift`, `.dart`, `.php`
160
+ - **Web**: `.html`, `.css`, `.scss`, `.js`, `.jsx`, `.ts`, `.tsx`, `.vue`, `.svelte`
161
+ - **Scripts & Systems**: `.sh`, `.bash`, `.zsh`, `.fish`, `.bat`, `.cmd`, `.ps1`, `.lua`, `.rb`, `.asm`, `.s`, `.hex`
162
+ - **Database & Schemas**: `.sql`, `.graphql`, `.gql`, `.proto`
163
+ - **Documentation**: `.md`, `.markdown`, `.rst`, `.txt`, `.tex`, `.log`
164
+ - **Build Files**: `Dockerfile`, `Makefile`, `CMakeLists.txt`, `Gemfile`, `Procfile`
165
+
166
+ ---
167
+
168
+ ## License
169
+
170
+ This project is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,8 @@
1
+ codefetch/__init__.py,sha256=OgTOFFfQIh-gT-X8j2hheukYFmfAe0SvzIuA_LosY6Y,98
2
+ codefetch/cli.py,sha256=muL99Mr9tCPZ0UJp3YfVcVGMxTLvCPGfEbOmH-GpNCU,23588
3
+ codefetch_cli-1.2.2.dist-info/licenses/LICENSE,sha256=hqEPPm8jxPava5BfKIj3wTIXNyWNwsIvPv2daPCOijY,1094
4
+ codefetch_cli-1.2.2.dist-info/METADATA,sha256=pOL04v-tCvJap5vLYlCE9bDXBv768lm-LR5gghvyzlc,6000
5
+ codefetch_cli-1.2.2.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
6
+ codefetch_cli-1.2.2.dist-info/entry_points.txt,sha256=jFLRsBB_USeSdqjewcXZfnOzY56s0PZat7mnYkYdrXg,49
7
+ codefetch_cli-1.2.2.dist-info/top_level.txt,sha256=kHrftHbyqugb8LQXjW1dR9uI-JFjZQJ0sUReIa45yXQ,10
8
+ codefetch_cli-1.2.2.dist-info/RECORD,,
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Reaver101
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 InzamamulQureshi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,182 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: codefetch-cli
3
- Version: 1.2.0
4
- Summary: Quickly fetch code files from GitHub repositories with simple commands
5
- Home-page: https://github.com/InzamamulQureshi/Codefetch
6
- Author: Inzamamul Qureshi
7
- Author-email: Inzamamul Qureshi <inzamamulqureshi@gmail.com>
8
- License-Expression: MIT
9
- Project-URL: Homepage, https://github.com/InzamamulQureshi/Codefetch
10
- Project-URL: Repository, https://github.com/InzamamulQureshi/Codefetch
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: Operating System :: OS Independent
13
- Classifier: Environment :: Console
14
- Classifier: Topic :: Utilities
15
- Requires-Python: >=3.8
16
- Description-Content-Type: text/markdown
17
- License-File: LICENSE
18
- Dynamic: author
19
- Dynamic: home-page
20
- Dynamic: license-file
21
- Dynamic: requires-python
22
-
23
- # CodeFetch
24
-
25
- Quickly fetch code files from GitHub repositories with simple commands.
26
-
27
- CodeFetch is a lightweight command-line utility designed to quickly inspect, preview, and download individual source code files directly from any GitHub repository without needing to clone full repositories.
28
-
29
- ---
30
-
31
- ## Features
32
-
33
- - **Any User & Repository**: Fetch files from any public GitHub repository using intuitive syntax (`codefetch <user>/<repo> <filename>`).
34
- - **Terminal Preview**: Inspect code directly in your console with `--show` without saving it to disk.
35
- - **Automatic Path & Case Resolution**: Automatically resolves case mismatches (e.g., `exp1.c` -> `EXP1.c`) and finds files nested inside subdirectories.
36
- - **Repository Discovery**: List all public repositories for any GitHub user with `--repos`.
37
- - **Tree Exploration**: List all supported code files within a repository with `--list`.
38
- - **Persistent Defaults**: Configure your preferred default repository and user with `--set-default` and `--set-default-user`.
39
- - **No Dependencies**: Built using the Python standard library with zero third-party runtime dependencies.
40
-
41
- ---
42
-
43
- ## Installation
44
-
45
- ### From PyPI
46
-
47
- ```bash
48
- pip install codefetch-cli
49
- ```
50
-
51
- ### From GitHub
52
-
53
- ```bash
54
- pip install git+https://github.com/InzamamulQureshi/Codefetch.git
55
- ```
56
-
57
- ### From Local Source
58
-
59
- Clone the repository and install locally:
60
-
61
- ```bash
62
- git clone https://github.com/InzamamulQureshi/Codefetch.git
63
- cd Codefetch
64
- pip install .
65
- ```
66
-
67
- ---
68
-
69
- ## Quick Start & Usage
70
-
71
- ### 1. Download Files
72
-
73
- Fetch a file from any GitHub repository:
74
-
75
- ```bash
76
- # Fetch from a specific user and repository
77
- codefetch InzamamulQureshi/Codefetch setup.py
78
-
79
- # Fetch using explicit flags
80
- codefetch -u InzamamulQureshi -r Codefetch setup.py
81
-
82
- # Fetch from a repository under the default user
83
- codefetch DS EXP1.c
84
- codefetch -r DS EXP1.c
85
-
86
- # Shorthand path syntax
87
- codefetch DS/EXP1.c
88
-
89
- # Fetch from the default repository
90
- codefetch 8.1.py
91
- ```
92
-
93
- Save to a custom filename or directory using `-o` / `--output`:
94
-
95
- ```bash
96
- codefetch -r DS EXP1.c -o my_experiment.c
97
- ```
98
-
99
- ### 2. Preview in Terminal (Without Downloading)
100
-
101
- Display the contents of a file directly in stdout:
102
-
103
- ```bash
104
- # Preview file from default repository
105
- codefetch --show 8.1.py
106
-
107
- # Preview file from another repository
108
- codefetch --show DS/EXP1.c
109
-
110
- # Preview file from any user repository
111
- codefetch --show InzamamulQureshi/Codefetch setup.py
112
- ```
113
-
114
- ### 3. Explore Repositories and Files
115
-
116
- ```bash
117
- # List all public repositories for default user
118
- codefetch --repos
119
-
120
- # List all public repositories for a specific user
121
- codefetch --repos -u InzamamulQureshi
122
- codefetch --repos torvalds
123
-
124
- # List code files in the default repository
125
- codefetch --list
126
-
127
- # List code files in another repository
128
- codefetch -r DS --list
129
- codefetch --list InzamamulQureshi/Codefetch
130
- ```
131
-
132
- ### 4. Configuration and Defaults
133
-
134
- Set persistent default preferences stored in `~/.codefetch.json`:
135
-
136
- ```bash
137
- # Set default repository
138
- codefetch --set-default DS
139
-
140
- # Set default user
141
- codefetch --set-default-user InzamamulQureshi
142
-
143
- # View current configuration
144
- codefetch --config
145
-
146
- # Reset configuration back to factory defaults
147
- codefetch --reset-config
148
- ```
149
-
150
- ---
151
-
152
- ## Command Reference
153
-
154
- | Flag | Description | Example |
155
- |---|---|---|
156
- | `-r`, `--repo` | Target repository name or URL | `codefetch -r DS EXP1.c` |
157
- | `-u`, `--user` | Target GitHub user or organization | `codefetch -u octocat -r Spoon-Knife --list` |
158
- | `-b`, `--branch` | Branch name (default: `main`) | `codefetch -b main DS EXP1.c` |
159
- | `-s`, `--show` | Print file contents to terminal | `codefetch --show 8.1.py` |
160
- | `-l`, `--list` | List available code files | `codefetch --list DS` |
161
- | `-R`, `--repos` | List public repositories for user | `codefetch --repos -u InzamamulQureshi` |
162
- | `-o`, `--output` | Specify destination output filename | `codefetch -r DS EXP1.c -o local.c` |
163
- | `--set-default` | Set persistent default repository | `codefetch --set-default DS` |
164
- | `--set-default-user` | Set persistent default user | `codefetch --set-default-user InzamamulQureshi` |
165
- | `--config` | Display active configuration | `codefetch --config` |
166
- | `--reset-config` | Reset configuration to defaults | `codefetch --reset-config` |
167
- | `-v`, `--version` | Display version information | `codefetch --version` |
168
- | `-h`, `--help` | Display help and usage message | `codefetch --help` |
169
-
170
- ---
171
-
172
- ## Supported File Extensions
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`
177
-
178
- ---
179
-
180
- ## License
181
-
182
- This project is licensed under the [MIT License](LICENSE).
@@ -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,,