Skip to content

Commit 655c3eb

Browse files
committed
fix(core): 修复参数检查和下载逻辑
- 修复参数检查逻辑错误 - 修复 MIN_FILE_SIZE 和 chunk_size 的类型错误
1 parent caad32f commit 655c3eb

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

fgit.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import argparse
55
import os
66
import json
7-
import threading
7+
from threading import Thread
88
from loguru import logger
99
from urllib.request import urlopen, Request
1010
from urllib.error import HTTPError
@@ -39,6 +39,12 @@
3939
else:
4040
logger.add(sys.stderr, level='INFO', colorize=True, format='{time:HH:mm:ss} | {level} | {message}')
4141

42+
def print_missing_arg():
43+
"""打印缺少参数的提示"""
44+
logger.error(Fore.RED + "❌ 缺少必要参数" + Style.RESET_ALL)
45+
logger.error(' '.join(sys.argv))
46+
logger.error(len(sys.argv) * " " + " ^^")
47+
logger.info(Fore.CYAN + "📖 使用帮助: fgit -h" + Style.RESET_ALL)
4248

4349
def main():
4450
"""主函数"""
@@ -54,11 +60,8 @@ def main():
5460

5561
logger.debug(Fore.CYAN + f"命令参数: {' '.join(sys.argv)}" + Style.RESET_ALL)
5662

57-
if not args.command or len(sys.argv) <= 2:
58-
logger.error(Fore.RED + "❌ 缺少必要参数" + Style.RESET_ALL)
59-
logger.error(' '.join(sys.argv))
60-
logger.error(" ^^")
61-
logger.info(Fore.CYAN + "📖 使用帮助: fgit -h" + Style.RESET_ALL)
63+
if not args.command or len(sys.argv) < 2:
64+
print_missing_arg()
6265
return
6366

6467
# 处理 download 命令
@@ -83,6 +86,10 @@ def main():
8386

8487
def handle_download_zip(args, unknown_args, config, env, verbose):
8588
"""处理下载zip文件命令"""
89+
if unknown_args is None or len(unknown_args) < 1:
90+
print_missing_arg()
91+
return
92+
8693
downloader_config = config.get_downloader_config()
8794
if not downloader_config:
8895
logger.warning(Fore.YELLOW + "🧐 下载配置不存在, 使用默认配置" + Style.RESET_ALL)
@@ -119,6 +126,10 @@ def handle_download_zip(args, unknown_args, config, env, verbose):
119126

120127
def handle_clone(args, unknown_args, config, env, verbose, proxy):
121128
"""处理克隆命令"""
129+
if unknown_args is None or len(unknown_args) < 1:
130+
print_missing_arg()
131+
return
132+
122133
original_url = unknown_args[0]
123134
original_url = normalize_repo_url(original_url)
124135

@@ -284,7 +295,7 @@ def input_with_timeout(prompt, timeout):
284295
"""
285296
logger.info(prompt)
286297
result = []
287-
thread = threading.Thread(target=lambda: result.append(sys.stdin.read(1)))
298+
thread = Thread(target=lambda: result.append(sys.stdin.read(1)))
288299
thread.daemon = True
289300
thread.start()
290301
thread.join(timeout)

utils/downloader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def download_file(url: str, file_path: str, chunk_size: int = 1024, MIN_FILE_SIZ
2323
total_size = int(response.headers.get('content-length', 0))
2424

2525
# 检查文件大小
26-
if MIN_FILE_SIZE > total_size:
26+
if int(MIN_FILE_SIZE) > total_size:
2727
logger.debug(f"镜像源错误: 文件大小小于{MIN_FILE_SIZE}字节")
2828
return False
2929

@@ -32,7 +32,7 @@ def download_file(url: str, file_path: str, chunk_size: int = 1024, MIN_FILE_SIZ
3232
# 下载文件
3333
with open(file_path, 'wb') as f:
3434
with tqdm(total=total_size, unit='B', unit_scale=True, desc="下载文件") as pbar:
35-
for data in response.iter_content(chunk_size=chunk_size):
35+
for data in response.iter_content(chunk_size=int(chunk_size)):
3636
f.write(data)
3737
pbar.update(len(data))
3838

0 commit comments

Comments
 (0)