feat(setup): add repo subcommand
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
29cbec8575
commit
0179ddf4f2
4 changed files with 58 additions and 7 deletions
|
|
@ -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)
|
||||
|
|
|
|||
22
cmd/setup/cmd_repo_test.go
Normal file
22
cmd/setup/cmd_repo_test.go
Normal file
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue