Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,10 @@ onboard:
@echo "Step 1: Creating service scaffolding..."
@mkdir -p cmd
@sed -e 's/{{SERVICE}}/$(SERVICE)/g' \
-e 's/{{SERVICE_DISPLAY}}/$(shell echo $(SERVICE) | sed 's/\([a-z]\)\([A-Z]\)/\1 \2/g' | sed 's/v\([0-9]\)/v\1/g' | sed 's/\b\(.\)/\u\1/g')/g' \
-e 's/{{SERVICE_ALIAS}}/$(shell echo $(SERVICE) | sed 's/v[0-9]*$$//')/g' \
templates/cmd/service.go.tmpl > cmd/$(SERVICE).go
@echo " - Created cmd/$(SERVICE).go"
@mkdir -p internal/$(SERVICE)
@sed -e 's/{{SERVICE}}/$(SERVICE)/g' \
-e 's/{{SERVICE_DISPLAY}}/$(shell echo $(SERVICE) | sed 's/\([a-z]\)\([A-Z]\)/\1 \2/g' | sed 's/v\([0-9]\)/v\1/g' | sed 's/\b\(.\)/\u\1/g')/g' \
templates/internal/service.go.tmpl > internal/$(SERVICE)/$(SERVICE).go
@echo " - Created internal/$(SERVICE)/$(SERVICE).go"
@echo ""
Expand Down
14 changes: 8 additions & 6 deletions cmd/accesstokenv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

"github.com/equinix/cli/internal/accesstokenv1"
"github.com/equinix/cli/internal/naming"
"github.com/equinix/cli/internal/register"
"github.com/spf13/cobra"
)
Expand All @@ -17,10 +18,12 @@ var accesstokenv1Debug bool
//go:embed descriptions/accesstokenv1.json
var accesstokenv1Descriptions []byte

// accesstokenv1Cmd represents the accesstokenv1 command
// accesstokenv1Cmd represents the accesstokenv1 command. It is named after the
// canonical service name, with the versioned API name kept as an alias.
var accesstokenv1Cmd = &cobra.Command{
Use: "accesstokenv1",
Short: "Manage Equinix accesstokenv1 resources",
Use: naming.CanonicalServiceName("accesstokenv1"),
Aliases: naming.ServiceAliases("accesstokenv1"),
Short: "Manage Equinix accesstokenv1 resources",
Long: `Commands for managing Equinix accesstokenv1 resources.

The accesstokenv1 commands are dynamically generated based on the accesstokenv1 API client,
Expand Down Expand Up @@ -67,9 +70,8 @@ func init() {
fmt.Fprintf(os.Stderr, "Warning: Failed to register accesstokenv1 commands: %v\n", err)
}

// Uncomment and customize aliases as needed for convenience
// Example: Add shorter aliases for commonly used commands
// accesstokenv1Cmd.Aliases = []string{"accesstoken"}
// The versioned API name is already registered as an alias of the
// canonical command name; add further aliases here as needed.
//
// Or add aliases to specific subcommands after registration:
// if connectionsCmd, _, err := accesstokenv1Cmd.Find([]string{"connections"}); err == nil {
Expand Down
14 changes: 8 additions & 6 deletions cmd/eiav2.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

"github.com/equinix/cli/internal/eiav2"
"github.com/equinix/cli/internal/naming"
"github.com/equinix/cli/internal/register"
"github.com/spf13/cobra"
)
Expand All @@ -17,10 +18,12 @@ var eiav2Debug bool
//go:embed descriptions/eiav2.json
var eiav2Descriptions []byte

// eiav2Cmd represents the eiav2 command
// eiav2Cmd represents the eiav2 command. It is named after the
// canonical service name, with the versioned API name kept as an alias.
var eiav2Cmd = &cobra.Command{
Use: "eiav2",
Short: "Manage Equinix eiav2 resources",
Use: naming.CanonicalServiceName("eiav2"),
Aliases: naming.ServiceAliases("eiav2"),
Short: "Manage Equinix eiav2 resources",
Long: `Commands for managing Equinix eiav2 resources.

The eiav2 commands are dynamically generated based on the eiav2 API client,
Expand Down Expand Up @@ -67,9 +70,8 @@ func init() {
fmt.Fprintf(os.Stderr, "Warning: Failed to register eiav2 commands: %v\n", err)
}

// Uncomment and customize aliases as needed for convenience
// Example: Add shorter aliases for commonly used commands
// eiav2Cmd.Aliases = []string{"eia"}
// The versioned API name is already registered as an alias of the
// canonical command name; add further aliases here as needed.
//
// Or add aliases to specific subcommands after registration:
// if connectionsCmd, _, err := eiav2Cmd.Find([]string{"connections"}); err == nil {
Expand Down
18 changes: 10 additions & 8 deletions cmd/fabricv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

"github.com/equinix/cli/internal/fabricv4"
"github.com/equinix/cli/internal/naming"
"github.com/equinix/cli/internal/register"
"github.com/spf13/cobra"
)
Expand All @@ -17,13 +18,15 @@ var fabricv4Debug bool
//go:embed descriptions/fabricv4.json
var fabricv4Descriptions []byte

