服務(wù)好 售后好的網(wǎng)站建設(shè)自己制作手機(jī)網(wǎng)站
鶴壁市浩天電氣有限公司
2026/01/24 08:47:11
服務(wù)好 售后好的網(wǎng)站建設(shè),自己制作手機(jī)網(wǎng)站,wordpress php 5.5,網(wǎng)頁制作設(shè)計框架Boilerplates CLI
Boilerplates 是一個用于管理基礎(chǔ)設(shè)施模板#xff08;boilerplates#xff09;的復(fù)雜集合#xff0c;并配備了一個Python CLI工具。它支持Terraform、Docker、Ansible、Kubernetes等多種技術(shù)#xff0c;幫助您快速生成、定制和部署配置模板。
功能特性
多…Boilerplates CLIBoilerplates是一個用于管理基礎(chǔ)設(shè)施模板boilerplates的復(fù)雜集合并配備了一個Python CLI工具。它支持Terraform、Docker、Ansible、Kubernetes等多種技術(shù)幫助您快速生成、定制和部署配置模板。功能特性多技術(shù)模板支持提供Docker Compose、Terraform、Ansible、Kubernetes、Packer等基礎(chǔ)設(shè)施模板。交互式變量收集通過交互式CLI提示引導(dǎo)用戶為模板變量輸入值。智能默認(rèn)值管理支持保存常用變量的默認(rèn)值并在多個項目中復(fù)用。Git倉庫集成模板庫基于Git管理支持添加、更新和移除自定義模板倉庫。Jinja2模板渲染使用Jinja2引擎渲染模板支持條件語句和變量替換。模塊化架構(gòu)通過模塊系統(tǒng)Module組織不同技術(shù)的模板和命令。配置文件管理提供配置管理功能存儲用戶默認(rèn)值和偏好設(shè)置。安全與驗證包含模板語法驗證、變量類型檢查和路徑安全防護(hù)。安裝指南使用安裝腳本推薦通過自動化安裝腳本安裝Boilerplates CLI# 安裝最新版本curl-fsSL https://raw.githubusercontent.com/christianlempa/boilerplates/main/scripts/install.sh|bash# 安裝特定版本curl-fsSL https://raw.githubusercontent.com/christianlempa/boilerplates/main/scripts/install.sh|bash-s -- --version v1.2.3安裝腳本使用pipx為CLI工具創(chuàng)建一個隔離環(huán)境。安裝完成后終端中即可使用boilerplates命令。依賴要求Python 3Git用于模板庫管理pipx用于隔離安裝安裝腳本會自動檢查使用說明基礎(chǔ)命令# 查看幫助信息boilerplates --help# 查看版本boilerplates --version# 更新模板庫boilerplates repo update# 列出所有已配置的庫boilerplates repo list模板操作# 列出所有可用的Docker Compose模板boilerplates compose list# 查看特定模板的詳細(xì)信息boilerplates compose show nginx# 生成模板交互式模式boilerplates compose generate authentik# 生成模板到自定義輸出目錄boilerplates compose generate nginx my-nginx-server# 非交互式模式直接指定變量值boilerplates compose generate traefik my-proxy--varservice_nametraefik--vartraefik_enabledtrue--vartraefik_hostproxy.example.com--no-interactive管理默認(rèn)值# 設(shè)置變量的默認(rèn)值boilerplates compose defaultssetcontainer_timezoneAmerica/New_Yorkboilerplates compose defaultssetrestart_policyunless-stopped模板庫管理# 添加自定義模板庫boilerplates repoaddmy-templates https://github.com/user/templates--directory library--branch main# 移除模板庫boilerplates repo remove my-templates核心代碼CLI主入口 (cli/__main__.py)#!/usr/bin/env python3 Main entry point for the Boilerplates CLI application. This file serves as the primary executable when running the CLI. from__future__importannotationsimportimportlibimportloggingimportpkgutilimportsysfrompathlibimportPathfromtypingimportOptionalfromtyperimportTyper,Context,Optionfromrich.consoleimportConsoleimportcli.modulesfromcli.core.registryimportregistryfromcli.coreimportrepo# Using standard Python exceptions instead of custom ones# NOTE: Placeholder version - will be overwritten by release script (.github/workflows/release.yaml)__version__0.0.0appTyper(helpCLI tool for managing infrastructure boilerplates.
[dim]Easily generate, customize, and deploy templates for Docker Compose, Terraform, Kubernetes, and more.
[white]Made with by [bold]Christian Lempa[/bold],add_completionTrue,rich_markup_moderich,)consoleConsole()defsetup_logging(log_level:strWARNING)-None:Configure the logging system with the specified log level. Args: log_level: The logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) Raises: ValueError: If the log level is invalid RuntimeError: If logging configuration fails numeric_levelgetattr(logging,log_level.upper(),None)ifnotisinstance(numeric_level,int):raiseValueError(fInvalid log level {log_level}. Valid levels: DEBUG, INFO, WARNING, ERROR, CRITICAL)try:logging.basicConfig(levelnumeric_level,format%(asctime)s - %(name)s - %(levelname)s - %(message)s,datefmt%Y-%m-%d %H:%M:%S)loggerlogging.getLogger(__name__)logger.setLevel(numeric_level)exceptExceptionase:raiseRuntimeError(fFailed to configure logging:{e})app.callback(invoke_without_commandTrue)defmain(version:Optional[bool]Option(None,--version,-v,helpShow the application version and exit,),log_level:strOption(WARNING,--log-level,-l,helpSet the logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL),),ctx:ContextNone,)-None:Main entry point for the boilerplates CLI. Args: version: Show version information log_level: Logging level for the application ctx: Typer context object ifversion:console.print(fBoilerplates CLI [bold]v{__version__}[/bold])raiseSystemExit(0)try:setup_logging(log_level)except(ValueError,RuntimeError)ase:console_err.print(f[red]Failed to set up logging:{e}[/red])sys.exit(1)# Discover and register modules_discover_modules()# Register repository management commandsapp.add_typer(repo.app,namerepo)ifctx.invoked_subcommandisNone:console.print(app.info.help)raiseSystemExit(0)def_discover_modules()-None:Dynamically discover and register all modules in the modules package.try:for_,name,_inpkgutil.iter_modules(cli.modules.__path__):module_pathfcli.modules.{name}try:importlib.import_module(module_path)logger.debug(fSuccessfully imported module:{name})exceptExceptionase:logger.warning(fFailed to import module {name}:{e})continuelogger.info(fModule discovery completed. Total modules:{len(list(registry.iter_module_classes()))})exceptExceptionase:logger.error(fModule discovery failed:{e})raiseif__name____main__:app()變量集合管理 (cli/core/collection.py)from__future__importannotationsfromcollectionsimportdefaultdictfromtypingimportAny,Dict,List,Optional,Set,Unionimportloggingfrom.variableimportVariablefrom.sectionimportVariableSection loggerlogging.getLogger(__name__)classVariableCollection:Manages variables grouped by sections and builds Jinja context.def__init__(self,spec:dict[str,Any])-None:Initialize VariableCollection from a specification dictionary. Args: spec: Dictionary containing the complete variable specification structure Expected format (as used in compose.py): { section_key: { title: Section Title, prompt: Optional prompt text, toggle: optional_toggle_var_name, description: Optional description, vars: { var_name: { description: Variable description, type: str, default: default_value, ... } } } } ifnotisinstance(spec,dict):raiseValueError(Spec must be a dictionary)self._sections:Dict[str,VariableSection]{}# NOTE: The _variable_map provides a flat, O(1) lookup for any variable by its name,# avoiding the need to iterate through sections. It stores references to the same# Variable objects contained in the _set structure.self._variable_map:Dict[str,Variable]{}self._initialize_sections(spec)# Validate dependencies after all sections are loadedself._validate_dependencies()def_initialize_sections(self,spec:dict[str,Any])-None:Initialize sections from the spec.forsection_key,section_datainspec.items():ifnotisinstance(section_data,dict):continue# Create VariableSectionsection_dict{key:section_key,title:section_data.get(title,section_key.title()),description:section_data.get(description),toggle:section_data.get(toggle),required:section_data.get(required,section_keygeneral),}# Handle dependenciesifneeds:section_data.get(needs):section_dict[needs]needs sectionVariableSection(section_dict)# Add variables to sectionifvarsinsection_dataandisinstance(section_data[vars],dict):forvar_name,var_datainsection_data[vars].items():ifnotisinstance(var_data,dict):continue# Create Variablevar_dictvar_data.copy()var_dict[name]var_name var_dict[origin]templatevariableVariable(var_dict)# Store in section and flat mapsection.variables[var_name]variable self._variable_map[var_name]variable self._sections[section_key]sectiondef_validate_dependencies(self)-None:Validate that all section dependencies exist.forsection_key,sectioninself._sections.items():fordepinsection.needs:ifdepnotinself._sections:logger.warning(fSection {section_key} depends on non-existent section {dep})defget_section(self,section_key:str)-Optional[VariableSection]:Get a section by its key.returnself._sections.get(section_key)defget_sections(self)-Dict[str,VariableSection]:Get all sections.returnself._sections.copy()defis_section_satisfied(self,section_key:str)-bool:Check if a sections dependencies are satisfied.sectionself._sections.get(section_key)ifnotsection:returnFalse# General section is always satisfiedifsection_keygeneral:returnTrue# Check all dependenciesfordepinsection.needs:dep_sectionself._sections.get(dep)ifnotdep_sectionornotdep_section.is_enabled():returnFalsereturnTruedefget_jinja_context(self)-Dict[str,Any]:Build Jinja2 template contextfromallvariables.Returns:Dictionary mapping variable names to their valuesfor更多精彩內(nèi)容 請關(guān)注我的個人公眾號 公眾號辦公AI智能小助手 對網(wǎng)絡(luò)安全、黑客技術(shù)感興趣的朋友可以關(guān)注我的安全公眾號網(wǎng)絡(luò)安全技術(shù)點滴分享