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

Add cli option --config-file #459

Merged
merged 10 commits into from
Feb 7, 2021
Merged

Add cli option --config-file #459

merged 10 commits into from
Feb 7, 2021

Conversation

bew
Copy link
Contributor

@bew bew commented Feb 5, 2021

It works! 🎉

I didn't find a documentation for global flags/options, is it currently missing?

I'm not fond of the duplication between wezterm/wezterm-gui/wezterm-mux-server.. But this is a larger problem I think, it shouldn't be solved in this PR.

For the implementation

  • I extracted the existing config load logic to a function that takes a Path, and make it used when the flag is given.

  • I changed the signature of reload (to avoid having reload() and reload_from_path(path) functions), to take a ConfigFileSelection (not sure about the naming), to choose between searching the config file or using a given one.

Copy link
Owner

@wez wez left a comment

Choose a reason for hiding this comment

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

Thanks for taking a crack at this! This is something that I'd use, so I definitely appreciate it!

I think this could be a smaller PR with fewer changes if you follow my suggestion of adding a global to remember the config file path.

wezterm/src/main.rs Outdated Show resolved Hide resolved
wezterm/src/main.rs Outdated Show resolved Hide resolved
wezterm/src/main.rs Outdated Show resolved Hide resolved
config/src/lib.rs Show resolved Hide resolved
config/src/lib.rs Outdated Show resolved Hide resolved
config/src/lib.rs Outdated Show resolved Hide resolved
@bew
Copy link
Contributor Author

bew commented Feb 6, 2021

Thanks for the review! the code is indeed simpler now 😃

I don't know how you prefer to do code reviews, so I didn't marked your comments as resolved, so you can see my answers and mark then as resolved if it is ok for you.

When the config is given explicitely (either using --config-file or via
WEZTERM_CONFIG_FILE), failing to load this file will use the default
config.
Otherwise the config file is searched one by one in a few directories.
@bew
Copy link
Contributor Author

bew commented Feb 7, 2021

Replying to #459 (comment)

I would expect it to fail to load (and fallback to default config?) if the given file is unreadable, no?

Good catch. I think this a good place to introduce a little enum:

enum Item {
   Required(PathBuf),
   Optional(PathBuf),
}

It should be done now! tested locally, it works great!

I didn't it implemented with the enum you suggested though, I found it was quite hard to use in the for loop over paths items.
I'm not fond of the naming of PathPossiblity but don't know what to name it to.. (Item feels way too generic, or PathItem ? but it's weird, looks like a path component.. anyway..)

I hope you like it 😃

@wez wez merged commit c576b9d into wez:main Feb 7, 2021
@wez
Copy link
Owner

wez commented Feb 7, 2021

Thanks!

@bew
Copy link
Contributor Author

bew commented Feb 7, 2021

Thanks!

Youhou, thank you 😊

@bew bew deleted the add-config-file-cli-arg branch February 7, 2021 17:30
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.

2 participants