Welcome the --one-liner flag, terminal multiplexer lovers
* Adding a new --one-liner flag that will return the weather on one line * Updating README with usage and tmux configuration example
This commit is contained in:
parent
2990b13f78
commit
cea7b560d0
2 changed files with 40 additions and 3 deletions
31
README.md
31
README.md
|
@ -39,9 +39,38 @@ Flags:
|
|||
-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.
|
||||
```
|
||||
|
||||
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.
|
||||
`go-cmw` can take advantage of `GO_CMW_FORMAT`, `GO_CMW_LOCATION` and `GO_CMW_LANGUAGE` environment variables if set.
|
||||
|
||||
```console
|
||||
$ go-cmw --zero
|
||||
Weather report: Paris
|
||||
|
||||
\ / Clear
|
||||
.-. 1..4 °C
|
||||
― ( ) ― ↗ 11 km/h
|
||||
`-’ 10 km
|
||||
/ \ 0.3 mm
|
||||
```
|
||||
|
||||
`go-cmw` makes it easier to integrate the weather with your favorite terminal multiplexer.
|
||||
|
||||
```console
|
||||
$ go-cmw --one-liner
|
||||
Paris: ☀️ +4°C
|
||||
```
|
||||
|
||||
Example configuration for `tmux`.
|
||||
|
||||
```console
|
||||
# Let us update sensibly every 30 minutes
|
||||
set -g status-interval 1800
|
||||
|
||||
WEATHER='#(go-cmw --one-liner)'
|
||||
set -g status-right '... $WEATHER ...'
|
||||
```
|
12
main.go
12
main.go
|
@ -37,6 +37,7 @@ const (
|
|||
ADDFRAME
|
||||
MIDTRANSPARENCY
|
||||
FORMAT
|
||||
ONELINER
|
||||
LOCATION
|
||||
LANGUAGE
|
||||
PNG
|
||||
|
@ -114,7 +115,7 @@ func (w weather) print(resp *http.Response) {
|
|||
if err != nil {
|
||||
log.Fatal("Error reading body. ", err)
|
||||
}
|
||||
fmt.Printf("%s\n", body)
|
||||
fmt.Printf("%s", body)
|
||||
}
|
||||
|
||||
// `weather` method to download the weather
|
||||
|
@ -161,7 +162,8 @@ func (cmdP *cmdParams) generateParamFormat() (string, bool, error) {
|
|||
affix = append(affix, "?")
|
||||
|
||||
// If --format is specified, let's not bother and simply return it
|
||||
if cmdP.Flags&FORMAT == FORMAT {
|
||||
// If --one-liner is specified, we know the format is set so let's return it
|
||||
if cmdP.Flags&FORMAT == FORMAT || cmdP.Flags&ONELINER == ONELINER {
|
||||
return cmdP.Format, false, nil
|
||||
}
|
||||
|
||||
|
@ -260,6 +262,7 @@ var (
|
|||
format = app.Flag("format", "Query format (overrides everything else)").Short('f').OverrideDefaultFromEnvar("GO_CMW_FORMAT").String()
|
||||
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()
|
||||
oneLiner = app.Flag("one-liner", "One liner outpet (for the terminal multiplexer lovers out there)").Short('O').Default("false").Bool()
|
||||
extraInformation = app.Flag("extra-information", "Print extra information").Default("false").Bool()
|
||||
)
|
||||
|
||||
|
@ -394,6 +397,11 @@ func flagParser(cmdP *cmdParams) {
|
|||
cmdP.Language = *language
|
||||
}
|
||||
|
||||
if *oneLiner {
|
||||
cmdP.Flags += ONELINER
|
||||
cmdP.Format = "?format=3"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Create a function to generate the url that we'll be calling shortly.
|
||||
|
|
Loading…
Reference in a new issue