From 2f9cb372e429e28b9765c04e490338ec14e5156f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lelzin=20=CE=BB?= Date: Wed, 25 Sep 2024 15:26:44 -0300 Subject: [PATCH 1/3] deps: add library `cobra v1.8.1` to manage CLI This library will replace the previous `flag` library, making it more practical to use, including when creating aliases. --- go.mod | 7 +++++++ go.sum | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/go.mod b/go.mod index 39bda2f..31e60e7 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,13 @@ go 1.22.1 require github.com/godbus/dbus/v5 v5.1.0 +require github.com/spf13/cobra v1.8.1 + +require ( + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect +) + require ( github.com/ebitengine/oto/v3 v3.1.0 // indirect github.com/ebitengine/purego v0.5.0 // indirect diff --git a/go.sum b/go.sum index badfed6..8fc5e7a 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,4 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/ebitengine/oto/v3 v3.1.0 h1:9tChG6rizyeR2w3vsygTTTVVJ9QMMyu00m2yBOCch6U= @@ -8,15 +9,23 @@ github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gopxl/beep v1.4.0 h1:pJERVDZMJkf49R1g/tV9DhVct4xNRuTlyMnMa53gGsc= github.com/gopxl/beep v1.4.0/go.mod h1:gGVz7MJKlfHrmkzr0wSLGNyY7oisM6rFWJnaLjNxEwA= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/orcaman/writerseeker v0.0.0-20200621085525-1d3f536ff85e h1:s2RNOM/IGdY0Y6qfTeUKhDawdHDpK9RGBdx80qN4Ttw= github.com/orcaman/writerseeker v0.0.0-20200621085525-1d3f536ff85e/go.mod h1:nBdnFKj15wFbf94Rwfq4m30eAcyY9V/IyKAGQFtqkW0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From fbf16c162428a50b660b1a6a7154c4c8a7356575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lelzin=20=CE=BB?= Date: Wed, 25 Sep 2024 15:39:31 -0300 Subject: [PATCH 2/3] imp(main): using `cobra` library instead of `flag` See more details on previous commit. --- cmd/hyprnotify/main.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/cmd/hyprnotify/main.go b/cmd/hyprnotify/main.go index fb57631..23b0297 100644 --- a/cmd/hyprnotify/main.go +++ b/cmd/hyprnotify/main.go @@ -1,19 +1,24 @@ package main import ( - "flag" "github.com/codelif/hyprnotify/internal" + "github.com/spf13/cobra" ) func main() { var enableSound bool - const message = "Disable sound" - flag.BoolVar(&enableSound, "no-sound", false, message) - flag.BoolVar(&enableSound, "silent", false, message) - flag.BoolVar(&enableSound, "s", false, message) + Cmd := &cobra.Command{ + Use: "hyprnotify", + Long: `DBus Implementation of Freedesktop Notification spec for 'hyprctl notify'`, + Run: func(cmd *cobra.Command, args []string) { + internal.InitDBus(enableSound) + }, + } - flag.Parse() + CmdFlags := Cmd.Flags() - internal.InitDBus(enableSound) + CmdFlags.BoolVarP(&enableSound, "no-sound", "s", false, "disable sound, silent mode") + + Cmd.Execute() } From fa130848f9bc29f445e8d4a2e08f6f3fa9a333ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lelzin=20=CE=BB?= Date: Thu, 26 Sep 2024 14:07:41 -0300 Subject: [PATCH 3/3] fix(cli): inverted boolean flag `--no-sound` bug from 2c34d12da404da31afe9ea68a0f4fc2690fe4898 --- cmd/hyprnotify/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/hyprnotify/main.go b/cmd/hyprnotify/main.go index 23b0297..cd3b0f6 100644 --- a/cmd/hyprnotify/main.go +++ b/cmd/hyprnotify/main.go @@ -6,19 +6,19 @@ import ( ) func main() { - var enableSound bool + var disableSound bool Cmd := &cobra.Command{ Use: "hyprnotify", Long: `DBus Implementation of Freedesktop Notification spec for 'hyprctl notify'`, Run: func(cmd *cobra.Command, args []string) { - internal.InitDBus(enableSound) + internal.InitDBus(!disableSound) }, } CmdFlags := Cmd.Flags() - CmdFlags.BoolVarP(&enableSound, "no-sound", "s", false, "disable sound, silent mode") + CmdFlags.BoolVarP(&disableSound, "no-sound", "s", false, "disable sound, silent mode") Cmd.Execute() }