- 
                Notifications
    You must be signed in to change notification settings 
- Fork 570
feat(serve): custom config option #761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| Provide only the file name instead of the file path. This is more convenient because  | 
        
          
                starport/services/chain/chain.go
              
                Outdated
          
        
      | // ConfigName specifies a custom config file to use | ||
| func ConfigName(configName string) Option { | ||
| return func(c *Chain) { | ||
| c.options.ConfigName = configName | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can refactor LocateDefault func to Locate(root string, []string) where []string is usually set as conf.FileNames but when ConfigName option is used it is set as []string{configName}. This might simplify some parts in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LocateDefault has a different purpose, it has a list of file that can be considered as the default configuration then if we find nothing we can properly handle the error to say that we use a default hard coded configuration.
Custom option responds to a different logic, you always have a single file and if you don't find it you always return an error.
I think it's more maintainable to separate the two if we want to change the logic to search for the default configuration in the future
| 
 I think it is kind of expected to be able to provide a relative/abs path when setting a config path flag in a CLI. I beleive it is better to stick with this convention. | 
| 
 I try with  | 
| We can first run  | 
| Nevermind I didn't notice this logic is from our side. It's easy to fix then | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, can we avoid updating starport/ui/dist-go/statik/statik.go  in case it contains an older version of the ui?
| 
 [EDIT] added ui to skipped dir for golint so no more problem | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works with a custom foo.yml config file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Asked for some tweaks. 👍
| // make sure that config.yml exists. | ||
| if _, err := conf.Locate(c.app.Path); err != nil { | ||
| if c.options.ConfigFile != "" { | ||
| if _, err := os.Stat(c.options.ConfigFile); err != nil { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With #761 (review) we don't need a change in this code block as well. It can just call conf.Locate(root, c.options.ConfigFiles).
        
          
                starport/services/chain/chain.go
              
                Outdated
          
        
      | } | ||
|  | ||
| // AppBackendConfigWatchPaths returns the files to watch for config changes | ||
| func (c *Chain) AppBackendConfigWatchPaths() []string { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#761 (review) can eliminate this func as well.
        
          
                starport/services/chain/chain.go
              
                Outdated
          
        
      | func (c *Chain) Config() (conf.Config, error) { | ||
| path, err := conf.Locate(c.app.Path) | ||
| if c.options.ConfigFile != "" { | ||
| return conf.ParseFile(c.options.ConfigFile) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#761 (review) can eliminate this change as well.
| // ConfigFile specifies a custom config file to use | ||
| func ConfigFile(configFile string) Option { | ||
| return func(c *Chain) { | ||
| c.options.ConfigFile = configFile | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding to #761 (review),  c.options.ConfigFile can be conf.FileNames by default and call to ConfigFile with a non-empty string will change it to []string{configFile}.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a bit ambiguous. The option should be a single string, conf.FileNames is an array because you want to have several possibilities of the file name for the default config
| return err | ||
| } | ||
| if config != "" { | ||
| chainOption = append(chainOption, chain.ConfigFile(os.ExpandEnv(config))) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can I think, pass this option anyway even if config path is an empty string but check for an empty string inside chain.ConfigFile to fallback to conf.FileNames.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmmh then we don't use the benefit of this pattern which is to have optional parameters?
Or else we use a positional argument
| Thank for the review I check this. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
* Custom config * Custom config option * Lint * Add test for custom config file * Change option name * SOme naming * Fix test * refacto: specify file name * Lint * Suport absolute paths * Revert statik.go * Lint * Add directory skip for lint * Ilker suggestions * Verifyu config exists * COnfigPath * No config check
-c/--configspecifies a custom starport config file for theservecommand