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

Load config before start() #423

Merged
merged 1 commit into from
May 1, 2021
Merged

Load config before start() #423

merged 1 commit into from
May 1, 2021

Conversation

yykamei
Copy link
Contributor

@yykamei yykamei commented Apr 30, 2021

Close #414

Previously, a config file was loaded within start(), and if the config file is invalid, Zellij was supposed to show a user what's wrong with it. However, since start() starts setting up its terminal with an alternative screen buffer, neither standard output nor standard error could display such an error.

This change intends to address this issue by making Zellij load a config file before start().

In addition, the patch also includes some refactorings:

  • Redefine from_cli_config with TryFrom, which was introduced in Rust 1.34
  • Remove conditional declaration cfg(not(test)) because start() now receive a Config as the third argument
  • Introduce tempfile in order to run tests with actual files
  • Typo?: "Deserialisation" -> "Deserialization"

@yykamei yykamei marked this pull request as draft April 30, 2021 21:59
src/common/input/config.rs Show resolved Hide resolved
src/common/input/config.rs Show resolved Hide resolved
src/common/input/config.rs Outdated Show resolved Hide resolved
src/common/input/config.rs Show resolved Hide resolved
@a-kenji
Copy link
Contributor

a-kenji commented May 1, 2021

Thank you, this is awesome!
This one test shouldn't be a big problem to fix.

Does it make sense to use ConfigResult here, or do you think that this is clearer?

This is just a small thing.

Remove conditional declaration cfg(not(test)) because start() now receive a Config as the third argument

This is quite an awesome side benefit of this change! Now even parts of changes are possible to test reasonably well in the integration tests. Good job!

Introduce tempfile in order to run tests with actual files

Also a good idea!

Typo?: "Deserialisation" -> "Deserialization"

This was a translation error, thanks for catching that.

Just write a message if you get that test fixed and feel its ready for a proper review, then I'll have another look at it.

@yykamei
Copy link
Contributor Author

yykamei commented May 1, 2021

Thanks for your quick review in spite of such a large diff 🙏

One of the tests always fails on GitHub Actions. I'm looking into this, but I'm not sure why it happens...

}
}

let config_dir = opts.config_dir.clone().or_else(install::default_config_dir);
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 misunderstood the behavior of default_config_dir, which I thought would create a directory.
default_config_dir just indicates a possible configuration directory, so it should be called here as the previous implementation.

By the way, as default_config_dir returns Option<PathBuf>, I made opts.config_dir call clone() to match these types. Maybe, I can delete this clone() by refactoring default_config_dir, but it should be done in another PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I misunderstood the behavior of default_config_dir, which I thought would create a directory.
default_config_dir just indicates a possible configuration directory, so it should be called here as the previous implementation.

Yeah, I glossed over that too now. The naming does suggest some sort of creation. I'll put it on my list to try to make the intention clearer.

By the way, as default_config_dir returns Option<PathBuf>, I made opts.config_dir call clone() to match these types. Maybe, I can delete this clone() by refactoring default_config_dir, but it should be done in another PR.

I would love that, as I am also unhappy about the state of default_config_dir, so feel free to open a PR on that, if you want to!

@yykamei yykamei marked this pull request as ready for review May 1, 2021 07:17
@yykamei
Copy link
Contributor Author

yykamei commented May 1, 2021

Please ping me if rebase is required!

Copy link
Contributor

@a-kenji a-kenji left a comment

Choose a reason for hiding this comment

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

Thank you! This is looking good. If you want you can rebase, then I'll merge it.

}
}

let config_dir = opts.config_dir.clone().or_else(install::default_config_dir);
Copy link
Contributor

Choose a reason for hiding this comment

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

I misunderstood the behavior of default_config_dir, which I thought would create a directory.
default_config_dir just indicates a possible configuration directory, so it should be called here as the previous implementation.

Yeah, I glossed over that too now. The naming does suggest some sort of creation. I'll put it on my list to try to make the intention clearer.

By the way, as default_config_dir returns Option<PathBuf>, I made opts.config_dir call clone() to match these types. Maybe, I can delete this clone() by refactoring default_config_dir, but it should be done in another PR.

I would love that, as I am also unhappy about the state of default_config_dir, so feel free to open a PR on that, if you want to!

Previously, a config file was loaded within `start()`, and if the config
file is invalid, Zellij was supposed to show a user what's wrong with
it. However, since `start()` starts setting up its terminal with an
alternative screen buffer, neither standard output nor standard error
could display such an error.

This change intends to address this issue by making Zellij load a config
file before `start()`.

In addition, the patch also includes some refactorings:

* Redefine `from_cli_config` with `TryFrom`, which was introduced in
  Rust 1.34
* Remove conditional declaration `cfg(not(test))` because `start()` now
  receive a `Config` as the third argument
* Introduce [`tempfile`](https://crates.io/crates/tempfile) in order to
  run tests with actual files
* Typo?: "Deserialisation" -> "Deserialization"
@yykamei
Copy link
Contributor Author

yykamei commented May 1, 2021

Thank you. I rebased and squashed commits into a single commit!

@a-kenji a-kenji merged commit e9eccc1 into zellij-org:main May 1, 2021
a-kenji added a commit to a-kenji/zellij that referenced this pull request May 1, 2021
@yykamei yykamei deleted the load-config-before-start branch May 2, 2021 13:04
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.

Let a user know why the configuration is invalid
2 participants