Day ??? of learning go. Building cli apps

Shem Maiwuya - Aug 16 - - Dev Community

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

. .