Compare commits

...

17 commits

Author SHA1 Message Date
bece933718 chore(NOTICKET): Adds Dockerfile 2025-03-05 23:37:42 +01:00
fd320d9ec3 chore(): Migrates from the deprecated ioutil 2024-12-17 21:58:48 +01:00
6dbc5784df Add renovate.json 2024-01-14 20:48:48 +00:00
8c2797cc82 chore(): Adds checksum to the releases for verification 2023-07-02 22:12:14 +02:00
e3817dfa47 chore(): Adds gitea release API key 2023-07-02 21:50:02 +02:00
96f4ca7e0b chore(): Rearranging the pipeline to build a release properly 2023-07-02 21:45:22 +02:00
9939b75bdf chore(): Adds a pipeline based on tagging 2023-07-02 21:37:43 +02:00
00d1ef76f3 chore(): Tests building package in parallel 2023-07-02 21:27:25 +02:00
9e8a2a392f chore(): Adds pipeline dependency 2023-07-02 21:15:27 +02:00
b52312f876 chore(): Reconfigure pipeline 2023-07-02 21:14:30 +02:00
ae9cb43294 chore(): Adds go.mod file 2023-07-02 21:05:46 +02:00
27d3667372 chore(): Adds test pipeline 2023-07-02 21:03:33 +02:00
4ef54af009 Migrating to the new kingpin Envar() interface 2020-05-06 19:46:10 +02:00
f1ab9a64fb Fixing transparency default value in README 2020-03-07 08:21:24 +01:00
24f8a92ab4 Version bump to 0.1.3 2020-03-06 20:53:45 +01:00
7eae3e5464 [BUGFIX] Windows terminals that don't set TERM now properly set
--no-colors by default
2020-03-06 20:52:48 +01:00
ba165eb68c [BUGFIX] Transparency of 0 as default is stupid, let's fix it. 2020-03-06 20:15:46 +01:00
6 changed files with 213 additions and 11 deletions

183
.drone.yml Normal file
View file

