-
Notifications
You must be signed in to change notification settings - Fork 286
config impl (pt.1) #1550
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
base: main
Are you sure you want to change the base?
config impl (pt.1) #1550
Conversation
@spenserblack I'm sorry for pinging you that many times... I opened new PR Current problem is config is not spawning at $XDG_CONFIG_HOME, but it spawns folder. I am not able to check how does config parsed because is not created. Waiting for your answer, thx |
No worries.
Since you're using serde, you should be able to read the config from a string. Or a reader type that uses a string. I'd honestly use that for testing. You can use Since the CLI type implements I'd recommend putting the tests and test config file into |
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.
See review comment. I think it should help you figure out why the config file isn't being created.
i think i should write a todo with what are my plans on customisation with config config sample:
|
Nah, we won't get any good customization if we just parse config as CLI arguments. I reverted all commits I am looking forward to CrabFetch approach. All customisation made by configuration file, and CLI just lets you some minimal settings. @spenserblack what's your opinion on that? |
Could you explain this a bit more? You hint at overriding logos per-language in #1550 (comment), which wouldn't work if config and CLI are identical. Is that the main issue, or are there others?
Each repository is different, and can require different options. For example, if a repository has a logo, show that with |
OK, I've just reread the idea that was documented in #745. I had kind of forgotten the original intent of that issue 😅 I've noticed that the original issue body was mainly focusing on display configuration options. This makes sense to me, since those are the types of things that I'd likely only want to set once, not per-repo. Also, some options would be kind of awkward to set via the CLI, like if I was trying to set Nerd Font icons for the info lines. So, yeah, I'm backtracking on the config file being a 1:1 with the CLI. Instead, we should focus on a limited set of options that we're very confident would only be set once, regardless of repo. And also some options that may work best in a config file instead of as CLI arguments. @o2sh Thoughts? |
Those could be key-value separator, number separator, nerd-fonts switch and natural colors (use colors set by terminal) switch (to be implemented). Im working on those and possibly finish in just few hours. |
That's going to be caused by clap, the library for argument parsing. It's reading the next argument after There's perhaps an option that would force clap to take whatever argument is next, regardless of format. |
AYO I MADE BASE FOR CONFIG!!1! |
@spenserblack I got one annoying error with config file - values MUST be set there, otherwise onefetch is crashing |
I think the easiest thing to do would be to just wrap them all in Also, ideally, let's not remove options from the CLI. Here's roughly how shared options should be resolved. let opt = cli.opt.or(config.opt).unwrap_or(default_opt); Check out the huge amount of helper methods defined on |
i dont really think someone would like to override such things like separators from CLI by the way, check latest commit, i did wrap values on Option, but code seems kinda idiotic imo |
@spenserblack i could not really find why ":" is hardcoded as separator, do you have any ideas? |
tests/snapshots/repo__repo.snap
Outdated
"numberSeparator": "Dot", | ||
"separator": "->" |
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.
These probably don't need to be in JSON outputs (or other machine-readable outputs).
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.
I could not find how should I remove it from output as rustc complains about "missing field"
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.
I think serde has an attribute to tell it to ignore when converting to JSON, YAML, etc.
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.
It is (serde(skip)) but this will prevent from writing default value in config
@spenserblack I need some help with Tera for per-language configuration field. It's very first time working with generators and for now I have no clue how could I implement those. Maybe there're already some references could help me? If so, may you show them or at least send link to documentation? thx |
These are probably what you need: Could you tell me what you're planning to write that involves writing with tera instead of Rust? I don't think you need to unless you're iterating over language entries. |
Sorry for late answer
That's exactly what I planned to implement. As you could see in my "todo", it contains custom image/ascii logo fields on every language. I don't want to write 100+ identical structures and implementation. I investigate on documentation and onefetch source code so possibly we will have something ready to merge really soon |
Lol I think i implemented the most useless feature imaginable. Shall I revert commit or better keep it? |
@spenserblack I really need your review on tests. I never worked with them and don't really understand how should I edit them according to changes. Also I feel like I made many shitcode |
I think it would be wiser to consider this a per-project configuration than a per-language configuration. So, for example, instead of configuring your favorite Rust logo, you would configure your logo for the onefetch repository. But, regardless, we haven't discussed this sort of configuration AFAIK, so I think it's best to save that for later and focus on the basic stuff. You don't need to add all the coolest features all at once. You can add just the simplest config that supports really basic options, and once that's done, we can say "cool, now what's next?" |
Looks like the CI can't run until merge conflicts on At a very quick glance I didn't see anything too bad. Were you concerned about the snapshot test? Or some other tests? |
A minor bug on current state: when running |
It's not a bug but an unimplemented feature, I will workaround it a bit later |
@Sk7Str1p3 Just want to say that the "todo" in your latest changes to the PR body looks perfect 👍 |
@spenserblack i consider reverting all my commits refactoring this pull request to onefetch reimplementation. I found current code non-extendable and hard to edit, especially BuildInfo struct. Also some stuff could be optimised. By the way, i found out new config format, RON. It could be also candidate to be config format, as more native to rust? Now, I need you to confirm or deny. Waiting for answer... |
I wouldn't really use RON unless you can expect users to almost entirely be Rust developers. I think TOML is a happy medium between "easy to use" and "familiar to the Rust ecosystem."
For now, I think just focus on the configuration options that are already easy to work with (so the things that are also configurable via CLI). Adding configuration for more difficult things can then be worked on individually, instead of stressing on how to add a bunch of difficult config options at once. But if you have ideas for optimization, feel free to share 🙂 |
Goals
Implements advanced customisation with config file in toml format. This pull request (pt.1) aims to implement just basic configuration, and pt.2 will go much deeper with it.
Resolves #745
Todo
(requires major changes in logic)
(ascii/pic logo, color, etc..)
upd: i doubt functions 'custom' are really necessary