// fabricv4Cmd represents the fabricv4 command
// fabricv4Cmd represents the fabricv4 command. It is named after the
// canonical service name, with the versioned API name kept as an alias.
var fabricv4Cmd = &cobra.Command{
Use: "fabricv4",
Short: "Manage Equinix fauricv4 resources",
Long: `Commands for managing Equinix fauricv4 resources.
Use: naming.CanonicalServiceName("fabricv4"),
Aliases: naming.ServiceAliases("fabricv4"),
Short: "Manage Equinix fabricv4 resources",
Long: `Commands for managing Equinix fabricv4 resources.

The fabricv4 commands are dynamically generated based on the fauricv4 API client,
The fabricv4 commands are dynamically generated based on the fabricv4 API client,
providing access to all available API services.`,
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
// Inject the client factory into the command context so that
Expand Down Expand Up @@ -67,9 +70,8 @@ func init() {
fmt.Fprintf(os.Stderr, "Warning: Failed to register fabricv4 commands: %v\n", err)
}

// Uncomment and customize aliases as needed for convenience
// Example: Add shorter aliases for commonly used commands
// fabricv4Cmd.Aliases = []string{"fabric"}
// The versioned API name is already registered as an alias of the
// canonical command name; add further aliases here as needed.
//
// Or add aliases to specific subcommands after registration:
// if connectionsCmd, _, err := fabricv4Cmd.Find([]string{"connections"}); err == nil {
Expand Down
14 changes: 8 additions & 6 deletions cmd/lookupv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

"github.com/equinix/cli/internal/lookupv2"
"github.com/equinix/cli/internal/naming"
"github.com/equinix/cli/internal/register"
"github.com/spf13/cobra"
)
Expand All @@ -17,10 +18,12 @@ var lookupv2Debug bool
//go:embed descriptions/lookupv2.json
var lookupv2Descriptions []byte

// lookupv2Cmd represents the lookupv2 command
// lookupv2Cmd represents the lookupv2 command. It is named after the
// canonical service name, with the versioned API name kept as an alias.
var lookupv2Cmd = &cobra.Command{
Use: "lookupv2",
Short: "Manage Equinix lookupv2 resources",
Use: naming.CanonicalServiceName("lookupv2"),
Aliases: naming.ServiceAliases("lookupv2"),
Short: "Manage Equinix lookupv2 resources",
Long: `Commands for managing Equinix lookupv2 resources.

The lookupv2 commands are dynamically generated based on the lookupv2 API client,
Expand Down Expand Up @@ -67,9 +70,8 @@ func init() {
fmt.Fprintf(os.Stderr, "Warning: Failed to register lookupv2 commands: %v\n", err)
}

// Uncomment and customize aliases as needed for convenience
// Example: Add shorter aliases for commonly used commands
// lookupv2Cmd.Aliases = []string{"lookup"}
// The versioned API name is already registered as an alias of the
// canonical command name; add further aliases here as needed.
//
// Or add aliases to specific subcommands after registration:
// if connectionsCmd, _, err := lookupv2Cmd.Find([]string{"connections"}); err == nil {
Expand Down
14 changes: 8 additions & 6 deletions cmd/orderhistoryv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"

"github.com/equinix/cli/internal/naming"
"github.com/equinix/cli/internal/orderhistoryv1"
"github.com/equinix/cli/internal/register"
"github.com/spf13/cobra"
Expand All @@ -17,10 +18,12 @@ var orderhistoryv1Debug bool
//go:embed descriptions/orderhistoryv1.json
var orderhistoryv1Descriptions []byte

// orderhistoryv1Cmd represents the orderhistoryv1 command
// orderhistoryv1Cmd represents the orderhistoryv1 command. It is named after the
// canonical service name, with the versioned API name kept as an alias.
var orderhistoryv1Cmd = &cobra.Command{
Use: "orderhistoryv1",
Short: "Manage Equinix orderhistoryv1 resources",
Use: naming.CanonicalServiceName("orderhistoryv1"),
Aliases: naming.ServiceAliases("orderhistoryv1"),
Short: "Manage Equinix orderhistoryv1 resources",
Long: `Commands for managing Equinix orderhistoryv1 resources.

The orderhistoryv1 commands are dynamically generated based on the orderhistoryv1 API client,
Expand Down Expand Up @@ -67,9 +70,8 @@ func init() {
fmt.Fprintf(os.Stderr, "Warning: Failed to register orderhistoryv1 commands: %v\n", err)
}

// Uncomment and customize aliases as needed for convenience
// Example: Add shorter aliases for commonly used commands
// orderhistoryv1Cmd.Aliases = []string{"orderhistory"}
// The versioned API name is already registered as an alias of the
// canonical command name; add further aliases here as needed.
//
// Or add aliases to specific subcommands after registration:
// if connectionsCmd, _, err := orderhistoryv1Cmd.Find([]string{"connections"}); err == nil {
Expand Down
14 changes: 8 additions & 6 deletions cmd/ordersv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"

"github.com/equinix/cli/internal/naming"
"github.com/equinix/cli/internal/ordersv2"
"github.com/equinix/cli/internal/register"
"github.com/spf13/cobra"
Expand All @@ -17,10 +18,12 @@ var ordersv2Debug bool
//go:embed descriptions/ordersv2.json
var ordersv2Descriptions []byte

// ordersv2Cmd represents the ordersv2 command
// ordersv2Cmd represents the ordersv2 command. It is named after the
// canonical service name, with the versioned API name kept as an alias.
var ordersv2Cmd = &cobra.Command{
Use: "ordersv2",
Short: "Manage Equinix ordersv2 resources",
Use: naming.CanonicalServiceName("ordersv2"),
Aliases: naming.ServiceAliases("ordersv2"),
Short: "Manage Equinix ordersv2 resources",
Long: `Commands for managing Equinix ordersv2 resources.

The ordersv2 commands are dynamically generated based on the ordersv2 API client,
Expand Down Expand Up @@ -67,9 +70,8 @@ func init() {
fmt.Fprintf(os.Stderr, "Warning: Failed to register ordersv2 commands: %v\n", err)
}

// Uncomment and customize aliases as needed for convenience
// Example: Add shorter aliases for commonly used commands
// ordersv2Cmd.Aliases = []string{"orders"}
// The versioned API name is already registered as an alias of the
// canonical command name; add further aliases here as needed.
//
// Or add aliases to specific subcommands after registration:
// if connectionsCmd, _, err := ordersv2Cmd.Find([]string{"connections"}); err == nil {
Expand Down
50 changes: 50 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package cmd

import (
"testing"
)

// TestNoConflictingServiceNames fails the build when two service commands
// claim the same name. Canonical service names drop the API version suffix,
// so two versions of the same API (e.g. fabricv4 and a future fabricv5) would
// otherwise silently shadow one another.
func TestNoConflictingServiceNames(t *testing.T) {
claimedBy := map[string]string{}

for _, cmd := range rootCmd.Commands() {
for _, name := range append([]string{cmd.Name()}, cmd.Aliases...) {
if owner, taken := claimedBy[name]; taken {
t.Errorf("command name %q is claimed by both %q and %q", name, owner, cmd.Name())
continue
}
claimedBy[name] = cmd.Name()
}
}
}

// TestServiceCommandsAreCanonical checks that each onboarded service is
// reachable under its canonical name and still under its versioned API name.
func TestServiceCommandsAreCanonical(t *testing.T) {
for apiName, canonical := range map[string]string{
"accesstokenv1": "accesstoken",
"eiav2": "eia",
"fabricv4": "fabric",
"lookupv2": "lookup",
"orderhistoryv1": "orderhistory",
"ordersv2": "orders",
"securecabinetv1": "securecabinet",
"smarthandsv1": "smarthands",
"stsv1alpha": "sts-alpha",
} {
for _, name := range []string{canonical, apiName} {
cmd, _, err := rootCmd.Find([]string{name})
if err != nil {
t.Errorf("looking up %q: %v", name, err)
continue
}
if cmd.Name() != canonical {
t.Errorf("%q resolved to command %q, want %q", name, cmd.Name(), canonical)
}
}
}
}
18 changes: 10 additions & 8 deletions cmd/securecabinetv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"

"github.com/equinix/cli/internal/naming"
"github.com/equinix/cli/internal/register"
"github.com/equinix/cli/internal/securecabinetv1"
"github.com/spf13/cobra"
Expand All @@ -17,13 +18,15 @@ var securecabinetv1Debug bool
//go:embed descriptions/securecabinetv1.json
var securecabinetv1Descriptions []byte

// securecabinetv1Cmd represents the securecabinetv1 command
// securecabinetv1Cmd represents the securecabinetv1 command. It is named after the
// canonical service name, with the versioned API name kept as an alias.
var securecabinetv1Cmd = &cobra.Command{
Use: "securecabinetv1",
Short: "Manage Equinix securecauinetv1 resources",
Long: `Commands for managing Equinix securecauinetv1 resources.
Use: naming.CanonicalServiceName("securecabinetv1"),
Aliases: naming.ServiceAliases("securecabinetv1"),
Short: "Manage Equinix securecabinetv1 resources",
Long: `Commands for managing Equinix securecabinetv1 resources.

The securecabinetv1 commands are dynamically generated based on the securecauinetv1 API client,
The securecabinetv1 commands are dynamically generated based on the securecabinetv1 API client,
providing access to all available API services.`,
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
// Inject the client factory into the command context so that
Expand Down Expand Up @@ -67,9 +70,8 @@ func init() {
fmt.Fprintf(os.Stderr, "Warning: Failed to register securecabinetv1 commands: %v\n", err)
}

// Uncomment and customize aliases as needed for convenience
// Example: Add shorter aliases for commonly used commands
// securecabinetv1Cmd.Aliases = []string{"securecabinet"}
// The versioned API name is already registered as an alias of the
// canonical command name; add further aliases here as needed.
//
// Or add aliases to specific subcommands after registration:
// if connectionsCmd, _, err := securecabinetv1Cmd.Find([]string{"connections"}); err == nil {
Expand Down
14 changes: 8 additions & 6 deletions cmd/smarthandsv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"

"github.com/equinix/cli/internal/naming"
"github.com/equinix/cli/internal/register"
"github.com/equinix/cli/internal/smarthandsv1"
"github.com/spf13/cobra"
Expand All @@ -17,10 +18,12 @@ var smarthandsv1Debug bool
//go:embed descriptions/smarthandsv1.json
var smarthandsv1Descriptions []byte

// smarthandsv1Cmd represents the smarthandsv1 command
// smarthandsv1Cmd represents the smarthandsv1 command. It is named after the
// canonical service name, with the versioned API name kept as an alias.
var smarthandsv1Cmd = &cobra.Command{
Use: "smarthandsv1",
Short: "Manage Equinix smarthandsv1 resources",
Use: naming.CanonicalServiceName("smarthandsv1"),
Aliases: naming.ServiceAliases("smarthandsv1"),
Short: "Manage Equinix smarthandsv1 resources",
Long: `Commands for managing Equinix smarthandsv1 resources.

The smarthandsv1 commands are dynamically generated based on the smarthandsv1 API client,
Expand Down Expand Up @@ -67,9 +70,8 @@ func init() {
fmt.Fprintf(os.Stderr, "Warning: Failed to register smarthandsv1 commands: %v\n", err)
}

// Uncomment and customize aliases as needed for convenience
// Example: Add shorter aliases for commonly used commands
// smarthandsv1Cmd.Aliases = []string{"smarthands"}
// The versioned API name is already registered as an alias of the
// canonical command name; add further aliases here as needed.
//
// Or add aliases to specific subcommands after registration:
// if connectionsCmd, _, err := smarthandsv1Cmd.Find([]string{"connections"}); err == nil {
Expand Down
14 changes: 8 additions & 6 deletions cmd/stsv1alpha.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"

"github.com/equinix/cli/internal/naming"
"github.com/equinix/cli/internal/register"
"github.com/equinix/cli/internal/stsv1alpha"
"github.com/spf13/cobra"
Expand All @@ -17,10 +18,12 @@ var stsv1alphaDebug bool
//go:embed descriptions/stsv1alpha.json
var stsv1alphaDescriptions []byte

// stsv1alphaCmd represents the stsv1alpha command
// stsv1alphaCmd represents the stsv1alpha command. It is named after the
// canonical service name, with the versioned API name kept as an alias.
var stsv1alphaCmd = &cobra.Command{
Use: "stsv1alpha",
Short: "Manage Equinix stsv1alpha resources",
Use: naming.CanonicalServiceName("stsv1alpha"),
Aliases: naming.ServiceAliases("stsv1alpha"),
Short: "Manage Equinix stsv1alpha resources",
Long: `Commands for managing Equinix stsv1alpha resources.

The stsv1alpha commands are dynamically generated based on the stsv1alpha API client,
Expand Down Expand Up @@ -67,9 +70,8 @@ func init() {
fmt.Fprintf(os.Stderr, "Warning: Failed to register stsv1alpha commands: %v\n", err)
}

// Uncomment and customize aliases as needed for convenience
// Example: Add shorter aliases for commonly used commands
// stsv1alphaCmd.Aliases = []string{"stsv1alpha"}
// The versioned API name is already registered as an alias of the
// canonical command name; add further aliases here as needed.
//
// Or add aliases to specific subcommands after registration:
// if connectionsCmd, _, err := stsv1alphaCmd.Find([]string{"connections"}); err == nil {
Expand Down
Loading
Loading