[BUG] 在使用`ps1`脚本运行开发工具时,部分参数不会正确传递
相关参数
开发工具版本: 2024.08.04.2345
命令:
ffdev 代码行数 --dir "D:\***\Fufu_Tools.v1.3.3-lite" --ignore-empty-lines --ignore-comments --show-ignored-lines --ignore-files LICENSE,Check_INFO.bat,Check_INFO_save.bat --ignore-folders "环境配置" --formats cpp,cxx,py,pyw,js,html,css,java,bat
参数:
--dir "D:\***\Fufu_Tools.v1.3.3-lite" --ignore-empty-lines --ignore-comments --show-ignored-lines --ignore-files LICENSE,Check_INFO.bat,Check_INFO_save.bat --ignore-folders "环境配置" --formats cpp,cxx,py,pyw,js,html,css,java,bat
情况分析
使用ffdev (ps1脚本) 时,出现未知错误:
✕ 文件 D:\***\Fufu_Tools.v1.3.3-lite\ico.ico 出现未知错误: 'utf-8' codec can't decode byte 0x89 in position 22: invalid start byte
Traceback (most recent call last):
File "D:\***\Fufu_Tools\Tools\***\开发工具\统计\代码总行数.py", line 96, in <module>
total_lines += lines
TypeError: unsupported operand type(s) for +=: 'int' and 'tuple'
[!NOTE] 按理来说,出现错误的文件应该已经被
--formats cpp,cxx,py,pyw,js,html,css,java,bat参数忽略,可是仍被处理。
尝试解决
- 对所有参数添加
""
[Powered by 虚空终端] PS D:\***\Fufu_Tools> ffdev 代码行数 --dir "D:\***\Fufu_Tools.v1.3.3-lite" --ignore-empty-lines --ignore-comments --show-ignored-lines --ignore-files "LICENSE,Check_INFO.bat,Check_INFO_save.bat" --ignore-folders "环境配置" --formats "cpp,cxx,py,pyw,js,html,css,java,bat"
✕ 文件 D:\***\Fufu_Tools.v1.3.3-lite\ico.ico 出现未知错误: 'utf-8' codec can't decode byte 0x89 in position 22: invalid start byte
Traceback (most recent call last):
File "D:\***\Fufu_Tools\Tools\开发工具\***\统计\代码总行数.py", line 96, in <module>
total_lines += lines
TypeError: unsupported operand type(s) for +=: 'int' and 'tuple'
得到相同结果。
- 对列表添加
[]
[Powered by 虚空终端] PS D:\***\Fufu_Tools> ffdev 代码行数 --dir "D:\***\Fufu_Tools.v1.3.3-lite" --ignore-empty-lines --ignore-comments --show-ignored-lines --ignore-files [LICENSE,Check_INFO.bat,Check_INFO_save.bat] --ignore-folders "环境配置" --formats [cpp,cxx,py,pyw,js,html,css,java,bat]
✕ 文件 D:\***\Fufu_Tools.v1.3.3-lite\ico.ico 出现未知错误: 'utf-8' codec can't decode byte 0x89 in position 22: invalid start byte
Traceback (most recent call last):
File "D:\***\Fufu_Tools\Tools\开发工具\***\统计\代码总行数.py", line 96, in <module>
total_lines += lines
TypeError: unsupported operand type(s) for +=: 'int' and 'tuple'
得到同样结果。
- 直接运行
py脚本
[Powered by 虚空终端] PS D:\***\Fufu_Tools> python D:\***\Fufu_Tools\Tools\开发工具\统计\代码总行数.py --dir "D:\***\Fufu_Tools.v1.3.3-lite" --ignore-empty-lines --ignore-comments --show-ignored-lines --ignore-files LICENSE,Check_INFO.bat,Check_INFO_save.bat --ignore-folders "环境配置" --formats cpp,cxx,py,pyw,js,html,css,java,bat
✓ 总代码行数: 4116 行
[!] 总共忽略的空行数: 821 行
[!] 总共忽略的注释行数: 391 行
[!] 总共忽略了: 1212 行
正常运行。
- 使用打包版用的
ffdev的修改版py脚本运行
正常运行。
总结问题
综上,测试未能解决问题,但将问题定位值ps1脚本上。
[!NOTE] 问题定位在
ps1脚本上,且运行命令无误
参数具体导入情况还没测试
- [x] 我将对此进行测试
测试用命令
ffdev 代码行数 --dir "D:\***\Chinese_git" --ignore-empty-lines --ignore-comments --show-ignored-lines --ignore-files LICENSE,Check_INFO.bat,Check_INFO_save.bat --ignore-folders "环境配置" --formats cpp,cxx,py,pyw,js,html,css,java,bat
被传入的参数
Namespace(dir_path='D:\\Duckhome\\CodeDebug\\Chinese_git', ignore_folders=None, ignore_files=None, file_formats=None, ignore_empty_lines=False, ignore_comments=False, show_ignored_lines=False, show_test_info=False, code_file_formats=False)
ps1脚本接受的参数
[Powered by 虚空终端] PS D:\***\Fufu_Tools> ffdev 代码行数 --dir "D:\***\Chinese_git" --ignore-empty-lines --ignore-comments --show-ignored-lines --ignore-files LICENSE,Check_INFO.bat,Check_INFO_save.bat --ignore-folders "环境配置" --formats cpp,cxx,py,pyw,js,html,css,java,bat
代码行数
--dir
D:\Duckhome\CodeDebug\Chinese_git
ps1脚本参数配置存在问题, $inputArgs参数只拿到了一个值,可以尝试一下添加以下行
param(
[string]$program,
[string]$command,
[Parameter(ValueFromRemainingArguments=$true)]
[string[]]$inputArgs
)
参考powershell: about_Functions_Advanced_Parameters的ValueFromRemainingArguments项
另外, 并不是很清楚 $command 参数独立出来的实际意义,ffdev.ps1 脚本看起来就做一个脚本转发的功能,预期后续参数都是子脚本(或者称program)的输入参数
~~$command 独立出来只是为了自己看着顺眼点,打包版中的使用示例也类似(ffdev <工具> <命令> [<参数>...])~~
修改已在独立包中发布:https://github.com/DuckDuckStudio/Fufu_Dev_Tools/releases/tag/2025.01.02.2300