CLI 템플릿 시스템
Caffeine CLI의 템플릿 시스템 상세 가이드입니다.
📋 개요
Caffeine CLI는 Embedded Resource로 템플릿을 관리하며, 프로젝트 생성 시 변수를 치환합니다.
🎨 템플릿 종류
1. driver (기본 드라이버)
생성 파일:
MyDriver/
├── MyDriver.csproj
├── MyDriver.cs
└── README.md
사용 시나리오:
- 간단한 프로토콜 드라이버
- 빠른 프로토타이핑
- 테스트 불필요한 경우
생성 명령:
cafe init --name MyDriver --template driver
2. driver-full (전체 드라이버)
생성 파일:
MyDriver/
├── src/
│ ├── MyDriver.csproj
│ └── MyDriver.cs
└── tests/
├── MyDriver.Tests.csproj
└── MyDriverTests.cs
사용 시나리오:
- 프로덕션 품질 드라이버
- TDD (Test-Driven Development)
- CI/CD 파이프라인
생성 명령:
cafe init --name MyDriver --template driver-full --git
3. app (클라이언트 앱)
생성 파일:
MyApp/
├── MyApp.csproj
├── Program.cs
└── README.md
사용 시나리오:
- Caffeine 클라이언트 애플리케이션
- 데이터 수집 앱
- 모니터링 도구
생성 명령:
cafe init --name MyApp --template app
4. solution (솔루션)
생성 파일:
MySolution/
└── .gitignore
사용 시나리오:
- 여러 프로젝트 관리
- 대규모 솔루션
생성 명령:
cafe init --name MySolution --template solution
🔧 템플릿 변수
모든 템플릿 파일(.template)에서 사용 가능한 변수:
| 변수 | 설명 | 예시 입력 | 예시 출력 |
|---|---|---|---|
{{ProjectName}} | 사용자가 입력한 프로젝트 이름 | ModbusDriver | ModbusDriver |
{{Namespace}} | C# 네임스페이스 (하이픈/공백 → 밑줄) | Modbus-Driver | Modbus_Driver |
{{ClassName}} | C# 클래스명 (하이픈/공백 제거) | Modbus Driver | ModbusDriver |
{{Year}} | 현재 연도 | - | 2026 |
{{Month}} | 현재 월 (2자리) | - | 01 |
{{Day}} | 현재 일 (2자리) | - | 28 |
{{Author}} | 시스템 사용자명 | - | matrix |
📁 템플릿 구조
driver 템플릿 파일
Templates/driver/
├── Driver.csproj.template
├── DriverService.cs.template
└── README.md.template
파일 변환 규칙:
Driver.csproj.template→{ProjectName}.csprojDriverService.cs.template→{ProjectName}.csREADME.md.template→README.md
driver-full 템플릿 파일
Templates/driver-full/
├── src/
│ ├── Driver.csproj.template
│ └── DriverService.cs.template
└── tests/
├── DriverTests.csproj.template
└── DriverServiceTests.cs.template
디렉토리 구조: src/, tests/ 디렉토리가 그대로 생성됩니다.
💡 템플릿 예시
Driver.csproj.template
템플릿 파일:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<RootNamespace>{{Namespace}}</RootNamespace>
<Authors>{{Author}}</Authors>
<Company>NEXCODE</Company>
<Product>{{ProjectName}}</Product>
<Copyright>Copyright © {{Year}}</Copyright>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NEXCODE.Caffeine.Core" Version="2.0.*" />
</ItemGroup>
</Project>
치환 후 (프로젝트명: ModbusDriver):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<RootNamespace>ModbusDriver</RootNamespace>
<Authors>matrix</Authors>
<Company>NEXCODE</Company>
<Product>ModbusDriver</Product>
<Copyright>Copyright © 2026</Copyright>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NEXCODE.Caffeine.Core" Version="2.0.*" />
</ItemGroup>
</Project>
DriverService.cs.template
템플릿 파일:
using Caffeine.Core.Abstractions;
using Caffeine.Core.Models;
using Microsoft.Extensions.Logging;
namespace {{Namespace}};
/// <summary>
/// {{ProjectName}} - generated on {{Year}}-{{Month}}-{{Day}}
/// </summary>
public class {{ClassName}} : IDriver
{
private readonly ILogger<{{ClassName}}> _logger;
public {{ClassName}}(ILogger<{{ClassName}}> logger)
{
_logger = logger;
}
public Task<bool> ConnectAsync(CancellationToken cancellationToken = default)
{
_logger.LogInformation("Connecting to equipment...");
// TODO: Implement connection logic
return Task.FromResult(true);
}
public Task DisconnectAsync()
{
_logger.LogInformation("Disconnecting...");
// TODO: Implement disconnection logic
return Task.CompletedTask;
}
public Task<TagValue?> ReadTagAsync(string tagName, CancellationToken cancellationToken = default)
{
// TODO: Implement tag reading
return Task.FromResult<TagValue?>(null);
}
public Task<bool> WriteTagAsync(string tagName, object value, CancellationToken cancellationToken = default)
{
// TODO: Implement tag writing
return Task.FromResult(false);
}
}
치환 후 (프로젝트명: ModbusDriver, 날짜: 2026-01-28):
using Caffeine.Core.Abstractions;
using Caffeine.Core.Models;
using Microsoft.Extensions.Logging;
namespace ModbusDriver;
/// <summary>
/// ModbusDriver - generated on 2026-01-28
/// </summary>
public class ModbusDriver : IDriver
{
private readonly ILogger<ModbusDriver> _logger;
public ModbusDriver(ILogger<ModbusDriver> logger)
{
_logger = logger;
}
public Task<bool> ConnectAsync(CancellationToken cancellationToken = default)
{
_logger.LogInformation("Connecting to equipment...");
// TODO: Implement connection logic
return Task.FromResult(true);
}
public Task DisconnectAsync()
{
_logger.LogInformation("Disconnecting...");
// TODO: Implement disconnection logic
return Task.CompletedTask;
}
public Task<TagValue?> ReadTagAsync(string tagName, CancellationToken cancellationToken = default)
{
// TODO: Implement tag reading
return Task.FromResult<TagValue?>(null);
}
public Task<bool> WriteTagAsync(string tagName, object value, CancellationToken cancellationToken = default)
{
// TODO: Implement tag writing
return Task.FromResult(false);
}
}
🎯 커스텀 템플릿 추가
1. 템플릿 디렉토리 생성
cd src/Caffeine.Cli
mkdir -p Templates/my-custom-template
2. 템플릿 파일 작성
변수 {{ProjectName}}, {{Namespace}} 등을 사용하여 .template 파일 작성
3. csproj에 리소스 추가
<ItemGroup>
<EmbeddedResource Include="Templates\my-custom-template\**\*.template" />
</ItemGroup>
4. CLI 재빌드
dotnet build
5. 사용
cafe init --name MyProject --template my-custom-template
🔍 고급 사용
조건부 템플릿
향후 지원 예정:
#if DEBUG
// Development code
#else
// Production code
#endif
외부 템플릿 URL
향후 지원 예정:
cafe init --name MyProject --template https://github.com/user/template.git
📚 참고 자료
- CLI Commands - 전체 명령어 가이드
- Troubleshooting - 문제 해결
- 첫 번째 드라이버 만들기 - 튜토리얼
작성일: 2026-01-28
버전: 2.0