@ -0,0 +1,183 @@
---
kind: pipeline
name: test
steps:
- name: test-code
image: golang
commands:
- go get
- go test
- name: run-code
image: golang
commands:
- go get
- go run .
---
kind: pipeline
name: test-build
steps:
- name: prepare
image: golang
commands:
- go version
- name: build-linux-amd64
image: golang
environment:
GOOS: linux
GOARCH: amd64
commands:
- go get
- go build -o cmw-linux-amd64-${DRONE_COMMIT_SHA:0:8}
depends_on:
- prepare
- name: build-darwin-amd64
image: golang
environment:
GOOS: darwin
GOARCH: amd64
commands:
- go get
- go build -o cmw-darwin-amd64-${DRONE_COMMIT_SHA:0:8}
depends_on:
- prepare
- name: build-windows-amd64
image: golang
environment:
GOOS: windows
GOARCH: amd64
commands:
- go get
- go build -o cmw-windows-amd64-${DRONE_COMMIT_SHA:0:8}.exe
depends_on:
- prepare
- name: build-linux-arm64
image: golang
environment:
GOOS: linux
GOARCH: arm64
commands:
- go get
- go build -o cmw-linux-arm64-${DRONE_COMMIT_SHA:0:8}
depends_on:
- prepare
- name: build-darwin-arm64
image: golang
environment:
GOOS: darwin
GOARCH: arm64
commands:
- go get
- go build -o cmw-darwin-arm64-${DRONE_COMMIT_SHA:0:8}
depends_on:
- prepare
depends_on:
- test
---
kind: pipeline
name: build
steps:
- name: prepare
image: golang
commands:
- mkdir bin/
- name: build-linux-amd64
image: golang
environment:
GOOS: linux
GOARCH: amd64
commands:
- go get
- go build -o bin/cmw-linux-amd64-${DRONE_TAG}
depends_on:
- prepare
- name: build-darwin-amd64
image: golang
environment:
GOOS: darwin
GOARCH: amd64
commands:
- go get
- go build -o bin/cmw-darwin-amd64-${DRONE_TAG}
depends_on:
- prepare
- name: build-windows-amd64
image: golang
environment:
GOOS: windows
GOARCH: amd64
commands:
- go get
- go build -o bin/cmw-windows-amd64-${DRONE_TAG}.exe
depends_on:
- prepare
- name: build-linux-arm64
image: golang
environment:
GOOS: linux
GOARCH: arm64
commands:
- go get
- go build -o bin/cmw-linux-arm64-${DRONE_TAG}
depends_on:
- prepare
- name: build-darwin-arm64
image: golang
environment:
GOOS: darwin
GOARCH: arm64
commands:
- go get
- go build -o bin/cmw-darwin-arm64-${DRONE_TAG}
depends_on:
- prepare
- name: generate-checksum
image: golang
commands:
- cd bin
- md5sum * > ../md5sums.txt
- sha512sum * > ../sha512sums.txt
- cp ../md5sums.txt .
- cp ../sha512sums.txt .
depends_on:
- build-linux-amd64
- build-darwin-amd64
- build-windows-amd64
- build-linux-arm64
- build-darwin-arm64
- name: gitea_release
image: plugins/gitea-release
settings:
title: Release ${DRONE_TAG}
note: This is the cmw release of version ${DRONE_TAG}
api_key:
from_secret:
gitea_release
base_url: https://scm.project42.io
files: bin/*
depends_on:
- generate-checksum
depends_on:
- test-build
trigger:
event:
- tag

14
Dockerfile Normal file
View file

@ -0,0 +1,14 @@
FROM docker.io/library/golang:alpine as builder
ADD . /cmw
RUN apk add git && \
cd /cmw && \
go get -u . && \
go build -o cmw
FROM docker.io/library/alpine:latest
COPY --from=builder /cmw/cmw /cmw
ENTRYPOINT ["/cmw"]

View file

@ -31,7 +31,7 @@ Flags:
-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)
-t, --transparency=255 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)

3
go.mod Normal file
View file

@ -0,0 +1,3 @@
module go-cmw
go 1.20

19
main.go
View file

@ -3,7 +3,6 @@ package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
@ -15,7 +14,7 @@ import (
)
// VERSION The version release
const VERSION = "0.1.2"
const VERSION = "0.1.5"
// AUTHOR The author name
const AUTHOR = "Elia el Lazkani"
@ -72,7 +71,7 @@ func (w weather) get(req *http.Request, download bool) {
// `weather` method to print the weather
func (w weather) print(resp *http.Response) {
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal("Error reading body. ", err)
}
@ -166,8 +165,8 @@ func generateParamFormat(switchesF []*bool, freeStyleF *string, formatF *string,
// 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 (--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()
location = app.Flag("location", "Specify explicite location (--expert-mode)").Short('L').Envar("GO_CMW_LOCATION").String()
language = app.Flag("language", "Specify explicite language (--expert-mode)").Short('l').Envar("GO_CMW_LANGUAGE").String()
v2 = app.Flag("v2", "Display Data-Rich output").Default("false").Bool()
switches = []*bool{
app.Flag("metric", "Display weather in metric").Short('m').Default("false").Bool(),
@ -185,12 +184,12 @@ 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) (--expert-mode)").OverrideDefaultFromEnvar("GO_CMW_TRANSPARENCY").Short('t').Default("0").Int()
transparency = app.Flag("transparency", "Set transparency level (0-255) (PNG only) (--expert-mode)").Envar("GO_CMW_TRANSPARENCY").Short('t').Default("255").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()
fileName = app.Flag("file-name", "Name download file (--expert-mode)").Envar("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()
format = app.Flag("format", "Specify a format query (e.g. \"%l:+%c+%t\") (--expert-mode)").Envar("GO_CMW_FORMAT").String()
freeStyle = app.Flag("free-style", "Specify a free-style API call (--expert-mode)").Envar("GO_CMW_FREE_STYLE").String()
expertMode = app.Flag("expert-mode", "Print expert mode information").Default("false").Bool()
)
@ -278,7 +277,7 @@ func flagParser() {
// Windows terminal does not have color encoding
// so let's make sure windows users are happy
if os.Getenv("TERM") == "" && !*png && *format != "" && *freeStyle != "" {
if os.Getenv("TERM") == "" && !*png && *format == "" && *freeStyle == "" {
*switches[11] = true
}
}

3
renovate.json Normal file
View file

@ -0,0 +1,3 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
}