index
+```
+
+例:
+
+```bash
+draft adr index
+```
+
+出力ディレクトリに全ドキュメントの一覧表を含む `README.md` を生成します。
+
+## 設定
+
+`.draft/config.json`:
+
+```json
+{
+ "templates_dir": ".draft/templates",
+ "output_dir": "docs",
+ "filename_format": "{{@id}}-{{@title}}.md"
+}
+```
+
+| キー | 説明 | デフォルト |
+|-----|-------------|---------|
+| `templates_dir` | テンプレートファイルのディレクトリ | `.draft/templates` |
+| `output_dir` | 生成ファイルの出力ディレクトリ | `docs` |
+| `filename_format` | 出力ファイル名のパターン | `{{@title}}.md` |
+| `templates` | テンプレートごとの設定オーバーライド | `null` |
+
+### テンプレートごとの設定
+
+特定のテンプレートに対して `output_dir` と `filename_format` をオーバーライドできます:
+
+```json
+{
+ "templates_dir": ".draft/templates",
+ "output_dir": "docs",
+ "filename_format": "{{@title}}.md",
+ "templates": {
+ "adr": {
+ "output_dir": "docs/adrs",
+ "filename_format": "{{@id{4}}}-{{@title}}.md"
+ },
+ "design": {
+ "output_dir": "docs/design",
+ "filename_format": "{{@date}}-{{@title}}.md"
+ }
+ }
+}
+```
+
+この設定では:
+- `draft adr "My ADR"` → `docs/adrs/0001-My ADR.md` を作成
+- `draft design "My Design"` → `docs/design/2024-01-01-My Design.md` を作成
+- 他のテンプレートはグローバルの `output_dir` と `filename_format` を使用
+
+## テンプレート変数
+
+| 変数 | 説明 |
+|----------|-------------|
+| `{{@title}}` | 引数で指定したタイトル |
+| `{{@today}}` | 今日の日付 (YYYY-MM-DD) |
+| `{{@date}}` | 今日の日付 (YYYY-MM-DD) |
+| `{{@name}}` | 現在のユーザー名 |
+| `{{@id}}` | 自動採番ID (001, 002, ...) |
+| `{{@id{N}}}` | N桁の自動採番ID (例: `{{@id{4}}}` -> 0001) |
+
+## インデックス変数
+
+| 変数 | 説明 |
+|----------|-------------|
+| `{{@index}}` | ドキュメント一覧表 (デフォルト列: Title, Date, Author) |
+| `{{@index{@id\|@title\|@status}}}` | 指定した列でカスタム形式の表 |
+| `{{@index{@id\|@title,asc:@id}}}` | ソート指定付きのカスタム形式 |
+| `{{@index{@id\|@title\|@date,desc:@date}}}` | 日付降順でソート |
+
+利用可能な列: `@id`, `@title`, `@date`, `@name`, `@status`
+
+### インデックスのソート
+
+列指定の後に `,asc:@field` または `,desc:@field` 構文でソート順を指定できます。
+
+**デフォルトのソート動作** (ソート指定がない場合):
+- ドキュメントに `@id` がある場合: `@id` の昇順
+- ドキュメントに `@date` がある場合: `@date` の降順
+- それ以外: ファイル更新日時の降順
+
+**例:**
+```markdown
+{{@index{@id|@title|@author,asc:@id}}}
+{{@index{@title|@date,desc:@date}}}
+```
+
+## カスタムテンプレート
+
+`.draft/templates/` に独自のテンプレートを作成:
+
+**`.draft/templates/rfc.md`**:
+```markdown
+# {{@title}}
+
+- ID: {{@id{4}}}
+- Date: {{@date}}
+- Author: {{@name}}
+- Status: Draft
+
+## Summary
+
+## Motivation
+
+## Detailed Design
+
+## Alternatives
+
+## Unresolved Questions
+```
+
+**`.draft/templates/rfc-index.md`**:
+```markdown
+# RFC Index
+
+{{@index{@id|@title|@status}}}
+```
+
+使用方法:
+```bash
+draft rfc "My RFC Title"
+draft rfc index
+```
+
+## 開発
+
+```bash
+# テスト実行
+zig build test
+
+# ビルド
+zig build
+
+# 実行
+zig build run -- help
+```
+
+## Author
+
+[linyows](https://github.com/linyows)
diff --git a/README.md b/README.md
index a3eddad..cc33b6a 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,14 @@
-# Draft
+English | 日本語
-A markdown template generator.
+
+
+
+
+
+ Markdown template generator
+
+
+
diff --git a/build.zig b/build.zig
index c4957bc..8a7ea27 100644
--- a/build.zig
+++ b/build.zig
@@ -1,9 +1,13 @@
const std = @import("std");
+const build_zon = @import("build.zig.zon");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
+ const options = b.addOptions();
+ options.addOption([]const u8, "version", build_zon.version);
+
const exe = b.addExecutable(.{
.name = "draft",
.root_module = b.createModule(.{
@@ -13,6 +17,8 @@ pub fn build(b: *std.Build) void {
}),
});
+ exe.root_module.addOptions("build_options", options);
+
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
diff --git a/build.zig.zon b/build.zig.zon
index bf0faa1..7936118 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -1,6 +1,7 @@
.{
.name = .draft,
- .version = "0.1.0",
+ // This version is replaced with the git tag during release workflow
+ .version = "0.0.0-dev",
.fingerprint = 0x467c969413062c0c,
.minimum_zig_version = "0.15.2",
.paths = .{
diff --git a/misc/draft.svg b/misc/draft.svg
new file mode 100644
index 0000000..3ebdb63
--- /dev/null
+++ b/misc/draft.svg
@@ -0,0 +1,17 @@
+
+
+
diff --git a/src/assets/usage.txt b/src/assets/usage.txt
new file mode 100644
index 0000000..8f03979
--- /dev/null
+++ b/src/assets/usage.txt
@@ -0,0 +1,42 @@
+
+ _
+ | | |
+ __| ,_ __, | |_|_
+ / | | | / | |/ |
+ \_/|_/ |_/\_/|_/|__/|_/
+ |\
+ |/
+
+Markdown template generator
+
+Usage:
+ draft init Initialize .draft directory with config and templates
+ draft Generate a markdown file from template
+ draft index Generate index file (e.g., README.md)
+ draft help Show this help message
+ draft version Show version
+
+Examples:
+ draft init
+ draft adr "Authentication System Design"
+ draft design "API Design"
+ draft adr index
+
+Template Variables:
+ {{@title}} - Title specified as argument
+ {{@today}} - Today's date (YYYY-MM-DD)
+ {{@date}} - Today's date (YYYY-MM-DD)
+ {{@name}} - Current user name
+ {{@id}} - Incremental ID (001, 002, ...)
+ {{@id{N}}} - Incremental ID with N digits (e.g., {{@id{4}}} -> 0001)
+
+Index Variables:
+ {{@index}} - Document list table (default: @title|@date|@name)
+ {{@index{@id|@title|@status}}} - Custom format table
+ {{@index{@id|@title,asc:@id}}} - Custom format with sort specification
+ {{@index{@id|@title|@date,desc:@date}}} - Sort by date descending
+
+Index Sort (default behavior):
+ - If documents have @id: sort by @id ascending
+ - Else if documents have @date: sort by @date descending
+ - Else: sort by file modification time descending
diff --git a/src/main.zig b/src/main.zig
index 1274315..fe55b3a 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -1,6 +1,7 @@
const std = @import("std");
const fs = std.fs;
const mem = std.mem;
+const build_options = @import("build_options");
const config = @import("config.zig");
const template = @import("template.zig");
@@ -28,6 +29,7 @@ const default_adr_template = @embedFile("templates/adr.md");
const default_adr_index_template = @embedFile("templates/adr-index.md");
const default_design_template = @embedFile("templates/design.md");
const default_design_index_template = @embedFile("templates/design-index.md");
+const usage_text = @embedFile("assets/usage.txt");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
@@ -68,54 +70,11 @@ pub fn main() !void {
}
fn printUsage() void {
- const usage =
- \\
- \\ ____ ____ _ ____ _____
- \\ | _ \| _ \ / \ | __|_ _|
- \\ | | | | |_) | / _ \ | |_ | |
- \\ | |_| | _ < / ___ \| _| | |
- \\ |____/|_| \_\_/ \_\_| |_|
- \\
- \\ Markdown template generator
- \\
- \\Usage:
- \\ draft init Initialize .draft directory with config and templates
- \\ draft Generate a markdown file from template
- \\ draft index Generate index file (e.g., README.md)
- \\ draft help Show this help message
- \\ draft version Show version
- \\
- \\Examples:
- \\ draft init
- \\ draft adr "Authentication System Design"
- \\ draft design "API Design"
- \\ draft adr index
- \\
- \\Template Variables:
- \\ {{@title}} - Title specified as argument
- \\ {{@today}} - Today's date (YYYY-MM-DD)
- \\ {{@date}} - Today's date (YYYY-MM-DD)
- \\ {{@name}} - Current user name
- \\ {{@id}} - Incremental ID (001, 002, ...)
- \\ {{@id{N}}} - Incremental ID with N digits (e.g., {{@id{4}}} -> 0001)
- \\
- \\Index Variables:
- \\ {{@index}} - Document list table (default: @title|@date|@name)
- \\ {{@index{@id|@title|@status}}} - Custom format table
- \\ {{@index{@id|@title,asc:@id}}} - Custom format with sort specification
- \\ {{@index{@id|@title|@date,desc:@date}}} - Sort by date descending
- \\
- \\Index Sort (default behavior):
- \\ - If documents have @id: sort by @id ascending
- \\ - Else if documents have @date: sort by @date descending
- \\ - Else: sort by file modification time descending
- \\
- ;
- std.debug.print("{s}", .{usage});
+ std.debug.print("{s}", .{usage_text});
}
fn printVersion() void {
- std.debug.print("draft version 0.3.0\n", .{});
+ std.debug.print("draft version {s}\n", .{build_options.version});
}
fn runInit(allocator: mem.Allocator) !void {