Skip to content

Commit

Permalink
chore: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalPazz committed Jan 7, 2025
1 parent 044b2ba commit 6a9bed1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 32 deletions.
30 changes: 15 additions & 15 deletions cmd/commands/get_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ import (
func GetProfile(cmd *cobra.Command) {

profile, _ := cmd.Flags().GetString("profile")
all, _ := cmd.Flags().GetBool("all")
all, _ := cmd.Flags().GetBool("all")

config, ok := viper.Get("config").(types.Config)
config, ok := viper.Get("config").(types.Config)

if !ok {
fmt.Println("error: config structure is invalid")
return
}
if !ok {
fmt.Println("error: config structure is invalid")
return
}

fmt.Printf("Active Profile is: %s \n", profile)
fmt.Printf("Project Name: %s \n", config.Profiles[profile].ProjectName)
fmt.Printf("Region: %s \n", config.Profiles[profile].Region)
fmt.Printf("Active Profile is: %s \n", profile)
fmt.Printf("Project Name: %s \n", config.Profiles[profile].ProjectName)
fmt.Printf("Region: %s \n", config.Profiles[profile].Region)

if all {
fmt.Println("\nOther Profile Names:")
for name := range config.Profiles {
fmt.Printf("* %s \n", name)
}
}
if all {
fmt.Println("\nOther Profile Names:")
for name := range config.Profiles {
fmt.Printf("* %s \n", name)
}
}
}
8 changes: 4 additions & 4 deletions cmd/commands/get_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ func GetServicesCmd(cmd *cobra.Command) {
return
}

serviceAttributes, err := utils.GetServicesFields(project, env, "name", "type", "imageTag")
serviceAttributes, err := utils.GetServicesFields(project, env, "name", "type", "imageTag")
if err != nil {
fmt.Print(err)
return
}

for _ , atts := range serviceAttributes {
// TODO: Assert Types Before Print
fmt.Printf("* %s-%s : %s \n", atts["name"].(string),atts["type"].(string), atts["imageTag"].(string))
for _, atts := range serviceAttributes {
// TODO: Assert Types Before Print
fmt.Printf("* %s-%s : %s \n", atts["name"].(string), atts["type"].(string), atts["imageTag"].(string))
}
}
2 changes: 1 addition & 1 deletion cmd/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Extend(rootCmd *cobra.Command) {
RevertProjectCmd.MarkFlagRequired("env")

rootCmd.AddCommand(GetProfileCmd)
GetProfileCmd.Flags().Bool("all", false, "return all profile names")
GetProfileCmd.Flags().Bool("all", false, "return all profile names")

}

Expand Down
11 changes: 5 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"

"promoter/cmd/commands"
"promoter/internal/types"
"promoter/internal/types"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -40,7 +40,6 @@ var (
}
)


// Execute executes the root command.
func Execute() error {
Extend(rootCmd)
Expand Down Expand Up @@ -81,21 +80,21 @@ func initConfig() {

if err := viper.ReadInConfig(); err != nil {
fmt.Print(fmt.Errorf("fatal error reading config file: %w", err))
os.Exit(1)
os.Exit(1)
}

if err := viper.Unmarshal(&config); err != nil {
fmt.Print(fmt.Errorf("unable to decode into config struct: %w", err))
os.Exit(1)
os.Exit(1)
}

selectedProfile, exists := config.Profiles[profile]
if !exists {
fmt.Print(fmt.Errorf("profile '%s' not found in configuration", profile))
os.Exit(1)
os.Exit(1)
}

viper.Set("config", config)
viper.Set("config", config)

if region == "" {
region = selectedProfile.Region
Expand Down
1 change: 0 additions & 1 deletion internal/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ type Profile struct {
ProjectName string `mapstructure:"project-name"`
Region string `mapstructure:"region"`
}

9 changes: 4 additions & 5 deletions internal/utils/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package utils
import (
"errors"
"fmt"
"strconv"
"strconv"
)

type Config map[interface{}]interface{}
Expand Down Expand Up @@ -64,7 +64,7 @@ func GetServicesNames(project, env string) ([]string, error) {
var serviceNames []string

for _, atts := range services {
serviceNames = append(serviceNames, fmt.Sprintf("%s-%s", atts["name"] , atts["type"]))
serviceNames = append(serviceNames, fmt.Sprintf("%s-%s", atts["name"], atts["type"]))
}
return serviceNames, nil
}
Expand All @@ -78,7 +78,6 @@ func GetServicesFields(project, env string, fields ...string) ([]map[string]inte

var result []map[string]interface{}


for _, app := range services {
appMap, ok := app.(map[string]interface{})
if !ok {
Expand All @@ -91,8 +90,8 @@ func GetServicesFields(project, env string, fields ...string) ([]map[string]inte
if val, exists := appMap[field]; exists {
extractedFields[field] = val
} else {
fmt.Printf("error: no %s field in service %s \n", field, strconv.Itoa(index))
}
fmt.Printf("error: no %s field in service %s \n", field, strconv.Itoa(index))
}
}

if len(extractedFields) > 0 {
Expand Down

0 comments on commit 6a9bed1

Please sign in to comment.