Moves the `domain` and `ports` packages from `internal/core` to `internal`. This refactoring simplifies the directory structure by elevating the core architectural concepts of domain and ports to the top level of the `internal` directory. The `core` directory is now removed as its only purpose was to house these two packages. All import paths across the project have been updated to reflect this change.
156 lines
No EOL
4.7 KiB
Go
156 lines
No EOL
4.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/domain"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
cloudletName string
|
|
cloudletOrg string
|
|
instanceName string
|
|
flavorName string
|
|
)
|
|
|
|
var appInstanceCmd = &cobra.Command{
|
|
Use: "instance",
|
|
Short: "Manage Edge Connect application instances",
|
|
Long: `Create, show, list, and delete Edge Connect application instances.`,
|
|
}
|
|
|
|
var createInstanceCmd = &cobra.Command{
|
|
Use: "create",
|
|
Short: "Create a new Edge Connect application instance",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
appInst := &domain.AppInstance{
|
|
Key: domain.AppInstanceKey{
|
|
Organization: organization,
|
|
Name: instanceName,
|
|
CloudletKey: domain.CloudletKey{
|
|
Organization: cloudletOrg,
|
|
Name: cloudletName,
|
|
},
|
|
},
|
|
AppKey: domain.AppKey{
|
|
Organization: organization,
|
|
Name: appName,
|
|
Version: appVersion,
|
|
},
|
|
Flavor: domain.Flavor{
|
|
Name: flavorName,
|
|
},
|
|
}
|
|
|
|
err := services.InstanceService.CreateAppInstance(context.Background(), region, appInst)
|
|
if err != nil {
|
|
fmt.Printf("Error creating app instance: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
fmt.Println("Application instance created successfully")
|
|
},
|
|
}
|
|
|
|
var showInstanceCmd = &cobra.Command{
|
|
Use: "show",
|
|
Short: "Show details of an Edge Connect application instance",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
instanceKey := domain.AppInstanceKey{
|
|
Organization: organization,
|
|
Name: instanceName,
|
|
CloudletKey: domain.CloudletKey{
|
|
Organization: cloudletOrg,
|
|
Name: cloudletName,
|
|
},
|
|
}
|
|
|
|
instance, err := services.InstanceService.ShowAppInstance(context.Background(), region, instanceKey)
|
|
if err != nil {
|
|
fmt.Printf("Error showing app instance: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
fmt.Printf("Application instance details:\n%+v\n", instance)
|
|
},
|
|
}
|
|
|
|
var listInstancesCmd = &cobra.Command{
|
|
Use: "list",
|
|
Short: "List Edge Connect application instances",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
instanceKey := domain.AppInstanceKey{
|
|
Organization: organization,
|
|
Name: instanceName,
|
|
CloudletKey: domain.CloudletKey{
|
|
Organization: cloudletOrg,
|
|
Name: cloudletName,
|
|
},
|
|
}
|
|
|
|
instances, err := services.InstanceService.ShowAppInstances(context.Background(), region, instanceKey)
|
|
if err != nil {
|
|
fmt.Printf("Error listing app instances: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
fmt.Println("Application instances:")
|
|
for _, instance := range instances {
|
|
fmt.Printf("%+v\n", instance)
|
|
}
|
|
},
|
|
}
|
|
|
|
var deleteInstanceCmd = &cobra.Command{
|
|
Use: "delete",
|
|
Short: "Delete an Edge Connect application instance",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
instanceKey := domain.AppInstanceKey{
|
|
Organization: organization,
|
|
Name: instanceName,
|
|
CloudletKey: domain.CloudletKey{
|
|
Organization: cloudletOrg,
|
|
Name: cloudletName,
|
|
},
|
|
}
|
|
|
|
err := services.InstanceService.DeleteAppInstance(context.Background(), region, instanceKey)
|
|
if err != nil {
|
|
fmt.Printf("Error deleting app instance: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
fmt.Println("Application instance deleted successfully")
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(appInstanceCmd)
|
|
appInstanceCmd.AddCommand(createInstanceCmd, showInstanceCmd, listInstancesCmd, deleteInstanceCmd)
|
|
|
|
// Add flags to all instance commands
|
|
instanceCmds := []*cobra.Command{createInstanceCmd, showInstanceCmd, listInstancesCmd, deleteInstanceCmd}
|
|
for _, cmd := range instanceCmds {
|
|
cmd.Flags().StringVarP(&organization, "org", "o", "", "organization name (required)")
|
|
cmd.Flags().StringVarP(&instanceName, "name", "n", "", "instance name (required)")
|
|
cmd.Flags().StringVarP(&cloudletName, "cloudlet", "c", "", "cloudlet name (required)")
|
|
cmd.Flags().StringVarP(&cloudletOrg, "cloudlet-org", "", "", "cloudlet organization (required)")
|
|
cmd.Flags().StringVarP(®ion, "region", "r", "", "region (required)")
|
|
|
|
for _, flag := range []string{"org", "name", "cloudlet", "cloudlet-org", "region"} {
|
|
if err := cmd.MarkFlagRequired(flag); err != nil {
|
|
panic(fmt.Sprintf("Failed to mark '%s' flag as required: %v", flag, err))
|
|
}
|
|
}
|
|
}
|
|
|
|
// Add additional flags for create command
|
|
createInstanceCmd.Flags().StringVarP(&appName, "app", "a", "", "application name (required)")
|
|
createInstanceCmd.Flags().StringVarP(&appVersion, "version", "v", "", "application version")
|
|
createInstanceCmd.Flags().StringVarP(&flavorName, "flavor", "f", "", "flavor name (required)")
|
|
if err := createInstanceCmd.MarkFlagRequired("app"); err != nil {
|
|
panic(fmt.Sprintf("Failed to mark 'app' flag as required: %v", err))
|
|
}
|
|
if err := createInstanceCmd.MarkFlagRequired("flavor"); err != nil {
|
|
panic(fmt.Sprintf("Failed to mark 'flavor' flag as required: %v", err))
|
|
}
|
|
} |