Using CLI Applications to Increase Efficiency in Work

Using CLI Applications to Increase Efficiency in Work

Daily short news for you
  • For over a week now, I haven't posted anything, not because I have nothing to write about, but because I'm looking for ways to distribute more valuable content in this rapidly exploding AI era.

    As I shared earlier this year, the number of visitors to my blog is gradually declining. When I looked at the statistics, the number of users in the first six months of 2025 has dropped by 30% compared to the same period last year, and by 15% compared to the last six months of 2024. This indicates a reality that users are gradually leaving. What is the reason for this?

    I think the biggest reason is that user habits have changed. They primarily discover the blog through search engines, with Google being the largest. Almost half of the users return to the blog without going through the search step. This is a positive signal, but it's still not enough to increase the number of new users. Not to mention that now, Google has launched the AI Search Labs feature, which means AI displays summarized content when users search, further reducing the likelihood of users accessing the website. Interestingly, when Search Labs was introduced, English articles have taken over the rankings for the most accessed content.

    My articles are usually very long, sometimes reaching up to 2000 words. Writing such an article takes a lot of time. It's normal for many articles to go unread. I know and accept this because not everyone encounters the issues being discussed. For me, writing is a way to cultivate patience and thoughtfulness. Being able to help someone through my writing is a wonderful thing.

    Therefore, I am thinking of focusing on shorter and medium-length content to be able to write more. Long content will only be used when I want to write in detail or delve deeply into a particular topic. So, I am looking for ways to redesign the blog. Everyone, please stay tuned! 😄

    » Read more
  • CloudFlare has introduced the pay per crawl feature to charge for each time AI "crawls" data from your website. What does that mean 🤔?

    The purpose of SEO is to help search engines see the website. When users search for relevant content, your website appears in the search results. This is almost a win-win situation where Google helps more people discover your site, and in return, Google gets more users.

    Now, the game with AI Agents is different. AI Agents have to actively seek out information sources and conveniently "crawl" your data, then mix it up or do something with it that we can't even know. So this is almost a game that benefits only one side 🤔!?

    CloudFlare's move is to make AI Agents pay for each time they retrieve data from your website. If they don’t pay, then I won’t let them read my data. Something like that. Let’s wait a bit longer and see 🤓.

    » Read more
  • Continuing to update on the lawsuit between the Deno group and Oracle over the name JavaScript: It seems that Deno is at a disadvantage as the court has dismissed the Deno group's complaint. However, in August, they (Oracle) must be held accountable for each reason, acknowledging or denying the allegations presented by the Deno group in the lawsuit.

    JavaScript™ Trademark Update

    » Read more

The Problem

As a programmer, I believe that everyone has thought about leveraging lines of code to automate tasks. For example, a JavaScript code snippet written by a programmer to calculate the total amount of money spent on an e-commerce platform, instead of manually adding up each order in a never-ending list.

Automation brings many benefits, the most obvious of which are time savings and reduced errors in repetitive processes. Moreover, if the code snippet I wrote can be shared with others, it's truly a win-win situation.

I also create such code snippets, but instead of calculating order values, they focus on solving common work-related issues. For instance, a code snippet that synchronizes data between two production servers and the development environment of this blog. Because sometimes it's necessary to test new features on real data for safety before deploying them to the "production" environment.

I usually store these snippets in a convenient location, such as the note-taking application of my operating system, so that they can be synchronized across all my workspaces. If I encounter a problem in the future, I can simply open the application, copy the code, and paste it to run. It's brilliant!

That's just a simple example of how to automate repetitive tasks. A few weeks ago, when I was focused on optimizing images for my blog, the problem became more complicated. Copying and pasting, then modifying the content for each task took more time. I realized that such code snippets are only suitable for low-frequency tasks, such as once a day.

At this point, you may already be imagining how to solve the problem for yourself. I know there are many ways to do it, but personally, I chose to create a CLI application to handle everything.

What is a CLI?

A Command-Line Interface (CLI) is a software mechanism that allows you to interact with your operating system through the keyboard. It is the opposite of a Graphical User Interface (GUI).

