diff --git a/cmd/flags/flags.go b/cmd/flags/flags.go new file mode 100644 index 0000000..2a627fb --- /dev/null +++ b/cmd/flags/flags.go @@ -0,0 +1,7 @@ +package flags + +const ( + LON = "lon" + LAT = "lat" + JSON = "json" +) diff --git a/cmd/now.go b/cmd/now.go index ccab052..bf53fc0 100644 --- a/cmd/now.go +++ b/cmd/now.go @@ -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) diff --git a/cmd/root.go b/cmd/root.go index 06fc9bd..387bd48 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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") }