File tree Expand file tree Collapse file tree 6 files changed +78
-0
lines changed
framework/fit/python/fit_cli Expand file tree Collapse file tree 6 files changed +78
-0
lines changed Original file line number Diff line number Diff line change 1+ from .main import main
2+
3+ if __name__ == "__main__" :
4+ main ()
Original file line number Diff line number Diff line change 1+ from pathlib import Path
2+
3+ TEMPLATE_PLUGIN = '''from fitframework.api.decorators import fitable
4+
5+ @fitable("genericable_id_demo", "fitable_id_demo")
6+ def hello(name: str) -> str:
7+ """一个简单的 FIT 插件示例函数"""
8+ return f"Hello, {name}!"
9+ '''
10+
11+ def run (args ):
12+ """生成插件模板"""
13+ base_dir = "plugin" / Path (args .name )
14+ src_dir = base_dir / "src"
15+
16+ # 创建目录
17+ if not base_dir .exists ():
18+ base_dir .mkdir (parents = True )
19+ print (f"✅ 已创建目录 { base_dir } " )
20+ if not src_dir .exists ():
21+ src_dir .mkdir (parents = True )
22+
23+ # __init__.py
24+ init_file = src_dir / "__init__.py"
25+ if not init_file .exists ():
26+ init_file .touch ()
27+ else :
28+ print (f"⚠️ 文件 { init_file } 已存在,未覆盖。" )
29+
30+ # plugin.py
31+ plugin_file = src_dir / "plugin.py"
32+ if not plugin_file .exists ():
33+ plugin_file .write_text (TEMPLATE_PLUGIN , encoding = "utf-8" )
34+ else :
35+ print (f"⚠️ 文件 { plugin_file } 已存在,未覆盖。" )
Original file line number Diff line number Diff line change 1+ import argparse
2+ from fit_cli .commands import init_cmd
3+
4+ # , build_cmd, package_cmd)
5+
6+
7+ def main ():
8+ parser = argparse .ArgumentParser (description = "FIT Framework CLI 插件开发工具" )
9+ subparsers = parser .add_subparsers (dest = "command" )
10+
11+ # init
12+ parser_init = subparsers .add_parser ("init" , help = "生成插件模板" )
13+ parser_init .add_argument ("name" , help = "插件目录名称" )
14+ parser_init .set_defaults (func = init_cmd .run )
15+
16+ args = parser .parse_args ()
17+
18+ if hasattr (args , "func" ):
19+ args .func (args )
20+ else :
21+ parser .print_help ()
22+
23+
24+ if __name__ == "__main__" :
25+ main ()
Original file line number Diff line number Diff line change 1+ # FIT CLI 工具
2+
3+ FIT CLI 工具是基于 ** FIT Framework** 的命令行开发工具,提供插件初始化、打包等功能,帮助用户快速开发和管理 FIT 插件。
4+
5+ ---
6+
7+ ## 使用方式
8+
9+ 以framework/fit/python为项目根目录,运行:
10+
11+ ``` bash
12+ python -m fit_cli init your_plugin_name
13+ ```
14+ 将会在plugin目录中创建your_plugin_name目录,并生成插件模板。
You can’t perform that action at this time.
0 commit comments