From 0179ddf4f20a02fe5b0e479954eedd0e4e9c1831 Mon Sep 17 00:00:00 2001 From: Virgil Date: Wed, 1 Apr 2026 06:49:34 +0000 Subject: [PATCH] feat(setup): add repo subcommand Co-Authored-By: Virgil --- cmd/setup/cmd_repo.go | 26 ++++++++++++++++++++++++++ cmd/setup/cmd_repo_test.go | 22 ++++++++++++++++++++++ cmd/setup/cmd_setup.go | 3 ++- locales/en.json | 14 ++++++++------ 4 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 cmd/setup/cmd_repo_test.go diff --git a/cmd/setup/cmd_repo.go b/cmd/setup/cmd_repo.go index 1fd6542..b50ba06 100644 --- a/cmd/setup/cmd_repo.go +++ b/cmd/setup/cmd_repo.go @@ -8,6 +8,7 @@ package setup import ( "fmt" + "os" "os/exec" "path/filepath" "strings" @@ -15,8 +16,33 @@ import ( "dappco.re/go/core/i18n" coreio "dappco.re/go/core/io" log "dappco.re/go/core/log" + "forge.lthn.ai/core/cli/pkg/cli" ) +var repoDryRun bool + +// addRepoCommand adds the 'repo' subcommand to generate .core configuration. +func addRepoCommand(parent *cli.Command) { + repoCmd := &cli.Command{ + Use: "repo", + Short: i18n.T("cmd.setup.repo.short"), + Long: i18n.T("cmd.setup.repo.long"), + Args: cli.ExactArgs(0), + RunE: func(cmd *cli.Command, args []string) error { + cwd, err := os.Getwd() + if err != nil { + return log.E("setup.repo", "failed to get working directory", err) + } + + return runRepoSetup(cwd, repoDryRun) + }, + } + + repoCmd.Flags().BoolVar(&repoDryRun, "dry-run", false, i18n.T("cmd.setup.flag.dry_run")) + + parent.AddCommand(repoCmd) +} + // runRepoSetup sets up the current repository with .core/ configuration. func runRepoSetup(repoPath string, dryRun bool) error { fmt.Printf("%s %s: %s\n", dimStyle.Render(">>"), i18n.T("cmd.setup.repo.setting_up"), repoPath) diff --git a/cmd/setup/cmd_repo_test.go b/cmd/setup/cmd_repo_test.go new file mode 100644 index 0000000..8b971a6 --- /dev/null +++ b/cmd/setup/cmd_repo_test.go @@ -0,0 +1,22 @@ +package setup + +import ( + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestRunRepoSetup_CreatesCoreConfigs(t *testing.T) { + dir := t.TempDir() + require.NoError(t, os.WriteFile(filepath.Join(dir, "go.mod"), []byte("module example.com/test\n"), 0o644)) + + require.NoError(t, runRepoSetup(dir, false)) + + for _, name := range []string{"build.yaml", "release.yaml", "test.yaml"} { + path := filepath.Join(dir, ".core", name) + _, err := os.Stat(path) + require.NoErrorf(t, err, "expected %s to exist", path) + } +} diff --git a/cmd/setup/cmd_setup.go b/cmd/setup/cmd_setup.go index 38128f3..a3b20f6 100644 --- a/cmd/setup/cmd_setup.go +++ b/cmd/setup/cmd_setup.go @@ -2,8 +2,8 @@ package setup import ( - "forge.lthn.ai/core/cli/pkg/cli" "dappco.re/go/core/i18n" + "forge.lthn.ai/core/cli/pkg/cli" ) // Style aliases from shared package @@ -51,6 +51,7 @@ func initSetupFlags() { // AddSetupCommand adds the 'setup' command to the given parent command. func AddSetupCommand(root *cli.Command) { initSetupFlags() + addRepoCommand(setupCmd) addGitHubCommand(setupCmd) root.AddCommand(setupCmd) } diff --git a/locales/en.json b/locales/en.json index 24b8f0e..0e14191 100644 --- a/locales/en.json +++ b/locales/en.json @@ -400,6 +400,14 @@ "select_packages": "Select packages to clone", "confirm_clone": "Clone {{.Count}} package(s) to {{.Target}}?" }, + "repo": { + "short": "Generate .core config for a repo", + "long": "Detect the current project type and generate .core/build.yaml, release.yaml, and test.yaml for the repository.", + "setting_up": "Setting up repo", + "detected_type": "Detected project type", + "would_create": "Would create", + "created": "Created" + }, "github": { "short": "Configure GitHub repo settings", "long": "Apply standardised GitHub settings (labels, webhooks, branch protection, security) to repos.", @@ -429,12 +437,6 @@ "to_create": "To create", "to_update": "To update", "to_delete": "To delete" - }, - "repo": { - "setting_up": "Setting up repo", - "detected_type": "Detected project type", - "would_create": "Would create", - "created": "Created" } } },