Skip to content

Commit

Permalink
add '--config' option to specify the path to configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-kar committed Oct 17, 2024
1 parent 648ea6e commit 891bda2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions cmd/iceberg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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() {
Expand All @@ -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)
}
Expand Down
18 changes: 12 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 891bda2

Please sign in to comment.