package commands

import (
	"fmt"
	"io"
	"os"

	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

var showConfigCmd = &cobra.Command{
	Use:   "config",
	Short: "print the current configuration",
	RunE: func(cmd *cobra.Command, args []string) error {
		configPath := viper.ConfigFileUsed()
		if configPath == "" {
			return fmt.Errorf("config file not setup yet, use \"localdev init\"")
		}

		file, err := os.Open(configPath)
		if err != nil {
			return err
		}

		defer file.Close()

		_, err = io.Copy(cmd.OutOrStdout(), file)
		return err
	},
}