The strength of GUI lies in its intuitive navigation, such as clicking icons and images to use software applications. However, GUI is not efficient for system administration tasks, especially in virtual or remote environments.

With CLI, you can enter text commands to configure, navigate, or run programs on any server or computer system. CLI focuses on functionality and speed of use.

CLI is a broad topic, but in this article, I only want to discuss the application of CLI in software applications. In simple terms, CLI applications are command-line applications that we type daily in the Terminal. Commands like cd, ls, pwd, etc. can also be considered as software applications that help us perform specific functions.

When to Create a CLI Application?

Let's go back to the image optimization problem that I wrote an article about, Optimizing Image Display with Blur Placeholder and Lazyload There are many steps involved in creating an image suitable for the blog post, but in general, there are two main actions:

First, reformat the image to webp, adjust the image quality, and crop it to the desired size.

Second, upload all the newly created images to R2 and retrieve all the links to them.

If we apply the "copy-paste" method as mentioned earlier, it becomes cumbersome. Therefore, creating a CLI application in this case is reasonable to centralize management and save typing time.

Imagine, my application is called img, and when I want to create all the optimized images, I just need to run:

$ img all path/to/file

Where path/to/file is the path to the original image. After running, the newly created images will be saved in path/to/new/file. At this point, I add another command upload for the action of uploading images to R2:

$ img upload path/to/new/file

Perfect, everything works. But it's not over yet. One advantage of CLI is that it supports parameters (args) and flags. Based on the flags, we can create more options for richer processing.

For example, if I want to upload the images to R2 immediately after they are created instead of running an additional upload command, I can add code for the --upload flag or its shorthand -u:

$ img all path/to/file --upload
# or
$ img all path/to/file -u

Of course, the above is just a hypothesis. A CLI application can do much more depending on each person's approach. So, feel free to customize commands and flags according to your preferences, but make sure they are clear, easy to remember, and easy to use.

How to Create a Simple CLI Application

CLI applications are not limited to any specific programming language. If you are using Golang, search for libraries that support creating CLI applications in Go. Similarly, in Node.js, oclif can help with this. Besides oclif, there are many other libraries that can help you create CLI applications. Take the time to explore them and choose one with a friendly and easy-to-use syntax. Find more libraries at Command-line utilities | awesome-nodejs Public | Github.

oclif is relatively simple to get started with. Just follow the instructions in Introduction | oclif docs, and you will immediately have your own "command."

$ npx oclif generate mynewcli
? npm package name (mynewcli): mynewcli
$ cd mynewcli
$ ./bin/dev.js hello world
hello world! (./src/commands/hello/world.ts)

oclif supports automatic generation of new commands (CLI Generator), flag/argument parsing, testing, autocomplete, and many other features. For more information, refer to Features | oclif docs.

Conclusion

CLI is a software mechanism that allows you to interact with the operating system. While CLI has a wide scope, in this article, we focused on using CLI applications to create software for our own use.

Previously, I used to store commonly used code snippets and simply "copy-paste" them when needed. Creating a CLI application simplifies this process, saving time and effort.

oclif is a library that helps create CLI applications using Node.js. If you are using a different programming language, search for a suitable library.

Premium
Hello

The secret stack of Blog

As a developer, are you curious about the technology secrets or the technical debts of this blog? All secrets will be revealed in the article below. What are you waiting for, click now!

As a developer, are you curious about the technology secrets or the technical debts of this blog? All secrets will be revealed in the article below. What are you waiting for, click now!

View all

Subscribe to receive new article notifications

or
* The summary newsletter is sent every 1-2 weeks, cancel anytime.

Comments (1)

Leave a comment...
Avatar
Ẩn danh1 year ago

đúng là một bài viết hay tôi muốn đọc thêm nhiều bài viết như thế này ưnax

Reply
Avatar
Xuân Hoài Tống1 year ago

Bạn có thể cho phép blog "gửi thông báo" khi có bài viết mới để không bị bỏ lỡ nhiều bài hấp dẫn trong tương lai 🙌