use flag instead os os.Args
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Simon Vieille 2022-08-30 15:42:28 +02:00
parent c9665b33b3
commit 79fe14e059
Signed by: deblan
GPG key ID: 579388D585F70417
10 changed files with 87 additions and 69 deletions

View file

@ -36,19 +36,19 @@ app <block_name> <name> <command> <background_color> <foreground_color>
Show the time using given format and run `gnome-calendar` when clicked. Show the time using given format and run `gnome-calendar` when clicked.
``` ```
date "%H:%M:%S %d/%m/%Y" date -format="%H:%M:%S %d/%m/%Y"
``` ```
Show mount point usage and warns with limits and colors. Show mount point usage and warns with limits and colors.
``` ```
du <block_name> <name> <mount_point> <limit_warning> <limit_danger> du -block=<block_name> -name=<name> -mount-point=<mount_point> -limit-warning=<limit_warning> -limit-danger=<limit_danger>
``` ```
Show the IP of the given iface. Show the IP of the given iface.
``` ```
ip <iface> <ip4|ip6> <name> ip -iface=<iface> -version=<ip4|ip6> -name=<name>
``` ```
Show the public IP. Show the public IP.
@ -60,19 +60,19 @@ ip_wan
Show the telemetry using Prusa Printer API. Show the telemetry using Prusa Printer API.
``` ```
prusa_telemetry <block_name> http://<prusa_printer_ip>/api/telemetry prusa_telemetry -api=http://1.2.3.4/api/telemetry
``` ```
Show a message when the given process is running (use `preg -f`). Show a message when the given process is running (use `preg -f`).
``` ```
ps <process> <message> ps -process=<process> -message=<message>
``` ```
Show indicator of RSS. Show indicator of RSS.
``` ```
rss <block_name> <feed_url> <feed_reader_url> <foreground_color_when_no_item> <foreground_color_when_items> rss -block=<block_name> -feed=<feed_url> -website=<feed_reader_url> -empty-color=<color> -non-empty-color=<color>
``` ```
Show current song played (spotify). Show current song played (spotify).
@ -84,13 +84,13 @@ spotify
Show volume. Show volume.
``` ```
volume <channel> volume -channel=<channel>
``` ```
Toggler for wireguard. Toggler for wireguard.
``` ```
wireguard <iface> <name> wireguard -iface=<iface> -name=<name>
``` ```
Add a blocks that represent opened apps to create a task bar. Add a blocks that represent opened apps to create a task bar.

