cli-go

command module
v0.0.0-...-f525e7c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

README

cli-go

Template for Command Line Interface (CLI) tool in Go

Development

Setup for macOS

Install goenv:

brew install goenv

Install Go:

# install go 1.22.5
goenv install 1.22.5

# to install latest Go version
goenv install latest
Work on macOS

Configure project:

source configure.sh

Open the project in Visual Studio Code:

code .
Build
go build ./...
Run
echo "John" > name.txt

./cli-go greet name.txt
./cli-go greet --language es name.txt
./cli-go greet -l bg name.txt

Output:

Hello, John!
Hola, John!
Здравей, John!
Test
go test -v
Generate Docs
godoc

Browse docs:

# this package
open http://localhost:6060/pkg/github.com/swiftsoftwaregroup/cli-go

# all packages
open http://localhost:6060/pkg/
How to create a new project
# create module
go mod init github.com/<username>/cli-go

# add packages
# see: https://cobra.dev
go get github.com/spf13/cobra

touch main.go

Tools:

go install golang.org/x/tools/cmd/godoc@latest

Documentation

Overview

Package main implements a CLI tool for greeting users in different languages.

cli-go is a command-line interface application that allows users to generate greetings in various languages. It reads a name from a file and can produce greetings in English, Spanish, or Bulgarian.

Usage:

The main command of the application is "greet", which takes a file path as an argument and an optional language flag:

cli-go greet [file] [--language language]

Where [file] is the path to a text file containing a name, and [--language] is an optional flag to specify the greeting language (default is English).

Supported languages:

  • English (en)
  • Spanish (es)
  • Bulgarian (bg)

Example usage:

echo "John" > name.txt
cli-go greet name.txt
cli-go greet --language es name.txt
cli-go greet -l bg name.txt

The application uses the Cobra library for CLI structure and argument parsing. It demonstrates basic file I/O, string manipulation, and modular CLI design in Go.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL