DEV Community

Shem Maiwuya
Shem Maiwuya

Posted on

Day ??? of learning go. Building cli apps

Why cli??

I have always had a preference for command line interface (CLI) and terminal user interface (TUI) tools over their graphical user interface (GUI) counterparts. This project, aptly named "Phraser" (no apologies for the poor naming), is a command line application designed to manage wallet seed phrases for crypto wallets. I developed this application to create a more convenient way to manage the seed phrases for my crypto wallets.
It creates a directory and stores the phrases in encrypted JSON files. You can then move the JSON files and store them anywhere you want.

Why go?

To enhance my skills, I chose to rewrite a project I had previously written in Python using Go. Unlike the Python version, which requires a multitude of dependencies to be installed, the Go version can be compiled into a single binary, making it more portable and less cumbersome. Additionally, Go is known for its blazing speed(I couldn't resist:))

Tool used

  • Go v1.22.5(of course)
  • Cobra-cli

Installation

You can find a precompiled binary on the releases page of the GitHub repository(link at end of article).

Manual Installation

If you prefer, you can clone the repository and install the dependencies to test it out.
The instructions are in the Readme in the GitHub repository, but I will still highlight them here.

Usage

Phraser is easy to use with a set of straightforward commands. Here's a basic overview:

   phraser [command] [flags]
Enter fullscreen mode Exit fullscreen mode

Commands

  • completion: Generate the autocompletion script for the specified shell.
  • create: Creates a wallet in your store.
  • gendoc: Generate Markdown documentation for all commands.
  • get: Retrieves data stored in a wallet.
  • init: Initializes a store.

Options

  -a, --amount int      amount of phrases to be inputted
  -h, --help            help for phraser
  -s, --store string    name of the store to access
  -t, --toggle          Help message for toggle
  -w, --wallet string   name of the wallet to be created
Enter fullscreen mode Exit fullscreen mode

Examples

  1. Initialize a new store:
   phraser init --store myStore
Enter fullscreen mode Exit fullscreen mode
  1. Create a new wallet:
   phraser create --store myStore --wallet myWallet --amount 12
Enter fullscreen mode Exit fullscreen mode
  1. Retrieve a wallet's seed phrase:
   phraser get --store --wallet myWallet
Enter fullscreen mode Exit fullscreen mode

Conclusion

This project taught me a lot about Go-like encryption/decryption, file handling, and also the cobra-cli for building CLI apps. Any feedback and corrections are appreciated.
The source code can be found here

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay