@@ -3,13 +3,16 @@ package cmd
33import (
44 "os"
55
6+ "github.com/highcard-dev/daemon/internal/core/domain"
7+ "github.com/highcard-dev/daemon/internal/core/services/registry"
68 "github.com/spf13/cobra"
79 "github.com/spf13/viper"
810)
911
1012var envPath string
1113var cwd string
1214var ignoreLockfileQueue bool
15+ var configFile string
1316
1417var RootCmd = & cobra.Command {
1518 Use : "druid" ,
@@ -22,8 +25,6 @@ var RootCmd = &cobra.Command{
2225}
2326
2427func init () {
25-
26- viper .SetDefault ("registry.host" , "registry-1.docker.io" )
2728 cobra .OnInitialize (initConfig )
2829
2930 RootCmd .AddCommand (ServeCommand )
@@ -43,22 +44,26 @@ func init() {
4344 RootCmd .PersistentFlags ().StringVarP (& cwd , "cwd" , "" , c , "Path to environment file (.env)" )
4445
4546 RootCmd .PersistentFlags ().StringVarP (& envPath , "env-file" , "e" , "./.env" , "Path to environment file (.env)" )
47+ RootCmd .PersistentFlags ().StringVar (& configFile , "config" , "" , "Path to config file (default: ~/.druid.yaml)" )
4648 RootCmd .PersistentFlags ().BoolVar (& ignoreVersionCheck , "ignore-version-check" , false , "Ignore version check between scroll.yaml and scroll-lock.json" )
4749 RootCmd .PersistentFlags ().BoolVar (& ignoreLockfileQueue , "ignore-lockfile-queue" , false , "Skip queuing the lock file" )
4850
4951}
5052
5153func initConfig () {
52- home , err := os .UserHomeDir ()
53- cobra .CheckErr (err )
54+ viper .AutomaticEnv ()
5455
55- viper .SetConfigType ("yaml" )
56- viper .SetConfigName (".druid" )
56+ if configFile != "" {
57+ viper .SetConfigFile (configFile )
58+ } else {
59+ home , err := os .UserHomeDir ()
60+ cobra .CheckErr (err )
5761
58- // Search config in home directory with name ".cobra" (without extension).
59- viper .AddConfigPath (home )
62+ viper .SetConfigType ("yaml" )
63+ viper .SetConfigName (".druid" )
64+ viper .AddConfigPath (home )
65+ }
6066
61- viper .AutomaticEnv ()
6267 viper .SafeWriteConfig ()
6368 viper .ReadInConfig ()
6469}
@@ -68,3 +73,24 @@ func Execute() {
6873 os .Exit (1 )
6974 }
7075}
76+
77+ func LoadRegistryStore () * registry.CredentialStore {
78+ var registries []domain.RegistryCredential
79+ viper .UnmarshalKey ("registries" , & registries )
80+
81+ if len (registries ) == 0 {
82+ host := viper .GetString ("registry.host" )
83+ user := viper .GetString ("registry.user" )
84+ password := viper .GetString ("registry.password" )
85+
86+ if host != "" {
87+ registries = append (registries , domain.RegistryCredential {
88+ Host : host ,
89+ Username : user ,
90+ Password : password ,
91+ })
92+ }
93+ }
94+
95+ return registry .NewCredentialStore (registries )
96+ }
0 commit comments