-
Notifications
You must be signed in to change notification settings - Fork 343
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
Export rules via dbus #1212
Export rules via dbus #1212
Conversation
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #1212 +/- ##
==========================================
+ Coverage 65.92% 66.04% +0.12%
==========================================
Files 50 50
Lines 8070 8214 +144
Branches 925 961 +36
==========================================
+ Hits 5320 5425 +105
- Misses 2750 2789 +39
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Your approach looks good. I have only one comment.
dunstctl
Outdated
@@ -31,6 +31,7 @@ show_help() { | |||
history with given ID. | |||
is-paused Check if dunst is running or paused | |||
set-paused [true|false|toggle] Set the pause status | |||
rules Displays configured rules (in JSON) |
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 know the history command already formats in json by default, but I'm wondering if it's not better to format in human-readable format by default and allow for a json toggle.
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.
This should be easily feasible.
My current idea is to have:
rules (as-json|human-readable) Displays configured rules
with human-readable
being the default when omitted. I don't know for sure, what's the correct notation for denoting an optional argument (or should it be mandatory, though I think it would be nice to have a default for interactive usage) and just used parentheses as an example.
How should the human-readable form look like? One could just emit ini-style information, basically recreating the original input.
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 would prefer to use an argument like --json
for json output. And it should definitely not be required, for the reason you mentioned.
Optional commands are put in [square brackets].
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 don't know what the best human-readable output is, but I would just look at what's easy to create. On second thought, the pretty json output might be good enough as well
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 currently don't have a good test setup to see, so you'll have to judge for yourself what's best
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.
Sure, I can do --json
as well. I just wanted to be consistent how other commands are used.
Optional commands are put in [square brackets].
Yes, that's how I would've expected it as well, but the usage output doesn't use it this way consistently. history-pop
and history-rm
look the same, but just history-pop
uses it as an optional argument. set-paused
and rule
also use them for mandatory arguments.
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.
Sure, I can do
--json
as well. I just wanted to be consistent how other commands are used.
You don't have to do it just because I mentioned it. Only if you think it's a good idea. Consistency between different commands is also nice.
Optional commands are put in [square brackets].
Yes, that's how I would've expected it as well, but the usage output doesn't use it this way consistently.
history-pop
andhistory-rm
look the same, but justhistory-pop
uses it as an optional argument.set-paused
andrule
also use them for mandatory arguments.
Oh that's a little bit weird. You would only need one of these commands. You can fix that in a separate PR if you want
Please add some tests as well. Our dbus interface is currently very well tested |
These shell completions look very promising. There's so many exciting things you can do with it 😄 |
d93582c
to
466267e
Compare
466267e
to
d01cbd7
Compare
Let me know if you'd like me to give it another round of review |
Are you planning to finish this PR? No pressure, you don't have to. But the feature seems cool |
d01cbd7
to
eaaedd9
Compare
Yes, I will try to finish this, though I cannot give a timeline when this will happen. Hopefully, within the next two weeks I will find some time to work on this (and the other PR). |
eaaedd9
to
a733909
Compare
@fwsmit I've implemented a human-readable output as well. If you agree with this, I'd continue to look into tests and also add all the other missing fields to both calls. Edit: |
f63eebd
to
6c5991d
Compare
dunstctl
Outdated
|| die "Dunst is not running." | ||
;; | ||
*) | ||
die "Unknown format \"${2}\". Please use either \"as-json\" or \"human-readable\"." |
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.
This help message is outdated
With the human readable printing I was not thinking to put it over dbus. Dbus is meant to be a stable interface, where as the human readable output could change at any time. I would prefer it if the dbus output was converted to a human-readable output by the script. The human-readable part is also just an idea. If you think it's readable enough from the json output, or that it's not necesary at all, you can also drop it.
Yeah, the docker images should probably be updated to remove EOL distro's EDIT: I see that you've made a PR for that already :) |
I could try to come up with some jq magic here as well. But then I think, that jq should be made a (at least) optional dependency of this project. The completion for zsh already uses it unconditionally and also some other scripts in contrib rely on it. I'm also fine with dropping a human-readable variant as of now and maybe add it later on when there's an actual need for it. Edit: Just one note on the dropping it now and adding it later: when the default behavior of Edit2: I've implemented the human-readable variant using jq. |
1f98aa8
to
5468661
Compare
I've added some simple test. I hope that is enough and not all branches need to be tested separately. Btw. none of the methods in the Another note, I assume the call to |
@fwsmit: Do you consider having a specified order in the output of the JSON important (currently I'm listing filter rules first and then the adjusted values). I could shorten the code quite drastically by using |
4ecf35c
to
63e48d4
Compare
No, order is not very important. It would help a bit with finding the rule in the settings, but not neccessary. As you said, it should not be relied on, so it can be changed in the future if it's needed |
if (r->set_stack_tag) | ||
g_variant_dict_insert(&dict, "set_stack_tag", "s", r->set_stack_tag); | ||
if (r->override_pause_level != -1) | ||
g_variant_dict_insert(&dict, "override_pause_level", "i", r->override_pause_level); |
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.
In this function, is it not possible to use the data in settings_data.h to programmatically fill the dictionary? All rules in the settings data struct have a non-zero rule (except probably for the first one, if that's a problem that's fixable).
This would make it more easy to maintain. Otherwise it's easy to forget to add it here after adding a rule. If you have idea's for how to do this, please let me know. Then we can discuss if it's worth doing.
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.
My knowledge of C is rather limited, but if I got you right, this would mean compile time code generation, which would mean using macros. I'm not 100% sure on this, but I would highly doubt, that this is possible. Run-time code generation via reflection is not possible in C AFAIK.
My (maybe overly simplistic) approach: just write some comment to the definition of rule to remind the implementer to add it to dbus_cb_dunst_RuleList
as well.
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.
Okay, could you then add some documentation to settings_data.h?
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.
maybe I can make it automatic when I refactor rule parsing. for now it is fine though
8d03d0a
to
db6b9bf
Compare
The intention is to have a way to get all configured rules.
This can be re-used to retrieve other pairs of information (e.g. history id message could be helpful as well).
9802037
to
dd3bc2a
Compare
Everything looks fine. Maybe you could add dunstctl rules to the manpage.
not sure what you mean by that |
This is outdated from the time when the output just consisted of some assorted fields. But I will adjust the other shell completions as well as add the new subcommand to dunstctl's man page. |
dd3bc2a
to
414d5d2
Compare
I've updated the man page as well as some completions. I've tested the bash completion (and found some issues which I will fix in another PR) but the ones for zsh are dry-coded (and thus kept minimal). |
414d5d2
to
623ae02
Compare
The old JSON formatted variant is now reachable with the `--json` flag.
623ae02
to
30b83c4
Compare
As noted in #1209 a completion for
dunstctl rule
is currently not feasible due to missing information about which rules exist. This PR proposes to add a new DBus method to list all configured rules and use this information for a proper completion.NB: Completion for bash and zsh will be adjusted when this approach is considered okay. Also, I'd add more information about the rules in the response in this case.