Skip to content
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

Add option --sort/--order #25

Open
don-rumata opened this issue Dec 18, 2023 · 3 comments
Open

Add option --sort/--order #25

don-rumata opened this issue Dec 18, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@don-rumata
Copy link

Hi. Can you add an option to sort columns in a table?

Now:

curl --silent http://<my-repo-in-intranet>/apt/debian/dists/stable/main/binary-amd64/Packages | /usr/local/bin/jc --pkg-index-deb -p | /usr/local/bin/jp "sort_by([], &package)[].{package: package, version: version, homepage: homepage}"  | /usr/local/bin/jtbl --markdown
| homepage                                       | package      | version    |
|------------------------------------------------|--------------|------------|
| https://schollz.com/software/croc/             | croc         | 9.6.6      |
| https://github.com/jgraph/drawio               | draw.io      | 22.1.2     |
|                                                | ifcplugin    | 3.1.1.0    |
| https://github.com/kellyjonbrazil/jc           | jc           | 1.24.0-1   |
| https://github.com/kellyjonbrazil/jtbl         | jtbl         | 1.6.0-1    |
|                                                | naps2        | 7.2.1      |
|                                                | pandoc       | 3.1.11-1   |
| https://rclone.org                             | rclone       | 1.65.0     |
|                                                | scenebuilder | 21.0.0     |
| https://github.com/ansible-semaphore/semaphore | semaphore    | 2.9.37     |
| www.hamrick.com                                | vuescan      | 9.8.22.0-0 |

How i want:

jtbl --markdown --order=package,version,homepage
| package       | version       | homepage                                       |
|---------------|---------------|------------------------------------------------|
| croc          | 9.6.6         | https://schollz.com/software/croc/             |
| draw.io       | 22.1.2        | https://github.com/jgraph/drawio               |
| ifcplugin     | 3.1.1.0       |                                                |
| jc            | 1.24.0-1      | https://github.com/kellyjonbrazil/jc           |
| jtbl          | 1.6.0-1       | https://github.com/kellyjonbrazil/jtbl         |
| naps2         | 7.2.1         |                                                |
| pandoc        | 3.1.11-1      |                                                |
| rclone        | 1.65.0        | https://rclone.org                             |
| scenebuilder  | 21.0.0        |                                                |
| semaphore     | 2.9.37        | https://github.com/ansible-semaphore/semaphore |
| vuescan       | 9.8.22.0-0    | www.hamrick.com                                |

@kellyjonbrazil
Copy link
Owner

I'll take a look at this - it might not be too hard to do.

@kellyjonbrazil kellyjonbrazil self-assigned this Apr 2, 2024
@kellyjonbrazil kellyjonbrazil added the enhancement New feature or request label Apr 2, 2024
@kellyjonbrazil
Copy link
Owner

kellyjonbrazil commented Apr 4, 2024

Playing around with this and I thought I had added a fix to preserve order even when resizing back in v1.4.0:
#7

This seems to be working for me - If I specify the order via jq or similar then it keeps that order. Yet the example you have doesn't seem to be doing this:

% jc -a | jq '[.parsers[0:10][] | {name,version,details,description}]' | jtbl -m
| name           |   version | details                 | description                               |
|----------------|-----------|-------------------------|-------------------------------------------|
| acpi           |      1.7  |                         | `acpi` command parser                     |
| airport        |      1.5  |                         | `airport -I` command parser               |
| airport_s      |      1.6  |                         | `airport -s` command parser               |
| apt_cache_show |      1.0  | Using the rpm-qi parser | `apt-cache show` command parser           |
| apt_get_sqq    |      1.0  |                         | `apt-get -sqq` command parser             |
| arp            |      1.12 |                         | `arp` command parser                      |
| asciitable     |      1.2  |                         | ASCII and Unicode table parser            |
| asciitable_m   |      1.2  |                         | multi-line ASCII and Unicode table parser |
| blkid          |      1.6  |                         | `blkid` command parser                    |
| bluetoothctl   |      1.1  |                         | `bluetoothctl` command parser             |

% jc -a | jq '[.parsers[0:10][] | {name,version,description,details}]' | jtbl -m
| name           |   version | description                               | details                 |
|----------------|-----------|-------------------------------------------|-------------------------|
| acpi           |      1.7  | `acpi` command parser                     |                         |
| airport        |      1.5  | `airport -I` command parser               |                         |
| airport_s      |      1.6  | `airport -s` command parser               |                         |
| apt_cache_show |      1.0  | `apt-cache show` command parser           | Using the rpm-qi parser |
| apt_get_sqq    |      1.0  | `apt-get -sqq` command parser             |                         |
| arp            |      1.12 | `arp` command parser                      |                         |
| asciitable     |      1.2  | ASCII and Unicode table parser            |                         |
| asciitable_m   |      1.2  | multi-line ASCII and Unicode table parser |                         |
| blkid          |      1.6  | `blkid` command parser                    |                         |
| bluetoothctl   |      1.1  | `bluetoothctl` command parser             |                         |

I can still add an option for this, but it seems that this should work as a workaround. Is there something different about your example? (e.g. is jp not keeping the order specified?)

@don-rumata
Copy link
Author

The jp is part of the jmespath.org project. It is used in Ansible. I use it because it's convenient. Adding the --order option would probably help those who do NOT use jp/jq.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants