martindstone / pagerduty-cli

A command line interface for PagerDuty
MIT License
91 stars 13 forks source link

Improve readability and simplify the -k flag #43

Open 825i opened 1 year ago

825i commented 1 year ago

So after learning, -k flag combined with --columns= are the two most useful tools in my arsenal.

The problem is that with --columns= I can do like:

columns=id,name,description,summary,time_zone,html_url

but with the -k flag, I need to do like:

-k description -k summary -k time_zone -k html_url

This means my final command looks like:

pd schedule:list -k description -k summary -k time_zone -k html_url --columns=id,name,description,summary,time_zone,html_url


Can we please have the same functionality so I can just write:

pd schedule:list -k description,summary,time_zone,html_url --columns=id,name,description,summary,time_zone,html_url

or even better just:

pd schedule:list -k description, summary, time_zone, html_url

or just:

pd schedule:list --columns=id,name,description,summary,time_zone,html_url

and still get the output:

ID      Name                                    description                                               summary                                 time_zone       html_url
 ─────── ─────────────────────────────────────── ───────────────────────────────────────────────────────── ─────────────────────────────────────── ─────────────── ─────────────────────────────────────────────────
 P47R7L5 1st Line 7-17                                                                                     1st Line 7-17                           Europe/Helsinki https://company.pagerduty.com/schedules/P47R7L5
 P64JBZZ 24-5                                                                                              24-5                                    Europe/Warsaw   https://company.pagerduty.com/schedules/P64JBZZ
 PDFD16Z Amazon Connect Test                     Temporary schedule for testing Amazon Connect             Amazon Connect Test                     Europe/Warsaw   https://company.pagerduty.com/schedules/PDFD16Z
 PT8KV6J AWS Support                             Default AWS Support Schedule.                             AWS Support                             Europe/Warsaw   https://company.pagerduty.com/schedules/PT8KV6J
martindstone commented 1 year ago

Hi @825i, this is something I have struggled with -- the reason why is partly dumb implementation details, because -k is a flag that I implemented and it has some more sophisticated functionality than --columns, which is a flag provided by the framework -- specifically, -k can take JSON paths, and lso you can add columns to the table using -k, then filter rows using --filter, then show only the columns you want to see with --columns -- for example you could include time zone, filter for only America/New_York, and then show only the name:

pd schedule list -k time_zone --filter time_zone=America/New_York --columns name

I am thinking about whether there is a way to further parse the -k flag to get closer to what you're describing. In the meantime though, it might help you to know that you can in fact separate multiple -k flags using spaces -- it doesn't feel intuitive, because --columns uses , while -k uses space, but it does work. For example:

pd schedule list -k time_zone html_url 'escalation_policies[*].summary' --columns id,name,time_zone

Hope this helps, let me know what you think...

martindstone commented 1 year ago

Hi @825i, I finally managed to make the change you were asking for as part of a big refactor for 0.1.7, it's available as an RC now if you want to try it, pd update rc to use the RC, pd update stable good go back to 0.1.6. Let me know what you observe.