From aa6341bb433a522f89051a13b7ce9e68b22dd58b Mon Sep 17 00:00:00 2001 From: David Muckle Date: Fri, 17 Jul 2020 01:21:51 -0400 Subject: [PATCH 1/2] Volume command --- cmd/volume.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 cmd/volume.go diff --git a/cmd/volume.go b/cmd/volume.go new file mode 100644 index 0000000..0c08bbc --- /dev/null +++ b/cmd/volume.go @@ -0,0 +1,57 @@ +/* +Copyright © 2020 NAME HERE + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package cmd + +import ( + "fmt" + "os" + "strconv" + + "github.com/dvdmuckle/goify/cmd/helper" + "github.com/spf13/cobra" +) + +// volumeCmd represents the volume command +var volumeCmd = &cobra.Command{ + Use: "volume", + Aliases: []string{"vol"}, + Args: cobra.ExactArgs(1), + Short: "Set volume for Spotify", + Long: `Sets the volume for Spotify. This command requires exactly + one argument, a number between 0 and 100 to set the volume to.`, + Run: func(cmd *cobra.Command, args []string) { + helper.SetClient(&conf) + vol, err := strconv.ParseInt(args[0], 10, 0) + if err != nil { + fmt.Println("Volume is not a number") + os.Exit(1) + } + if vol > 100 { + fmt.Println("Volume cannot be higher than 100") + os.Exit(1) + } else if vol < 0 { + //By virtue of how cobra processes args, where "-" denotes a flag, we should never get here + //Still, just in case... + fmt.Println("Volume cannot be less than 0") + os.Exit(1) + } + conf.Client.Volume(int(vol)) + }, +} + +func init() { + rootCmd.AddCommand(volumeCmd) +} From b150baf8f5b0caf375421800dcfec484a1aefdc8 Mon Sep 17 00:00:00 2001 From: David Muckle Date: Fri, 17 Jul 2020 01:35:26 -0400 Subject: [PATCH 2/2] Correct license info --- cmd/volume.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/volume.go b/cmd/volume.go index 0c08bbc..73527dc 100644 --- a/cmd/volume.go +++ b/cmd/volume.go @@ -1,5 +1,5 @@ /* -Copyright © 2020 NAME HERE +Copyright © 2020 David Muckle Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.