feat(cmd/scm): add forge-url alias for index links
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
6dbb70d626
commit
8a269fa107
2 changed files with 36 additions and 8 deletions
|
|
@ -13,10 +13,10 @@ import (
|
|||
|
||||
func addIndexCommand(parent *cli.Command) {
|
||||
var (
|
||||
dirs []string
|
||||
output string
|
||||
baseURL string
|
||||
org string
|
||||
dirs []string
|
||||
output string
|
||||
forgeURL string
|
||||
org string
|
||||
)
|
||||
|
||||
cmd := &cli.Command{
|
||||
|
|
@ -27,21 +27,22 @@ func addIndexCommand(parent *cli.Command) {
|
|||
if len(dirs) == 0 {
|
||||
dirs = []string{"."}
|
||||
}
|
||||
return runIndex(dirs, output, baseURL, org)
|
||||
return runIndex(dirs, output, forgeURL, org)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringArrayVarP(&dirs, "dir", "d", nil, "Directories to scan (repeatable, default: current directory)")
|
||||
cmd.Flags().StringVarP(&output, "output", "o", "index.json", "Output path for the index file")
|
||||
cmd.Flags().StringVar(&baseURL, "base-url", "", "Base URL for repo links (e.g. https://forge.lthn.ai)")
|
||||
cmd.Flags().StringVar(&forgeURL, "forge-url", "", "Forge base URL for repo links (e.g. https://forge.lthn.ai)")
|
||||
cmd.Flags().StringVar(&forgeURL, "base-url", "", "Deprecated alias for --forge-url")
|
||||
cmd.Flags().StringVar(&org, "org", "", "Organisation for repo links")
|
||||
|
||||
parent.AddCommand(cmd)
|
||||
}
|
||||
|
||||
func runIndex(dirs []string, output, baseURL, org string) error {
|
||||
func runIndex(dirs []string, output, forgeURL, org string) error {
|
||||
b := &marketplace.Builder{
|
||||
BaseURL: baseURL,
|
||||
BaseURL: forgeURL,
|
||||
Org: org,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"dappco.re/go/core/io"
|
||||
"dappco.re/go/core/scm/marketplace"
|
||||
"forge.lthn.ai/core/cli/pkg/cli"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
@ -35,3 +36,29 @@ sign: key-a
|
|||
assert.Equal(t, "mod-a", idx.Modules[0].Code)
|
||||
assert.Equal(t, "https://forge.example.com/core/mod-a.git", idx.Modules[0].Repo)
|
||||
}
|
||||
|
||||
func TestAddScmCommands_Good_IndexForgeURLFlagAlias_Good(t *testing.T) {
|
||||
root := &cli.Command{Use: "root"}
|
||||
|
||||
AddScmCommands(root)
|
||||
|
||||
var scmCmd *cli.Command
|
||||
for _, cmd := range root.Commands() {
|
||||
if cmd.Name() == "scm" {
|
||||
scmCmd = cmd
|
||||
break
|
||||
}
|
||||
}
|
||||
require.NotNil(t, scmCmd)
|
||||
|
||||
var indexCmd *cli.Command
|
||||
for _, cmd := range scmCmd.Commands() {
|
||||
if cmd.Name() == "index" {
|
||||
indexCmd = cmd
|
||||
break
|
||||
}
|
||||
}
|
||||
require.NotNil(t, indexCmd)
|
||||
assert.NotNil(t, indexCmd.Flags().Lookup("forge-url"))
|
||||
assert.NotNil(t, indexCmd.Flags().Lookup("base-url"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue