Skip to content
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

Refactor config #153

Merged
merged 2 commits into from
Jan 19, 2015
Merged

Refactor config #153

merged 2 commits into from
Jan 19, 2015

Conversation

kytrinyx
Copy link
Member

We only ever do three things from the outside:

  1. Load an existing config, falling back to defaults if it doesn't exist.
  2. Update values on a config.
  3. Write the config to disc.

Everything else is details.

In order to be able to set a fake homeDir on this, the New function delegates to a separate load function. This also allows us to avoid potential race conditions in the tests by not setting ENV variables.

func (c *Config) configure() (*Config, error) {
c.sanitize()

func (c *Config) setDefaults() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

this name does a much better job of communicating what it does. 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, everything seemed a bit tangled before. Or perhaps: both tangled and fragmented. This time around I've kept larger chunks. I think fewer abstractions will be easier to manage.

We only ever do three things from the outside:

1. Load an existing config, falling back to defaults if it doesn't exist.
2. Update values on a config.
3. Write the config to disc.

Everything else is details.

In order to be able to set a fake homeDir on this, the New function
delegates to a separate load function. This also allows us to avoid
potential race conditions in the tests by not setting ENV variables.
@Tonkpils
Copy link
Contributor

This looks good to me, it definitely improves readability and its easier to understand whats going on. 👍

@kytrinyx
Copy link
Member Author

OK, cool. Merging.

kytrinyx added a commit that referenced this pull request Jan 19, 2015
@kytrinyx kytrinyx merged commit e6672ec into master Jan 19, 2015
@kytrinyx kytrinyx deleted the refactor-config branch January 19, 2015 16:36
lcowell pushed a commit to lcowell/cli that referenced this pull request Jan 25, 2015
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.

3 participants