exec method
Run command.
The contents of katana.yaml and the arguments of the command are passed to context.
コマンドを実行します。
contextにkatana.yamlの内容やコマンドの引数が渡されます。
Implementation
@override
Future<void> exec(ExecContext context) async {
final bin = context.yaml.getAsMap("bin");
final gh = bin.get("gh", "gh");
final github = context.yaml.getAsMap("github");
final claudeCode = github.getAsMap("claude_code");
final api = claudeCode.getAsMap("api");
final oauth = claudeCode.getAsMap("oauth");
final apiKey = api.get("api_key", "");
final token = oauth.get("token", "");
final personalAccessToken = claudeCode.get("personal_access_token", "");
final enableClaudeCodeBackground = claudeCode.get("background", false);
final model = claudeCode.get("model", "claude-sonnet-4-20250514");
final uses = claudeCode.get("uses", "anthropics/claude-code-action@beta");
if (apiKey.isEmpty && token.isEmpty) {
error(
"Configuration not found. Please set one of the following: `[claude_code]->[api]->[api_key]`, `[claude_code]->[oauth]->[token]`.",
);
return;
}
if (apiKey.isNotEmpty) {
await command(
"Set Anthropic API Key in `secrets.ANTHROPIC_API_KEY`.",
[
gh,
"secret",
"set",
"ANTHROPIC_API_KEY",
"--body",
apiKey,
],
);
} else {
await command(
"Set Claude Access Token in `secrets.CLAUDE_CODE_OAUTH_TOKEN`.",
[
gh,
"secret",
"set",
"CLAUDE_CODE_OAUTH_TOKEN",
"--body",
token,
],
);
}
if (personalAccessToken.isNotEmpty) {
await command(
"Store `personal_access_token` in `secrets.PERSONAL_ACCESS_TOKEN`.",
[
gh,
"secret",
"set",
"PERSONAL_ACCESS_TOKEN",
"--body",
personalAccessToken,
],
);
}
label("Create claude_code.yaml");
final gitDir = await findGitDirectory(Directory.current);
await GitClaudeCodeCliCode(
model: model,
actionsRepositoryName: uses,
workingDirectory: gitDir,
useApiKey: apiKey.isNotEmpty,
).generateFile("claude_code.yaml");
label("Create AGENTS.md");
await GitAgentsMarkdownCliCode(
availabeBackground: enableClaudeCodeBackground)
.generateFile("AGENTS.md");
label("Create settings.local.json");
await const GitClaudeSettingsCliCode().generateFile("settings.local.json");
label("Create agents");
await const AgentsAiCode().exec(context);
label("Create .mcp.json");
await const McpMcpCode().exec(context);
}