3737 // `cmd.PersistentFlags().AddFlagSet(connection.Flags)`
3838 Flags * pflag.FlagSet = CreateFlagSet ()
3939
40- // Directory is $HOME/config/registry
40+ // Directory is $HOME/. config/registry
4141 Directory string
4242 ErrCannotDeleteActive = fmt .Errorf ("cannot delete active configuration" )
4343 ErrReservedConfigName = fmt .Errorf ("%q is reserved" , ActivePointerFilename )
@@ -100,10 +100,6 @@ func ValidateName(name string) error {
100100 if name == ActivePointerFilename {
101101 return ErrReservedConfigName
102102 }
103-
104- if dir , _ := filepath .Split (name ); dir != "" {
105- return fmt .Errorf ("%q must not include a path" , name )
106- }
107103 return nil
108104}
109105
@@ -199,9 +195,10 @@ func ReadValid(name string) (c Configuration, err error) {
199195}
200196
201197// Read loads a Configuration from yaml file matching `name`. If name
202- // contains a path, the file will be read from that path, otherwise
203- // the path is assumed as: ~/.config/registry. Does a simple read from the
204- // file: does not bind to env vars or flags, resolve, or validate.
198+ // contains a path or refers to a local file, the file will be read
199+ // using name, otherwise the path is assumed as: ~/.config/registry.
200+ // Does a simple read from the file: does not bind to env vars or flags,
201+ // resolve, or validate.
205202// See also: ReadValid()
206203func Read (name string ) (c Configuration , err error ) {
207204 if err = ValidateName (name ); err != nil {
@@ -210,7 +207,11 @@ func Read(name string) (c Configuration, err error) {
210207
211208 dir , file := filepath .Split (name )
212209 if dir == "" {
213- name = filepath .Join (Directory , file )
210+ // If name refers to a local file, preferentially read the local file.
211+ // Otherwise assume name refers to a file in the config directory.
212+ if info , err := os .Stat (file ); errors .Is (err , os .ErrNotExist ) || info .IsDir () {
213+ name = filepath .Join (Directory , file )
214+ }
214215 }
215216 var r io.Reader
216217 if r , err = os .Open (name ); err != nil {
0 commit comments