Skip to content

Conversation

@lumtis
Copy link
Contributor

@lumtis lumtis commented Feb 16, 2021

-c/--config specifies a custom starport config file for the serve command

@lumtis lumtis linked an issue Feb 16, 2021 that may be closed by this pull request
@lumtis lumtis marked this pull request as ready for review February 16, 2021 16:31
@lumtis lumtis requested review from fadeev and ilgooz as code owners February 16, 2021 16:31
@lumtis
Copy link
Contributor Author

lumtis commented Feb 16, 2021

Provide only the file name instead of the file path. This is more convenient because fswatcher has the path of the project as a workdir and we must use it to watch for config changes

// ConfigName specifies a custom config file to use
func ConfigName(configName string) Option {
return func(c *Chain) {
c.options.ConfigName = configName
Copy link
Member

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.

Copy link
Contributor Author

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

@ilgooz
Copy link
Member

ilgooz commented Feb 17, 2021

Provide only the file name instead of the file path. This is more convenient because fswatcher has the path of the project as a workdir and we must use it to watch for config changes

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.

@lumtis
Copy link
Contributor Author

lumtis commented Feb 17, 2021

Provide only the file name instead of the file path. This is more convenient because fswatcher has the path of the project as a workdir and we must use it to watch for config changes

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 filepath.Rel for the fswatcher issue. If this doesn't work and need a more complex solution I would prefer to rename the option --config-name and track the issue since we initially need this feature to test IBC applications

@ilgooz
Copy link
Member

ilgooz commented Feb 17, 2021

We can first run path := filepath.Abs(custumConfigRelOrAbs) and check if filepath.IsAbs(path) before joining paths in fswatcher, if it is, we don't need to join them.

@lumtis
Copy link
Contributor Author

lumtis commented Feb 17, 2021

Nevermind I didn't notice this logic is from our side. It's easy to fix then

Copy link
Member

@ilgooz ilgooz left a 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?

@lumtis
Copy link
Contributor Author

lumtis commented Feb 17, 2021

starport/ui/dist-go/statik/statik.go is automatically updated when running gofmt do you think it's a problem?

[EDIT] added ui to skipped dir for golint so no more problem

@lumtis lumtis requested a review from ilgooz February 17, 2021 09:03
fadeev
fadeev previously approved these changes Feb 17, 2021
Copy link
Contributor

@fadeev fadeev left a 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.

Copy link
Member

@ilgooz ilgooz left a 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 {
Copy link
Member

@ilgooz ilgooz Feb 17, 2021

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).

}

// AppBackendConfigWatchPaths returns the files to watch for config changes
func (c *Chain) AppBackendConfigWatchPaths() []string {
Copy link
Member

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.

func (c *Chain) Config() (conf.Config, error) {
path, err := conf.Locate(c.app.Path)
if c.options.ConfigFile != "" {
return conf.ParseFile(c.options.ConfigFile)
Copy link
Member

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
Copy link
Member

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}.

Copy link
Contributor Author

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)))
Copy link
Member

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.

Copy link
Contributor Author

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

@lumtis
Copy link
Contributor Author

lumtis commented Feb 17, 2021

Thank for the review I check this.
The only problem in the solution is we currently use the default hardcoded config if config.yml is not found while we should return an error if the provided config doesn't exist

@lumtis lumtis requested review from fadeev and ilgooz February 18, 2021 10:07
Copy link
Contributor

@fadeev fadeev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

Copy link
Member

@ilgooz ilgooz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ilgooz ilgooz merged commit c97bd6c into develop Feb 18, 2021
@ilgooz ilgooz deleted the feat/config-option branch February 18, 2021 12:09
Jchicode pushed a commit to Jchicode/cli that referenced this pull request Aug 9, 2023
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(serve): adding -c/--config flag

4 participants