diff --git a/cmd/scm/cmd_index.go b/cmd/scm/cmd_index.go index d4fadb2..b976626 100644 --- a/cmd/scm/cmd_index.go +++ b/cmd/scm/cmd_index.go @@ -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, } diff --git a/cmd/scm/cmd_index_test.go b/cmd/scm/cmd_index_test.go index fd214fb..3a2edce 100644 --- a/cmd/scm/cmd_index_test.go +++ b/cmd/scm/cmd_index_test.go @@ -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")) +}