-
Notifications
You must be signed in to change notification settings - Fork 49
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
feat: Implement toml config for fmt command. #205
Conversation
This implements a config option which can be used to set options for "yr fmt". An example config file is included as "wxsfmt.toml" which currently has everything disabled just to demonstrate the behavior. If any option is not set it will fall back to the default values provided by the "fmt" command which currently match the defaults provided by the library.
This is not ready to be merged yet, but it is at a point where the overall design should be discussed. The idea is to have defaults that can be overridden with the config file, which is toml format. An example config file is: [rule]
indent_section_headers = false
indent_section_contents = false
[meta]
align_values = false
[patterns]
align_values = false I think it is worth breaking up the config file into sections, which will make it easier to write and document. Currently there are three sections:
The idea is to expose the rest of the options in the formatter through the config file, but if we choose to change the format of the config file now is a good time to do that. I'm open to changing names on any of these if you have any opinions on that. |
I like the approach, and the I would also like that users don't need to specify the config file in the command-line (that option can remain), but the program should look for well-known locations looking for a |
Move the config structures and loading to a separate module, so that it can be used by each command. Pass the "fmt" section of the config to the "fmt" command. As we add support for other commands to use the config file we can easily pass their sub-structure into the command. Load the config file from %{HOME}/.yara-x.toml - or whatever the corresponding location is on Windows. The exact format of the config is still to be documented, but now that it is generic and not specific to formatting I've moved the docs to a new file that is more appropriately named.
OK, I've added support for loading it from Turns out the config file format I gave above is total garbage (I misread some stackoverflow post) and this is a much better way to do it:
The above is my current If you think this config format works well I'll update this PR with the actual documentation and then I can go about tackling the rest of the options in discussed in #192. |
I like the latest changes. |
This adds a "rule.indent_spaces" option to the fmt config. It is a u8 where 0 means "use tabs" and any positive integer will use that many spaces per indent-level. While here, document the config file format. I intend to keep updating this documentation as I add more options to the "fmt" command, and also as I extend the config file to work with more than just "fmt".
@@ -212,6 +212,8 @@ pub(crate) enum Token<'a> { | |||
// Non-control tokens | |||
// | |||
Whitespace, | |||
#[allow(dead_code)] |
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.
@plusvic I'm not sure this is the right way to do this.
The config file will be used by the CLI only, not by the YARA-X library as a whole. Every configurable setting in the library is set through some method in `Compiler`, `Scanner` or any of the types exported by the library.
This implements a config options for `yr fmt`. The options reside in a config file at `%{HOME}/.yara-x.toml` - or whatever the corresponding location is on Windows. The exact format of the config file is documented in `docs/YARA-X Config Guide.md`.
This implements a config option which can be used to set options for "yr fmt".
An example config file is included as "wxsfmt.toml" which currently has everything disabled just to demonstrate the behavior.
If any option is not set it will fall back to the default values provided by the "fmt" command which currently match the defaults provided by the library.