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/).
# 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
`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.
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)
-f, --format=FORMAT Query format (overrides everything else)
-L, --location=LOCATION Specify explicite location
-l, --language=LANGUAGE Specify explicite language
-O, --one-liner One liner outpet (for the terminal multiplexer lovers out there)
--extra-information Print extra information
--version Show application version.
--help Show context-sensitive help (also try --help-long and --help-man).
-L, --location=LOCATION Specify explicite location (--expert-mode)
-l, --language=LANGUAGE Specify explicite language (--expert-mode)
--v2 Display Data-Rich output
-m, --metric Display weather in metric
-u, --uscs Display weather in imperial
-M, --meter-second Display wind in m/s
-z, --zero Display current weather
-o, --one Display current weather + 1 day
-w, --two Display current weather + 2 days
-A, --ignore-user-agent Ignore User-Agent and force ANSI output
-F, --follow-link Do not display the 'Follow' line
-n, --narrow Display narrow view (only day/night)
-q, --quiet Display quiet version (no weather report)
-Q, --super-quiet Display super quiet version (no weather report and no city)
-N, --no-colors Display no colors (always enabled on windows
-P, --png Download a weather PNG image
-p, --add-frame Add a frame to the output (PNG only)
-t, --transparency=0 Set transparency level (0-255) (PNG only) (--expert-mode)
-d, --download Enables download mode (--expert-mode)
--file-name="" Name download file (--expert-mode)
-O, --one-liner One liner outpet (for the terminal multiplexer lovers out there)
--format=FORMAT Specify a format query (e.g. "%l:+%c+%t") (--expert-mode)
--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.
`go-cmw` can take advantage of `GO_CMW_FORMAT`, `GO_CMW_LOCATION` and `GO_CMW_LANGUAGE` environment variables if set.
On top of the following command-line flags, `go-cmw` can also take advantage of environment variables `--expert-mode`.
```console
$ go-cmw --zero
@ -73,4 +70,20 @@ set -g status-interval 1800
WEATHER='#(go-cmw --one-liner)'
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)
if err != nil {
log.Fatal(err)
log.Fatal("Error opening file. ", err)
}
defer f.Close()
@ -163,8 +163,8 @@ func generateParamFormat() (string, bool, error) {
// Defining the command-line interface
var (
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()
language = app.Flag("language", "Specify explicite language").Short('l').OverrideDefaultFromEnvar("GO_CMW_LANGUAGE").String()
location = app.Flag("location", "Specify explicite location (--expert-mode)").Short('L').OverrideDefaultFromEnvar("GO_CMW_LOCATION").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()
switches = [13]*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()
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()
download = app.Flag("download", "Enables download mode").Short('d').Default("false").Bool()
fileName = app.Flag("file-name", "Name download file").OverrideDefaultFromEnvar("GO_CMW_FILE_NAME").Default("").String()
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 (--expert-mode)").Short('d').Default("false").Bool()
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()
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()
@ -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
// provided and save them in the parameter struct.
// provided.
func flagParser() {
app.Version(VERSION)
@ -273,9 +273,9 @@ func flagParser() {
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
if os.Getenv("TERM") == "" && !*png {
if os.Getenv("TERM") == "" && !*png && *format != "" && *freeStyle != "" {
*switches[11] = true
}
}