Day ??? of learning go. Building cli apps

WBOY
Release: 2024-08-16 16:31:22
Original
1104 people have browsed it

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]
Copy after login

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
Copy after login

Examples

  1. Initialize a new store:
   phraser init --store myStore
Copy after login
  1. Create a new wallet:
   phraser create --store myStore --wallet myWallet --amount 12
Copy after login
  1. Retrieve a wallet's seed phrase:
   phraser get --store --wallet myWallet
Copy after login

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

The above is the detailed content of Day ??? of learning go. Building cli apps. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template