-
-
Notifications
You must be signed in to change notification settings - Fork 437
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
Adding support for reading options from a config file #317
Conversation
Hi @kmoschcau, Thanks a lot for the PR, it seems very promising! Sadly I don't have much time for open-source at the moment but I hope that I will be able to do your review during the next week. Sorry for the delay, |
Hi @Peltoche and @meain. I will rather unexpectedly have a lot of free time on my hands for at least the next two months. I have been thinking about this before, but now I have one more reason to offer this: I would like to offer my help as a maintainer for lsd, if you would have me. I would also be entirely fine, if I would become the code owner for the configuration file and command line args part of the application. Just give me a shout what you think of this. :) |
Hi @kmoschcau , I have finally some time this week-end to check you PR and this is a beautiful one! I don't have any comment on your code because all seems good to me: good comments, a lot of tests, clear code, etc. I fetch the code and run some tests locally.If everything is good we will merge it as soon as all the tests are green. |
If all your PR are as good as this one it will be with pleasure that I will add you as a codeowner. But before that I think that you should go through the PR system for the next few issues in order to ensure that our visions and way of working is aligned. @meain, what do you think of it? |
Sounds reasonable to me. And I am glad you like the PR. Once it gets merged, I think I will have a look at either implementing configuration files on Windows or adding some configurable color schemes. |
That sounds like a plan. We could always use more people on board. |
Hey, I found few small issues. Seems like
|
Oh yeah, that combination (or not combination) of blocks and list is a no go. And I agree it should ignore the blocks setting when list is not specified. (It allows blocks to be configured in the config, but grid be specified as format for some calls.) If I remember I might have thought the core program itself would ignore blocks when the list or tree format is not specified. If it does not do that, then I will make the config just set it to name only. And I can have a look at writing some warnings to STDERR for unknown names in the config and/or command line options. Edit: I'm going to merge the current master into my branch and then go about improving the above mentioned points. |
@meain I remembered wrong. I actually did handle the one per line format correctly, previously. But only if they are specified as multiple occurences. (i.e.: Just for future reference, because this might be confusing in the future when dealing with clap: |
Alright I am done with adding the warnings to stderr. I also added an additional option to disable reading and checking the config file. That should help with the integration tests being independent from whatever config you have lying around. I did not however add integration tests yet to check that those error messages actually get printed. I only tested that by hand so far. And it also seems I have to merge master again. I'll do that right away. |
Master is merged, clippy complaints have been fixed. (I was not able to install clippy for a while now, can you tell? :D) |
Hey, sorry that this is taking a while to get merged in. I have been super busy lately. I am hoping to get to it this weekend. I was going through your initial comment. The idea of taking the last argument in case of multiple arguments is so that if they have an alias defined, that could be overridden when actually calling the command. We will in any case have to atleast have some basic documentation in the readme. |
Hey, had some time and went through the PR. Just a few points I would like to check with you and also a few fixes. I kinda dumped my notes here, so feel free to ask me if you need any clarifications. Discuss
Fixes
Good to have
|
For anyone trying out this branch, here are the config options. The config file is at color: never # auto, always, never
layout: grid # oneline, grid, long
size: short # default, short, bytes
total-size: false # true, false
indicators: false # true, false
no-symlink: false # true, false
icons:
when: auto # auto, never, always
theme: unicode # unicode, fancy
date: relative # date, relative, custom(+...)
display: almost-all # all, almost-all, ...
sorting:
reverse: false
column: time # time, size, name
dir-grouping: none # first, last, none
blocks: # name, size, permission, user, group, date
- name
- size
ignore-globs:
- .git
- .cache |
Could you explain a bit more what you mean by that? I don't quite get it.
My intent was to include everything that can be specified by command line options. Someone somewhere always ends up using something as a default.
That was missing a line, I fixed that with https://github.com/kmoschcau/lsd/commit/f64f8098788b87db638f6481058b7de4e89e6223
This is already supported, but the syntax is icons in the config file. My current approach would be to implement something similar to the XDG dir spec ourselves for Windows. I can do that if that is the route we want to go, but that is going to take a while. But it would be faster than completely implementing our own config search solution.
That sounds reasonable to do, but shouldn't that be done as a separate enhancement once we actually add sorting by multiple columns?
I agree that this would be better design. Though changing this would require a rewrite of the drawing code as well and that is out of scope for this merge request in my opinion.
I can add this in the scope of this change request, if you guys want to have it now. Otherwise I would add this later.
If you mean invalid values for options, it already does that. I did not have it print out errors for unknown options, because this makes it easier to add things in the future and have it be backward compatible. If we want to make this more strict, then I can add that. In general I wanted to make further merge requests later for adding new options, mainly the theme customization. I just want to get this in first, to make future merges easier. Edit: The multiple command line options and taking the last value is something I will have to look at. It's weird that clap doesn't offer that on its own. |
From what I understood, you are looking up if keys exist, but I was thinking that it might be better to have a struct defined and serialize into that. But since this is not a rigid spec(as in items are optional) I am not sure if this is the right way to go.
Huh, weird. It could not find any code related to it. Just in case, I was talking about supporting both icons: never and icons:
when: never
I am not entirely sure about the situation. How bad would it be to hardcode a path for windows to begin with, just maybe substitute username in it?
That works, just thought I would mention
From what I am assuming, a user would like to specify the blocks which they would like to have enabled when using long mode. The current setup just displays blocks without long which kinda messes up the output. What I meant was that we should only consider blocks if long is mentioned. With the current setup, if they have to customize their blocks they will either have a broken output or will have to only view the output in long format always. What I am thinking is more like a check in
What I was thinking was more in the line of giving a warning(to stderr) if a config option they added is not supported.
|
I looked through the
Now I understand what you mean. My instinct would be to rather change the colors option to be this instead: color:
when: never I am a bit hesitant to provide different syntaxes at the same time to configure the same thing. It's bound to be confusing. But it would not be hard to change it to your solution and have it accept both. We could use it as a kind of shorthand, since we can't have both versions in the same file anyway, the YAML spec just doesn't allow duplicate keys on the same level.
That would be fairly easy I think. We can't really implement the entire XDG spec easily in Windows anyway, because the dir structure is that different. I will have a look at only using XDG when we are on a unix system.
Yes you are right about that. This behavior makes more sense in light of a config file. I will then use
I can add something like that, but it just occurred to me, that I then have to "consume" options I evaluated and once I am done with the known options, see if there are any left. I will look into it, but I am not sure how feasible it is. |
I think I just found a better solution to get our config file placed. I just found this crate: https://github.com/dirs-dev/directories-rs |
This sounds good
Yup, looks good.
This is a good to have and could be added in a future PR too. There is a small issue with this. It seems to give |
Hmm I don't really see a way to make In the latter case this will take a bit of work if we want to cover the hierarchical nature of the XDG spec as well. Also I don't own a Mac to test that on. |
This is what |
I implemented blocks only being considered along with the "long" option. Though looking at the current behavior, I am not entirely sure that this is what we want. I propose we change a few things in behavior:
The more I think about this, the more I think it would be a good idea to be able to configure separate blocks for each layout. Edit: I just discovered that the proposals will have to wait, because of the way the grid drawing code works right now. |
Alright! I implemented the use of the I think that should now cover everything that was still to do and shouldn't be broken off into another PR. |
Actually, I just remembered that the custom date format is still not supported in the config. I will have a look at that tomorrow when I have the time. Optionally also putting the configuration of the command line args into the flags module is something left to be done as well. |
I am sorry nothing happened here for so long. Other things took over my spare time. I will see what I can do the coming weekend. |
I think I figured out now why moving the flag definitions to the flags submodules is giving me so much trouble and why the error messages between RLS and the compiler were conflicting. The include macro for |
@Peltoche @meain I think I am done with the code. I added the date validation plus added tests for it for both the command line and config file parsing. The only thing left now is writing user documentation. I would also like to treat the implementation of themes as a separate pull request. Do you guys have any specific expectation of the format of the config documentation? I get the feeling that all of this into the readme can very easily blow it up quite a bit. I also noticed that there are no man pages yet, maybe this could go there at some point. |
Hey @kmoschcau , really sorry that this is taking a while. I have been pretty busy lately. |
I guess we could give man pages a go. Although I think we should have a some basic info about it in the readme anyways. A lot of people does not even look into the man pages a lot of the time. |
Hey, I don't think the blocks piece is working anymore. Also, I think for blocks maybe we could do something like |
Hi again, I was a bit busy so I didn't have that much time to work on this until now. I just merged master into this. As for the long blocks, the I will now write a section about the config file in the readme. |
@meain You were actually right, setting the blocks via the config seems to have broken. I will have a look into it. |
Alright! This should now fix everything and add documentation and with that check off everything that was still left to do for this merge request. |
Hey, there seems to be conflicts with master. Could you rebase it on top of current master. |
@meain It might be that Github got confused because I did two force pushes in a row, but when I try to merge locally, there are no conflicts. I just triggered Github again with an empty amend and force push, maybe that resolves it. Or do you mean you guys require a rebase instead of a merge commit? |
@kmoschcau Yeah, I believe you'll have to a rebase on top of current master. |
That will take a while. I will have to fix the same conflicts up to 31 times then. Are you sure you can't just do a merge commit? |
As of now, there is a restriction on the repo that merge has to happen via a rebase. |
@kmoschcau The concept is still new to me, but https://git-scm.com/book/en/v2/Git-Tools-Rerere https://git-scm.com/docs/git-rerere https://medium.com/@porteneuve/fix-conflicts-only-once-with-git-rerere-7d116b2cec67 |
# Conflicts: # Cargo.lock # Cargo.toml # README.md # src/app.rs # src/core.rs # src/display.rs # src/flags.rs # src/meta/mod.rs # src/sort.rs # tests/integration.rs
I had a look at |
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.
Hey, sorry that you had to blow out the commit history because of the rebase.
There is this one thing I would like you opinion on, but other than that I think we are more or less good to go.
OK I changed the option. |
|| matches.is_present("oneline") | ||
|| matches.is_present("inode") | ||
|| matches!(matches.values_of("blocks"), Some(values) if values.len() > 1) | ||
// TODO: handle this differently |
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.
Hey, anything you were planning to change?
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.
@meain maybe but that is more something that could use some redesigning on how the logic works in general. I wouldn't say that this is part of the scope of this merge request.
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.
LGTM
I just realized I forgot to add this whole feature to the CHANGELOG. I'll open a new pull request for that. |
This is a first implementation of lsd using a configuration file to configure itself in addition to command line flags. This should lay the groundwork for issue #92.
Design
Generally this tries not to change any behavior of the command line options. They always have precedence and the config file values are only used when the corresponding command line option has not been passed. If neither command line option nor a configuration option have been specified, the Default value of the flag is used, which this pull request also implements for each flag.
Changes
The only real change I made is, that for command line options that can be specified multiple times, I always use the first, instead of the last, because this is already defined behavior and has existing methods in clap. On this I would also like to know what the motivation is for this overall, because it is not really explained and can be pretty unexpected for the user, when they can specify multiple values, but only one is ever used.
Caveats and TODOMissing XDG support for WindowsThis is actually a non-goal for the xdg crate according to this issue: whitequark/rust-xdg/issues/28I could also not find another crate, that implements the specification. That leaves us with two options:
either not use XDG config dirs specification (bad option in my opinion)implement the behavior ourselves (writing this as a wrapper as suggested in the issue wouldn't work because of this line: https://github.com/whitequark/rust-xdg/blob/master/src/lib.rs#L1)Missing date format validation in the configuration fileI did not just simply want to duplicate the validation code, that was already written for the command line argument validation. This touches on something that I would like to do with the config file, that I have not been able to so far.I would like to have the command line argument definitions for each option in its corresponding module. I tried doing that by defining functions for each option, which return clap Args. But I have not been able to do that, because trying to use the flags module in the app module, makes the rust compiler complain it can't find the flags module. This might be a cyclic dependency, I am not sure. In any case I never ran into this problem with rust before and couldn't really find a solution for this way to implement it.
Another way to implement it could be to write functions in the flags modules, which take a clap App and just add their options to it. That however would make it necessary to have the code to call those in the main module.