35

Refactor Common CLI Tools

 4 years ago
source link: https://niradler.com/refactor-common-cli-tools/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Command-Line-793x397.jpg

All of us command line fans have our common CLI tools ready for tasks such as jq for json manipulation and curl for creating http requests.

I decided to revisit this tools and refactor them to check if i can make them more flexible and easy to use basically to make them a bit more modern.

This is the tools i created:

1. json-cli-tool - Manipulate json.

2. loop-pipe - Loop over piped data.

3. transform-cli - Transform data types for now just from and to base64.

* just to mention github-kit-cli this is the gkc in the example, basically until Github will finish their cli this is my solution.

gkc search repos -p="q=org:niradler" | jc --path="items" --flatMap="name" --output="newline" | lp "gkc repos getContents --p=\"owner=niradler&repo={v}&path=README.md\" | jc --path=\"content\" | tc --ft=\"base64\" --tt=\"txt\""

Lets breaks this down:

1.  query Github API to get my repos names. (gkc)

2. manipulate JSON response to a flattered list. (jc)

3. loop over the list of repos and run commands for each repo. (lp)

This tools will probably not replace jq, sed, xargs and others but i find them more easy to use so i can save this big guns for more heavy duty.

This is just a POC to test if this path is even a thing, do i really want to refactor an amazing tools that have been battle tests ? not sure about this, but for now im enjoying the easy usage, and testing new capabilities.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK