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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -15,8 +16,33 @@ import (
|
||||||
"dappco.re/go/core/i18n"
|
"dappco.re/go/core/i18n"
|
||||||
coreio "dappco.re/go/core/io"
|
coreio "dappco.re/go/core/io"
|
||||||
log "dappco.re/go/core/log"
|
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.
|
// runRepoSetup sets up the current repository with .core/ configuration.
|
||||||
func runRepoSetup(repoPath string, dryRun bool) error {
|
func runRepoSetup(repoPath string, dryRun bool) error {
|
||||||
fmt.Printf("%s %s: %s\n", dimStyle.Render(">>"), i18n.T("cmd.setup.repo.setting_up"), repoPath)
|
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
|
package setup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"forge.lthn.ai/core/cli/pkg/cli"
|
|
||||||
"dappco.re/go/core/i18n"
|
"dappco.re/go/core/i18n"
|
||||||
|
"forge.lthn.ai/core/cli/pkg/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Style aliases from shared package
|
// Style aliases from shared package
|
||||||
|
|
@ -51,6 +51,7 @@ func initSetupFlags() {
|
||||||
// AddSetupCommand adds the 'setup' command to the given parent command.
|
// AddSetupCommand adds the 'setup' command to the given parent command.
|
||||||
func AddSetupCommand(root *cli.Command) {
|
func AddSetupCommand(root *cli.Command) {
|
||||||
initSetupFlags()
|
initSetupFlags()
|
||||||
|
addRepoCommand(setupCmd)
|
||||||
addGitHubCommand(setupCmd)
|
addGitHubCommand(setupCmd)
|
||||||
root.AddCommand(setupCmd)
|
root.AddCommand(setupCmd)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -400,6 +400,14 @@
|
||||||
"select_packages": "Select packages to clone",
|
"select_packages": "Select packages to clone",
|
||||||
"confirm_clone": "Clone {{.Count}} package(s) to {{.Target}}?"
|
"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": {
|
"github": {
|
||||||
"short": "Configure GitHub repo settings",
|
"short": "Configure GitHub repo settings",
|
||||||
"long": "Apply standardised GitHub settings (labels, webhooks, branch protection, security) to repos.",
|
"long": "Apply standardised GitHub settings (labels, webhooks, branch protection, security) to repos.",
|
||||||
|
|
@ -429,12 +437,6 @@
|
||||||
"to_create": "To create",
|
"to_create": "To create",
|
||||||
"to_update": "To update",
|
"to_update": "To update",
|
||||||
"to_delete": "To delete"
|
"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