feat: Introduce cmd flags package
Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
This commit is contained in:
parent
d84f17e7ab
commit
36309212a7
3 changed files with 15 additions and 6 deletions
7
cmd/flags/flags.go
Normal file
7
cmd/flags/flags.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package flags
|
||||
|
||||
const (
|
||||
LON = "lon"
|
||||
LAT = "lat"
|
||||
JSON = "json"
|
||||
)
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.sr.ht/~timharek/yr-go/cmd/flags"
|
||||
"git.sr.ht/~timharek/yr-go/internal/nominatim"
|
||||
"git.sr.ht/~timharek/yr-go/yr"
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -23,10 +24,10 @@ func init() {
|
|||
}
|
||||
|
||||
func now(cmd *cobra.Command, args []string) {
|
||||
isJson, err := cmd.Flags().GetBool("json")
|
||||
isJson, err := cmd.Flags().GetBool(flags.JSON)
|
||||
cobra.CheckErr(err)
|
||||
lon, _ := cmd.Flags().GetFloat64("lon")
|
||||
lat, _ := cmd.Flags().GetFloat64("lat")
|
||||
lon, _ := cmd.Flags().GetFloat64(flags.LON)
|
||||
lat, _ := cmd.Flags().GetFloat64(flags.LAT)
|
||||
|
||||
c, err := yr.New()
|
||||
cobra.CheckErr(err)
|
||||
|
|
|
@ -3,6 +3,7 @@ package cmd
|
|||
import (
|
||||
"os"
|
||||
|
||||
"git.sr.ht/~timharek/yr-go/cmd/flags"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -20,7 +21,7 @@ func Execute() {
|
|||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().Bool("json", false, "Result in JSON")
|
||||
rootCmd.PersistentFlags().Float64P("lon", "x", 0, "Longitude coordinate")
|
||||
rootCmd.PersistentFlags().Float64P("lat", "y", 0, "Latitude coordinate")
|
||||
rootCmd.PersistentFlags().Bool(flags.JSON, false, "Result in JSON")
|
||||
rootCmd.PersistentFlags().Float64P(flags.LON, "x", 0, "Longitude coordinate")
|
||||
rootCmd.PersistentFlags().Float64P(flags.LAT, "y", 0, "Latitude coordinate")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue