new: port the shell, empty, makefile and go templates to manifests

Move the four templates' static file bodies into .tpl files under
data/templates/<id>/, referenced by their manifests' files: lists —
the shell skeleton script (executable, {command}-named) with its
skeleton-only debian/install mapping, the empty template's stub README,
the makefile hello.c/Makefile skeleton with its skeleton-only install
mapping, and go's go.mod/main.go skeleton (the go directive of go.mod
stays a literal: nothing about it is answer-derived).

The empty template ends up hookless — zero Rust, its registry entry
points at no hooks — and src/new/templates/empty.rs is deleted. The
shell and go hooks shrink to their probes (plus go's {go_import_path}
context value); the makefile hooks keep only the existing-tree hint
probing the packaged Makefile for a phony install: target, since that
heuristic reads the tree and cannot be data.
This commit is contained in:
2026-09-18 14:58:13 +02:00
parent 04a572cd77
commit ffac4d6b57
17 changed files with 204 additions and 250 deletions
+9 -39
View File
@@ -1,16 +1,16 @@
//! The `go` template: a Go module built through dh-golang.
//!
//! The source stanza carries `XS-Go-Import-Path`, declared as the
//! `{go_import_path}` placeholder by the manifest and filled from the
//! `module` line of `go.mod` when the packaged tree has one, defaulting to
//! the package name (fresh skeletons embed the package name in their own
//! `go.mod`). The module line is also the probe of an existing project; the
//! skeleton bodies stay here until they move into the manifest's `files:`
//! list.
//! The skeleton bodies (`go.mod`, `main.go`) are manifest data
//! (`data/templates/go/manifest.yml`); the source stanza carries
//! `XS-Go-Import-Path`, declared as the `{go_import_path}` placeholder by
//! the manifest and filled here from the `module` line of `go.mod` when
//! the packaged tree has one, defaulting to the package name (fresh
//! skeletons embed the package name in their own `go.mod`). The module
//! line is also the probe of an existing project.
use std::path::Path;
use super::{OutputFile, ProbeResult, TemplateHooks, source_dir_of};
use super::{ProbeResult, TemplateHooks, source_dir_of};
use crate::new::options::NewOptions;
/// The logic half of the go template.
@@ -20,37 +20,6 @@ pub struct Hooks;
pub static HOOKS: Hooks = Hooks;
impl TemplateHooks for Hooks {
/// A stdlib-only `main.go` (no archive dependencies needed to build) and
/// the matching `go.mod` whose module path is the package name.
fn skeleton_files(&self, opts: &NewOptions) -> Vec<OutputFile> {
vec![
OutputFile::new(
"go.mod",
format!(
"module {name}\n\
\n\
go 1.21\n",
name = opts.name,
),
),
OutputFile::new(
"main.go",
format!(
"// Placeholder for {name}, generated by `pkh new`.\n\
package main\n\
\n\
import \"fmt\"\n\
\n\
func main() {{\n\
\tfmt.Println(\"Hello from {command}!\")\n\
}}\n",
name = opts.name,
command = opts.command,
),
),
]
}
/// The `{go_import_path}` value of the manifest's `XS-Go-Import-Path`
/// source field (see [`import_path`]).
fn context(&self, opts: &NewOptions) -> Vec<(String, String)> {
@@ -143,6 +112,7 @@ mod tests {
assert_eq!(template.rules_dh_line(), "dh $@ --buildsystem=golang");
assert!(template.debian(&o).is_empty());
// The skeleton bodies are manifest data now.
let skeleton = template.skeleton(&o);
assert!(
skeleton