Skip to content

Commit

Permalink
fix: modify code such that allow only yaml, not yml
Browse files Browse the repository at this point in the history
Signed-off-by: Youngjin Jo <[email protected]>
  • Loading branch information
yjinjo committed Nov 18, 2024
1 parent 6c2b88a commit 820df4f
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ var configInitCmd = &cobra.Command{
baseURL = "grpc+ssl://identity.api.stg.spaceone.dev:443"
}

// Set endpoint and token fields for the environment
if baseURL != "" {
viper.Set(fmt.Sprintf("environments.%s.endpoint", envName), baseURL)
}
viper.Set(fmt.Sprintf("environments.%s.token", envName), "") // Add token as an empty value

// Set the current environment
viper.Set("environment", envName)
Expand Down Expand Up @@ -121,11 +123,9 @@ var envCmd = &cobra.Command{

// Handle environment switching
if switchEnv != "" {
// Check for both .yaml and .yml extensions
// Check only for .yaml extensions
if _, err := os.Stat(filepath.Join(getConfigDir(), "environments", switchEnv+".yaml")); os.IsNotExist(err) {
if _, err := os.Stat(filepath.Join(getConfigDir(), "environments", switchEnv+".yml")); os.IsNotExist(err) {
log.Fatalf("Environment '%s' not found.", switchEnv)
}
log.Fatalf("Environment '%s' not found.", switchEnv)
}

// Update the environment in ~/.spaceone/config.yaml
Expand Down Expand Up @@ -155,11 +155,9 @@ var envCmd = &cobra.Command{

// Handle environment removal with confirmation
if removeEnv != "" {
// Check for both .yaml and .yml extensions
// Check only for .yaml extensions
if _, err := os.Stat(filepath.Join(getConfigDir(), "environments", removeEnv+".yaml")); os.IsNotExist(err) {
if _, err := os.Stat(filepath.Join(getConfigDir(), "environments", removeEnv+".yml")); os.IsNotExist(err) {
log.Fatalf("Environment '%s' not found.", removeEnv)
}
log.Fatalf("Environment '%s' not found.", removeEnv)
}

// Ask for confirmation before deletion
Expand All @@ -171,7 +169,6 @@ var envCmd = &cobra.Command{
if response == "y" {
// Remove the environment file
os.Remove(filepath.Join(getConfigDir(), "environments", removeEnv+".yaml"))
os.Remove(filepath.Join(getConfigDir(), "environments", removeEnv+".yml"))

// Check if this environment is set in config.yaml and clear it if so
configFilePath := filepath.Join(getConfigDir(), "config.yaml")
Expand Down Expand Up @@ -222,7 +219,7 @@ var envCmd = &cobra.Command{
pterm.Println("Available Environments:")
for _, entry := range entries {
name := entry.Name()
name = strings.TrimSuffix(name, filepath.Ext(name)) // Remove ".yaml" or ".yml" extension
name = strings.TrimSuffix(name, ".yaml") // Remove ".yaml" extension
if name == currentEnv {
pterm.FgGreen.Printf(" > %s (current)\n", name)
} else {
Expand Down Expand Up @@ -309,7 +306,7 @@ var syncCmd = &cobra.Command{
}

for _, entry := range entries {
if !entry.IsDir() && (filepath.Ext(entry.Name()) == ".yaml" || filepath.Ext(entry.Name()) == ".yml") {
if !entry.IsDir() && (filepath.Ext(entry.Name()) == ".yaml") {
envName := strings.TrimSuffix(entry.Name(), filepath.Ext(entry.Name()))

// Check if the environment already has a URL; if not, set it to an empty string
Expand Down

0 comments on commit 820df4f

Please sign in to comment.