Making use of environment variables and a better README

This commit is contained in:
Elia el Lazkani 2020-02-26 19:18:19 +01:00
parent 0d97bc8dcb
commit 202fc60d38
2 changed files with 40 additions and 3 deletions

View file

@ -5,4 +5,41 @@
# Reason # Reason
This project is a journey of learning Golang. This project is a journey of learning Golang.
If you would like to make an MR, please go right ahead, it would be a good learning process for me. If you would like to make an MR, please go right ahead, it would be a good learning process for me.
# Usage
`go-cmw` features a good command-line interface thanks to `kingpin.v2`.
```console
$ go-cmw --help
usage: go-cmw [<flags>]
A small terminal wrapper around the wttr.in weather endpoint.
Flags:
--help Show context-sensitive help (also try --help-long and --help-man).
-m, --metric Display weather in metric
-u, --uscs Display weather in imperial
-M, --meter-second Display wind in m/s
-z, --zero Show the weather now
-o, --one Show the weather for one day
-w, --two Show the weather for two days
-A, --ignore-user-agent Request ignoring the user agent
-F, --follow-link Follow link redirect
-n, --narrow Display weather in narrow view
-q, --quiet Add the quiet flag
-Q, --super-quiet Add the super quiet flag
-N, --no-colors Disable displaying colors (always enabled on windows
-p, --add-frame Add a frame to the output
-T, --mid-transparency Enable mid-transparency (PNG only)
-P, --png Download a weather PNG image
--v2 Use the v2 endpoint
-t, --transparency=0 Set transparency level (0-100) (PNG only)
-L, --location=LOCATION Specify explicite location
-l, --language=LANGUAGE Specify explicite language
--version Show application version.
```
On top of the following command-line flags, `go-cmw` can also take advantage of environment variables.
`go-cmw` can take advantage of `GO_CMW_LOCATION` and `GO_CMW_LANGUAGE` environment variables if set.

View file

@ -250,8 +250,8 @@ var (
png = app.Flag("png", "Download a weather PNG image").Short('P').Default("false").Bool() png = app.Flag("png", "Download a weather PNG image").Short('P').Default("false").Bool()
v2 = app.Flag("v2", "Use the v2 endpoint").Default("false").Bool() v2 = app.Flag("v2", "Use the v2 endpoint").Default("false").Bool()
transparency = app.Flag("transparency", "Set transparency level (0-100) (PNG only)").Short('t').Default("0").Int() transparency = app.Flag("transparency", "Set transparency level (0-100) (PNG only)").Short('t').Default("0").Int()
location = app.Flag("location", "Specify explicite location").Short('L').String() location = app.Flag("location", "Specify explicite location").Short('L').OverrideDefaultFromEnvar("GO_CMW_LOCATION").String()
language = app.Flag("language", "Specify explicite language").Short('l').String() language = app.Flag("language", "Specify explicite language").Short('l').OverrideDefaultFromEnvar("GO_CMW_LANGUAGE").String()
) )
// Create a function to parse all the command line parameters // Create a function to parse all the command line parameters