Skip to content

Conversation

@GwynethLlewelyn
Copy link

Hi there,

The stand-alone CLI which I had added on PR #7 got a big revamp.

Besides extending the existing package code to deal with the latest innovations by Tinify, such as support for more file types and a new resizing option, I've also managed to add more comments, clean up the JSON being sent, and properly deal with error codes sent by the API endpoint; additionally, I've introduced a few new features, such as extract (and pass back) the current token count (perhaps, at some point, it might even be possible to avoid making API calls if one's token limit has been reached). I cannot guarantee 100% compatibility with past versions, but it should be close enough.

I gave up on my clumsy attempts to build my own CLI framework, I was wasting too much time and getting nowhere. So, I went back to good, old, faithful urfave/cli, and redid everything from scratch, using version 3 of that package. With a bit of hand-holding by some knowledgeable developers, who pointed out glaring mistakes in my code (thus explaining why "nothing worked" in my previous attempt), I managed to get it to work fine (extra bonus: auto-completion works!).

Since I was mostly going to use this tool for batch processing, I also felt the need to use a more robust logging system, as opposed to just sending fmt.Fprintf(os.Stderr, "..."); after checking a few benchmarks, I've decided to use zerolog in its ConsoleWriter mode — that could later be easily changed if needed. Ironically, it was only after I did everything that I noticed that the zerolog repository includes some neat tricks for CLI apps, which I wasn't aware of. That's for a future version!

As usual, feel free to use or ignore whatever you wish. It's a big PR!

Cheers,

— Gwyn

… because the API requires it!
This is just syntactic sugar for Go to compile the “local” module as if it were the “real” module.
Not even worth a commit.
… but added some info regarding the CPI example, too.
It’s not really used and should probably be abolished.
If error, return is a valid integer with 0. Since we deal with image sizes here, a size of zero is by no means acceptable upstream.
Minor cleaning up bugs required but that’s IT.
… and I forgot all about that
Also: added more debug messaeges
As suggestd by ChatGPT.
… now, there it goes, in spades!
There is still a lot left to fix…
(e.g. for resize with scale, only width OR height can be non-zero, and the missing dimension should be skipped)
Seems to work, according to the tests!
This is just to make it future-proof!
Set in “secret” environment for GiHub Actions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant