From 891bda2f2e2ee8afa17c61ad46c2581f442c2b12 Mon Sep 17 00:00:00 2001 From: Alex Karpov Date: Mon, 30 Sep 2024 23:29:34 -0400 Subject: [PATCH] add '--config' option to specify the path to configuration file --- cmd/iceberg/main.go | 6 ++++-- config/config.go | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cmd/iceberg/main.go b/cmd/iceberg/main.go index f4e0c41..7ec4a8e 100644 --- a/cmd/iceberg/main.go +++ b/cmd/iceberg/main.go @@ -59,7 +59,8 @@ Options: --uri TEXT specify the catalog URI --output TYPE output type (json/text) [default: text] --credential TEXT specify credentials for the catalog - --warehouse TEXT specify the warehouse to use` + --warehouse TEXT specify the warehouse to use + --config TEXT specify the path to the configuration file` type Config struct { List bool `docopt:"list"` @@ -95,6 +96,7 @@ type Config struct { History bool `docopt:"--history"` Cred string `docopt:"--credential"` Warehouse string `docopt:"--warehouse"` + Config string `docopt:"--config"` } func main() { @@ -109,7 +111,7 @@ func main() { log.Fatal(err) } - fileCfg := config.ParseConfig(config.LoadConfig(), "default") + fileCfg := config.ParseConfig(config.LoadConfig(cfg.Config), "default") if fileCfg != nil { mergeConf(fileCfg, &cfg) } diff --git a/config/config.go b/config/config.go index fa6b92c..4af7654 100644 --- a/config/config.go +++ b/config/config.go @@ -38,13 +38,19 @@ type CatalogConfig struct { Warehouse string `yaml:"warehouse"` } -func LoadConfig() []byte { - homeDir, err := os.UserHomeDir() - if err != nil { - return nil +func LoadConfig(configPath string) []byte { + var path string + if len(configPath) > 0 { + path = configPath + } else { + homeDir, err := os.UserHomeDir() + if err != nil { + return nil + + } + path = filepath.Join(homeDir, cfgFile) } - filePath := filepath.Join(homeDir, cfgFile) - file, err := os.ReadFile(filePath) + file, err := os.ReadFile(path) if err != nil { return nil }