Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,21 @@ git clone https://github.com/CodeCrafter-TL/python-cmd.git
#### 安装必需包
在 clone 之后的工作目录中执行如下命令:
```bash
pip3 install -r requirements.txt
pip install -r requirements.txt
```
如果安装较慢,可以使用如下命令切换为阿里云镜像:
```bash
pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
```
等待安装完成后,使用如下命令即可开始使用 Python cmd:
```bash
python3 main.py
python main.py
```

#### 日志说明
日志存放位于`C:\users\你的用户名\.pcmd`下
#### Warning!
- 无法自定义日志位置
- cd 有部分问题 例子:
```bash
cd c:\
unterminated string literal (detected at line 1); perhaps you escaped the end quote? (<string>, line 1)
```
请使用
```bash
cd c:\\
```

### 文件说明

Expand Down
33 changes: 18 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,28 +117,32 @@ def __init__(self, parent=None):

def process_command(self, line_text):
try:
result: list | tuple = line_text.split(' ')
command: str = result[0]
args: list | tuple = result[1:]
result = line_text.split(' ')
command = result[0]
args = result[1:]

if command in self.COMMANDS:
method_name = self.COMMANDS[command]
if method_name == "exit":
sys.exit()
else:
try:
processed_args = []
for arg in args:
processed_args.append(f'"{str(arg)}"')
eval(f"self.{method_name}({ \
', '.join(processed_args)})")
except NameError as e:
method = getattr(self, method_name)
# 直接传递参数列表,无需字符串处理
method(*args)
except AttributeError:
self.error([CMD_NOT_FOUND, COLON, command])
except TypeError as e:
if re.search(r'takes \d+ positional argument', str(e)):
self.error([command, COLON, LARGE_ARG])
elif re.search(r'missing \d+ required positional argument', str(e)):
self.error([command, COLON, MISS_ARG])
error_msg = str(e)
if "positional argument" in error_msg:
if "missing" in error_msg:
self.error([command, COLON, MISS_ARG])
elif "takes" in error_msg:
self.error([command, COLON, LARGE_ARG])
else:
self.error([str(e)])
except Exception as e:
self.error([str(e)])
elif self.in_path(command):
if os.name == 'nt':
executable = 'cmd'
Expand Down Expand Up @@ -251,8 +255,7 @@ def help(self):
ls: 列出目录下的文件和目录 - ls
= dir
help: 查看本消息 - help
日志保存位置在{self.home_directory}\.pcmd\下
"""
日志保存位置在{self.home_directory}""" + r"""\.pcmd\下"""
self.print(info)

def cd(self, dir_name='.'):
Expand Down