View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
r "gitnet.fr/deblan/i3-blocks-go/rendering" r "gitnet.fr/deblan/i3-blocks-go/rendering"
"os" "os"
@ -17,18 +18,25 @@ func runCmd(wg *sync.WaitGroup, value string) {
func main() { func main() {
var wg sync.WaitGroup var wg sync.WaitGroup
if os.Getenv("BLOCK_BUTTON") == "1" { argBlockName := flag.String("block", "app", "block name")
argName := flag.String("name", "", "name of the app")
argCommand := flag.String("cmd", "", "command to run on click")
argBgColor := flag.String("bg-color", "#333333", "background color")
argFbColor := flag.String("fg-color", "#ffffff", "foreground color")
flag.Parse()
if os.Getenv("BLOCK_BUTTON") == "1" && *argCommand != "" {
wg.Add(1) wg.Add(1)
go runCmd(&wg, os.Args[5]) go runCmd(&wg, *argCommand)
} }
options := r.NewBlockOptions() options := r.NewBlockOptions()
options.FullText = r.TextWithPadding(os.Args[2], r.FB{ options.FullText = r.TextWithPadding(*argName, r.FB{
Background: os.Args[3], Background: *argBgColor,
Foreground: os.Args[4], Foreground: *argFbColor,
}) })
block := r.Block(os.Args[1], options) block := r.Block(*argBlockName, options)
fmt.Println(block) fmt.Println(block)
wg.Wait() wg.Wait()
} }

View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"github.com/enescakir/emoji" "github.com/enescakir/emoji"
"github.com/itchyny/timefmt-go" "github.com/itchyny/timefmt-go"
@ -18,7 +19,9 @@ func runCalendar(wg *sync.WaitGroup) {
} }
func main() { func main() {
argFormat := os.Args[1] argFormat := flag.String("format", "%H:%M:%S %m-%d-%Y", "time format")
flag.Parse()
now := time.Now() now := time.Now()
var wg sync.WaitGroup var wg sync.WaitGroup
@ -29,7 +32,7 @@ func main() {
} }
symbol := string(emoji.Calendar) symbol := string(emoji.Calendar)
date := timefmt.Format(now, argFormat) date := timefmt.Format(now, *argFormat)
options := r.NewBlockOptions() options := r.NewBlockOptions()
options.FullText = r.TextWithRightPadding(fmt.Sprintf("%s %s", symbol, date), r.FB{ options.FullText = r.TextWithRightPadding(fmt.Sprintf("%s %s", symbol, date), r.FB{

View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
r "gitnet.fr/deblan/i3-blocks-go/rendering" r "gitnet.fr/deblan/i3-blocks-go/rendering"
"os" "os"
@ -27,32 +28,33 @@ func runFileExplorer(wg *sync.WaitGroup, path string) {
} }
func main() { func main() {
argBlockName := os.Args[1] argBlockName := flag.String("block", "du", "block name")
argName := os.Args[2] argName := flag.String("name", "du", "block name")
argPoint := os.Args[3] argMountPoint := flag.String("mount-point", "du", "block name")
argLimitWarning, _ := strconv.Atoi(os.Args[4]) argLimitWarning := flag.Int("limit-warning", 70, "limit for warning")
argLimitDanger, _ := strconv.Atoi(os.Args[5]) argLimitDanger := flag.Int("limit-danger", 90, "limit for danger")
flag.Parse()
used := DiskUsage(argPoint) used := DiskUsage(*argMountPoint)
fbUsed := r.FB{Background: r.Color("black1")} fbUsed := r.FB{Background: r.Color("black1")}
var wg sync.WaitGroup var wg sync.WaitGroup
if os.Getenv("BLOCK_BUTTON") == "1" { if os.Getenv("BLOCK_BUTTON") == "1" {
wg.Add(1) wg.Add(1)
go runFileExplorer(&wg, fmt.Sprintf("file://%s", argPoint)) go runFileExplorer(&wg, fmt.Sprintf("file://%s", *argMountPoint))
} }
if used < argLimitWarning { if used < *argLimitWarning {
fbUsed.Foreground = r.Color("green") fbUsed.Foreground = r.Color("green")
} else if used < argLimitDanger { } else if used < *argLimitDanger {
fbUsed.Foreground = r.Color("orange") fbUsed.Foreground = r.Color("orange")
} else { } else {
fbUsed.Foreground = r.Color("red") fbUsed.Foreground = r.Color("red")
} }
label := r.TextWithPadding( label := r.TextWithPadding(
argName, *argName,
r.FB{ r.FB{
Foreground: r.Color("grey1"), Foreground: r.Color("grey1"),
Background: r.Color("black2"), Background: r.Color("black2"),
@ -63,7 +65,7 @@ func main() {
options := r.NewBlockOptions() options := r.NewBlockOptions()
options.FullText = fmt.Sprintf("%s%s", label, value) options.FullText = fmt.Sprintf("%s%s", label, value)
block := r.Block(argBlockName, options) block := r.Block(*argBlockName, options)
fmt.Println(block) fmt.Println(block)
wg.Wait() wg.Wait()

View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"github.com/atotto/clipboard" "github.com/atotto/clipboard"
r "gitnet.fr/deblan/i3-blocks-go/rendering" r "gitnet.fr/deblan/i3-blocks-go/rendering"
@ -11,21 +12,10 @@ import (
) )
func main() { func main() {
argIface := os.Args[1] argIface := flag.String("iface", "eth0", "the iface")
argVersion := os.Args[2] argVersion := flag.String("version", "ip4", "ip4 or ip6")
argName := os.Args[3] argName := flag.String("name", "eth0", "the name")
flag.Parse()
if argIface == "" {
argIface = "eth0"
}
if argVersion == "" {
argVersion = "ip4"
}
if argName == "" {
argName = argIface
}
var ( var (
iface *net.Interface iface *net.Interface
@ -33,7 +23,7 @@ func main() {
// ip net.IP // ip net.IP
) )
iface, err := net.InterfaceByName(argIface) iface, err := net.InterfaceByName(*argIface)
if err != nil { if err != nil {
return return
@ -47,9 +37,9 @@ func main() {
if ip == "" { if ip == "" {
a := addr.String() a := addr.String()
if argVersion == "ip4" && !strings.Contains(a, ":") { if *argVersion == "ip4" && !strings.Contains(a, ":") {
ip = a ip = a
} else if argVersion == "ip6" && strings.Contains(a, ":") && !strings.Contains(a, "fe80") { } else if *argVersion == "ip6" && strings.Contains(a, ":") && !strings.Contains(a, "fe80") {
ip = a ip = a
} }
} }
@ -67,7 +57,7 @@ func main() {
} }
label := r.TextWithPadding( label := r.TextWithPadding(
argName, *argName,
r.FB{ r.FB{
Foreground: r.Color("grey1"), Foreground: r.Color("grey1"),
Background: r.Color("black2"), Background: r.Color("black2"),

View file

@ -2,12 +2,12 @@ package main
import ( import (
"encoding/json" "encoding/json"
"flag"
"fmt" "fmt"
"github.com/itchyny/timefmt-go" "github.com/itchyny/timefmt-go"
r "gitnet.fr/deblan/i3-blocks-go/rendering" r "gitnet.fr/deblan/i3-blocks-go/rendering"
"io" "io"
"net/http" "net/http"
"os"
"strconv" "strconv"
"time" "time"
) )
@ -20,7 +20,10 @@ type Telemetry struct {
} }
func main() { func main() {
resp, err := http.Get(os.Args[2]) argApi := flag.String("api", "", "the api url")
flag.Parse()
resp, err := http.Get(*argApi)
if err != nil { if err != nil {
return return
@ -62,7 +65,7 @@ func main() {
options := r.NewBlockOptions() options := r.NewBlockOptions()
options.FullText = fmt.Sprintf("%s%s%s%s", progress, tempNozzle, tempBed, date) options.FullText = fmt.Sprintf("%s%s%s%s", progress, tempNozzle, tempBed, date)
block := r.Block(os.Args[1], options) block := r.Block("prusa_telemetry", options)
fmt.Println(block) fmt.Println(block)
} }

View file

@ -1,9 +1,9 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
r "gitnet.fr/deblan/i3-blocks-go/rendering" r "gitnet.fr/deblan/i3-blocks-go/rendering"
"os"
"os/exec" "os/exec"
"strings" "strings"
) )
@ -17,14 +17,15 @@ func ProcessExists(process string) bool {
} }
func main() { func main() {
argProcess := os.Args[1] argProcess := flag.String("process", "", "the process")
argName := os.Args[2] argMessage := flag.String("message", "", "the message")
flag.Parse()
if !ProcessExists(argProcess) { if !ProcessExists(*argProcess) {
return return
} }
value := r.TextWithPadding(argName, r.FB{ value := r.TextWithPadding(*argMessage, r.FB{
Foreground: r.Color("green"), Foreground: r.Color("green"),
Background: r.Color("black1"), Background: r.Color("black1"),
}) })

View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
r "gitnet.fr/deblan/i3-blocks-go/rendering" r "gitnet.fr/deblan/i3-blocks-go/rendering"
"io" "io"
@ -27,12 +28,19 @@ func openBrowser(wg *sync.WaitGroup, url string) {
func main() { func main() {
var wg sync.WaitGroup var wg sync.WaitGroup
argBlock := flag.String("block", "rss", "block name")
argFeed := flag.String("feed", "", "url of the feed")
argWebsite := flag.String("website", "", "website")
argEmptyColor := flag.String("empty-color", "#CCCCCC", "empty color")
argNonEmptyColor := flag.String("non-empty-color", "#B3FF6C", "when items color")
flag.Parse()
if os.Getenv("BLOCK_BUTTON") == "1" { if os.Getenv("BLOCK_BUTTON") == "1" {
wg.Add(1) wg.Add(1)
go openBrowser(&wg, os.Args[3]) go openBrowser(&wg, *argWebsite)
} }
resp, err := http.Get(os.Args[2]) resp, err := http.Get(*argFeed)
if err != nil { if err != nil {
return return
@ -45,18 +53,18 @@ func main() {
label := r.FontAwesome("\uf09e") label := r.FontAwesome("\uf09e")
fb := r.FB{ fb := r.FB{
Foreground: os.Args[4], Foreground: *argEmptyColor,
Background: r.Color("black2"), Background: r.Color("black2"),
} }
if count > 0 { if count > 0 {
label = fmt.Sprintf("%s +%d", label, count) label = fmt.Sprintf("%s +%d", label, count)
fb.Foreground = os.Args[5] fb.Foreground = *argNonEmptyColor
} }
options := r.NewBlockOptions() options := r.NewBlockOptions()
options.FullText = r.TextWithPadding(label, fb) options.FullText = r.TextWithPadding(label, fb)
block := r.Block(os.Args[1], options) block := r.Block(*argBlock, options)
fmt.Println(block) fmt.Println(block)
wg.Wait() wg.Wait()

View file

@ -1,9 +1,9 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
r "gitnet.fr/deblan/i3-blocks-go/rendering" r "gitnet.fr/deblan/i3-blocks-go/rendering"
"os"
"os/exec" "os/exec"
"regexp" "regexp"
"strconv" "strconv"
@ -21,9 +21,10 @@ func Volume(channel string) int {
} }
func main() { func main() {
argChannel := os.Args[1] argChannel := flag.String("channel", "Master", "the channel")
flag.Parse()
volume := Volume(argChannel) volume := Volume(*argChannel)
var symbole string var symbole string

View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
r "gitnet.fr/deblan/i3-blocks-go/rendering" r "gitnet.fr/deblan/i3-blocks-go/rendering"
"net" "net"
@ -10,8 +11,9 @@ import (
) )
func main() { func main() {
argIface := os.Args[1] argIface := flag.String("iface", "wg0", "the iface")
argName := os.Args[2] argName := flag.String("name", "wg0", "the name")
flag.Parse()
var ( var (
iface *net.Interface iface *net.Interface
@ -20,7 +22,7 @@ func main() {
var ip string var ip string
iface, err := net.InterfaceByName(argIface) iface, err := net.InterfaceByName(*argIface)
if err == nil { if err == nil {
addrs, _ = iface.Addrs() addrs, _ = iface.Addrs()
@ -42,11 +44,11 @@ func main() {
if ip == "" { if ip == "" {
fb.Foreground = r.Color("grey1") fb.Foreground = r.Color("grey1")
fb.Background = r.Color("black3") fb.Background = r.Color("black3")
command = exec.Command("sudo", "wg-quick", "up", argIface) command = exec.Command("sudo", "wg-quick", "up", *argIface)
} else { } else {
fb.Foreground = r.Color("black1") fb.Foreground = r.Color("black1")
fb.Background = r.Color("green") fb.Background = r.Color("green")
command = exec.Command("sudo", "wg-quick", "down", argIface) command = exec.Command("sudo", "wg-quick", "down", *argIface)
} }
if os.Getenv("BLOCK_BUTTON") == "1" { if os.Getenv("BLOCK_BUTTON") == "1" {
@ -54,8 +56,8 @@ func main() {
} }
options := r.NewBlockOptions() options := r.NewBlockOptions()
options.FullText = r.TextWithPadding(argName, fb) options.FullText = r.TextWithPadding(*argName, fb)
block := r.Block(fmt.Sprintf("wireguard_%s", argIface), options) block := r.Block(fmt.Sprintf("wireguard_%s", *argIface), options)
fmt.Println(block) fmt.Println(block)
} }