refactor: enhancement of logging, config and metrics
This commit is contained in:
@@ -16,9 +16,10 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/jkaninda/goma-gateway/internal"
|
||||
"github.com/jkaninda/goma-gateway/pkg/logger"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
)
|
||||
|
||||
var InitConfigCmd = &cobra.Command{
|
||||
@@ -26,14 +27,34 @@ var InitConfigCmd = &cobra.Command{
|
||||
Short: "Initialize Goma Gateway configuration file",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) == 0 {
|
||||
pkg.InitConfig(cmd)
|
||||
force, _ := cmd.Flags().GetBool("force")
|
||||
configFile, _ := cmd.Flags().GetString("output")
|
||||
if configFile == "" {
|
||||
fmt.Println("Error: no config file specified")
|
||||
os.Exit(1)
|
||||
}
|
||||
// Check if the config file exists
|
||||
if _, err := os.Stat(configFile); !os.IsNotExist(err) {
|
||||
if !force {
|
||||
fmt.Printf("%s config file already exists, use -f to overwrite\n", configFile)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
err := pkg.InitConfig(configFile)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println("configuration file has been initialized successfully")
|
||||
} else {
|
||||
logger.Fatal(`"config" accepts no argument %q`, args)
|
||||
fmt.Printf("config accepts no argument %q\n", args)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
InitConfigCmd.Flags().StringP("output", "o", "", "config file output")
|
||||
InitConfigCmd.Flags().StringP("output", "o", "", "configuration file output")
|
||||
InitConfigCmd.Flags().BoolP("force", "f", false, "Force overwrite configuration file")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user