Skip to content

Copy and Merge directories

Asterios Raptis edited this page Aug 26, 2025 · 1 revision

📂 Copy and Merge directories (Java) — BETA

A small Java CLI that mirrors the Python merge-with-tmpl behavior using your existing utility classes:

  • Copy when destination subdirectory doesn’t exist (CopyDirectoryExtensions)

  • Merge when destination subdirectory exists (MergeDirectoryExtensions, overwriting conflicts)

  • Optional dry-run to preview actions

  • Optional defaults via ./config/merge_defaults.json

Status: BETA — Interfaces and defaults may change. Please verify with --dry-run before committing.


⚙️ Defaults (optional)

./config/merge_defaults.json:

{
  "default_src_base": "/path/to/template",
  "default_dst_base": "/path/to/project",
  "default_dirs": ["scripts", "tests"]
}
  • default_src_base – Source base (template)

  • default_dst_base – Destination base (your project)

  • default_dirs – Directories to process


🚀 Usage

Run with explicit args:

java io.github.astrapi69.tools.MergeWithTemplate \
  --src_base /path/to/template \
  --dst_base /path/to/project \
  --dirs scripts tests

Use defaults from JSON:

java io.github.astrapi69.tools.MergeWithTemplate

Preview only:

java io.github.astrapi69.tools.MergeWithTemplate --dry-run --dirs scripts tests

📂 Behavior

  • If /project/scripts does not existcopy whole /template/scripts into it.

  • If /project/scripts existsmerge /template/scripts into it (files with same relative path are overwritten by source).

  • Multiple dirs supported: --dirs scripts tests assets.


🛡️ Best Practices (BETA)

  • Always run with --dry-run first to see planned changes.

  • Keep merge_defaults.json in version control to unify defaults across repos.

  • Check git status after running to confirm expected diffs.

  • Prefer small, focused commits: first the template merge, then your edits.


✅ Testing

A JUnit 5 test class is provided (MergeWithTemplateTest) verifying:

  • copy on non-existing destination,

  • merge overwriting behavior,

  • dry-run safety,

  • multi-dir operation.


Clone this wiki locally