Documentation update

This commit is contained in:
Elia el Lazkani 2020-02-29 12:37:17 +01:00
parent 826d262d42
commit 939ec82312
2 changed files with 54 additions and 41 deletions

View file

@ -2,11 +2,6 @@
`go-cmw` is a [cmw](https://gitlab.com/elazkani/cmw) rewrite in [Go](https://golang.org/). `go-cmw` is a [cmw](https://gitlab.com/elazkani/cmw) rewrite in [Go](https://golang.org/).
# Reason
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.
# Usage # Usage
`go-cmw` features a good command-line interface thanks to `kingpin.v2`. `go-cmw` features a good command-line interface thanks to `kingpin.v2`.
@ -18,34 +13,36 @@ usage: go-cmw [<flags>]
A small terminal wrapper around the wttr.in weather endpoint. A small terminal wrapper around the wttr.in weather endpoint.
Flags: Flags:
--help Show context-sensitive help (also try --help-long and --help-man). --help Show context-sensitive help (also try --help-long and --help-man).
-m, --metric Display weather in metric -L, --location=LOCATION Specify explicite location (--expert-mode)
-u, --uscs Display weather in imperial -l, --language=LANGUAGE Specify explicite language (--expert-mode)
-M, --meter-second Display wind in m/s --v2 Display Data-Rich output
-z, --zero Show the weather now -m, --metric Display weather in metric
-o, --one Show the weather for one day -u, --uscs Display weather in imperial
-w, --two Show the weather for two days -M, --meter-second Display wind in m/s
-A, --ignore-user-agent Request ignoring the user agent -z, --zero Display current weather
-F, --follow-link Follow link redirect -o, --one Display current weather + 1 day
-n, --narrow Display weather in narrow view -w, --two Display current weather + 2 days
-q, --quiet Add the quiet flag -A, --ignore-user-agent Ignore User-Agent and force ANSI output
-Q, --super-quiet Add the super quiet flag -F, --follow-link Do not display the 'Follow' line
-N, --no-colors Disable displaying colors (always enabled on windows -n, --narrow Display narrow view (only day/night)
-p, --add-frame Add a frame to the output -q, --quiet Display quiet version (no weather report)
-T, --mid-transparency Enable mid-transparency (PNG only) -Q, --super-quiet Display super quiet version (no weather report and no city)
-P, --png Download a weather PNG image -N, --no-colors Display no colors (always enabled on windows
--v2 Use the v2 endpoint -P, --png Download a weather PNG image
-t, --transparency=0 Set transparency level (0-100) (PNG only) -p, --add-frame Add a frame to the output (PNG only)
-f, --format=FORMAT Query format (overrides everything else) -t, --transparency=0 Set transparency level (0-255) (PNG only) (--expert-mode)
-L, --location=LOCATION Specify explicite location -d, --download Enables download mode (--expert-mode)
-l, --language=LANGUAGE Specify explicite language --file-name="" Name download file (--expert-mode)
-O, --one-liner One liner outpet (for the terminal multiplexer lovers out there) -O, --one-liner One liner outpet (for the terminal multiplexer lovers out there)
--extra-information Print extra information --format=FORMAT Specify a format query (e.g. "%l:+%c+%t") (--expert-mode)
--version Show application version. --free-style=FREE-STYLE Specify a free-style API call (--expert-mode)
--expert-mode Print expert mode information
--version Show application version.
``` ```
On top of the following command-line flags, `go-cmw` can also take advantage of environment variables. On top of the following command-line flags, `go-cmw` can also take advantage of environment variables `--expert-mode`.
`go-cmw` can take advantage of `GO_CMW_FORMAT`, `GO_CMW_LOCATION` and `GO_CMW_LANGUAGE` environment variables if set.
```console ```console
$ go-cmw --zero $ go-cmw --zero
@ -73,4 +70,20 @@ set -g status-interval 1800
WEATHER='#(go-cmw --one-liner)' WEATHER='#(go-cmw --one-liner)'
set -g status-right '... $WEATHER ...' set -g status-right '... $WEATHER ...'
``` ```
# Expert Mode
The commands labeled `--expert-mode` have special functionality attached to them.
Some of them can be used as environment variables while others override `go-cmw`
default functionality to provide the user with more flexible interface.
For more information about commands labeled `--expert-mode`
```console
$ go-cmw --expert-mode
```
# Reason
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.

18
main.go
View file

@ -89,7 +89,7 @@ func (w weather) download(resp *http.Response) {
f, err := os.Create(fName) f, err := os.Create(fName)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal("Error opening file. ", err)
} }
defer f.Close() defer f.Close()
@ -163,8 +163,8 @@ func generateParamFormat() (string, bool, error) {
// Defining the command-line interface // Defining the command-line interface
var ( var (
app = kingpin.New("go-cmw", "A small terminal wrapper around the wttr.in weather endpoint.") app = kingpin.New("go-cmw", "A small terminal wrapper around the wttr.in weather endpoint.")
location = app.Flag("location", "Specify explicite location").Short('L').OverrideDefaultFromEnvar("GO_CMW_LOCATION").String() location = app.Flag("location", "Specify explicite location (--expert-mode)").Short('L').OverrideDefaultFromEnvar("GO_CMW_LOCATION").String()
language = app.Flag("language", "Specify explicite language").Short('l').OverrideDefaultFromEnvar("GO_CMW_LANGUAGE").String() language = app.Flag("language", "Specify explicite language (--expert-mode)").Short('l').OverrideDefaultFromEnvar("GO_CMW_LANGUAGE").String()
v2 = app.Flag("v2", "Display Data-Rich output").Default("false").Bool() v2 = app.Flag("v2", "Display Data-Rich output").Default("false").Bool()
switches = [13]*bool{ switches = [13]*bool{
app.Flag("metric", "Display weather in metric").Short('m').Default("false").Bool(), app.Flag("metric", "Display weather in metric").Short('m').Default("false").Bool(),
@ -182,9 +182,9 @@ 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()
addFrame = app.Flag("add-frame", "Add a frame to the output (PNG only)").Short('p').Default("false").Bool() addFrame = app.Flag("add-frame", "Add a frame to the output (PNG only)").Short('p').Default("false").Bool()
transparency = app.Flag("transparency", "Set transparency level (0-255) (PNG only)").OverrideDefaultFromEnvar("GO_CMW_TRANSPARENCY").Short('t').Default("0").Int() transparency = app.Flag("transparency", "Set transparency level (0-255) (PNG only) (--expert-mode)").OverrideDefaultFromEnvar("GO_CMW_TRANSPARENCY").Short('t').Default("0").Int()
download = app.Flag("download", "Enables download mode").Short('d').Default("false").Bool() download = app.Flag("download", "Enables download mode (--expert-mode)").Short('d').Default("false").Bool()
fileName = app.Flag("file-name", "Name download file").OverrideDefaultFromEnvar("GO_CMW_FILE_NAME").Default("").String() fileName = app.Flag("file-name", "Name download file (--expert-mode)").OverrideDefaultFromEnvar("GO_CMW_FILE_NAME").Default("").String()
oneLiner = app.Flag("one-liner", "One liner outpet (for the terminal multiplexer lovers out there)").Short('O').Default("false").Bool() oneLiner = app.Flag("one-liner", "One liner outpet (for the terminal multiplexer lovers out there)").Short('O').Default("false").Bool()
format = app.Flag("format", "Specify a format query (e.g. \"%l:+%c+%t\") (--expert-mode)").OverrideDefaultFromEnvar("GO_CMW_FORMAT").String() format = app.Flag("format", "Specify a format query (e.g. \"%l:+%c+%t\") (--expert-mode)").OverrideDefaultFromEnvar("GO_CMW_FORMAT").String()
freeStyle = app.Flag("free-style", "Specify a free-style API call (--expert-mode)").OverrideDefaultFromEnvar("GO_CMW_FREE_STYLE").String() freeStyle = app.Flag("free-style", "Specify a free-style API call (--expert-mode)").OverrideDefaultFromEnvar("GO_CMW_FREE_STYLE").String()
@ -260,7 +260,7 @@ Supported: af be ca da de el et fr fa hu id it
} }
// Create a function to parse all the command line parameters // Create a function to parse all the command line parameters
// provided and save them in the parameter struct. // provided.
func flagParser() { func flagParser() {
app.Version(VERSION) app.Version(VERSION)
@ -273,9 +273,9 @@ func flagParser() {
os.Exit(0) os.Exit(0)
} }
// Windows does not have color encoding // Windows terminal does not have color encoding
// so let's make sure windows users are happy // so let's make sure windows users are happy
if os.Getenv("TERM") == "" && !*png { if os.Getenv("TERM") == "" && !*png && *format != "" && *freeStyle != "" {
*switches[11] = true *switches[11] = true
} }
} }