Skip to content
/ go-cli-skeleton Public template

A minimal but functional skeleton Go CLI application

License

Notifications You must be signed in to change notification settings

Allaman/go-cli-skeleton

Repository files navigation

Go CLI Skeleton

A skeleton/template for writing Go CLI applications.

What's included

  • global logging via zerolog (JSON and human friendly)
  • simple HTTP client via net/http package
  • parsing JSON dynamically via gjson and via unmarshalling with structs
  • reading a file
  • writing to a file
  • reading directory content (optional recursively)
  • reading from stdin (e.g. a Linux pipe)
  • CLI commands, parameters and flags via Kong
  • only main package
  • Goreleaser workflow for automatic multi platform binary releases and Dockerhub images (allaman/go-cli-skeleton:latest or tag)

What's not included

  • sophisticated HTTP client
  • parsing yaml, json, ... files
  • modular file structure (project-layout)
  • tests 😬
go run . -h
Usage: go-cli-skeleton <command>

A minimal skeleton for building CLI apps

Flags:
  -h, --help           Show context-sensitive help.
  -d, --debug          Enable debug output
  -j, --json-output    Log in json format

Commands:
  hello
    default command

  get
    GET query to postman-echo and printing response

  post
    POST query to postman-echo and printing response

  file read --path=STRING
    Read a file

  file write --path=STRING
    Write a file

  dir
    List all files in a directory (and sub directories)

  parse
    GET query to postman-echo and parsing the response

  version
    Show version information

Run "go-cli-skeleton <command> --help" for more information on a command.

TODO

  • GlobalLog improvement
  • include pterm
  • parse yaml/json files