From d22ce15be8b2adc431470c3ec1960db7b3ee1880 Mon Sep 17 00:00:00 2001 From: abs3nt Date: Mon, 27 Feb 2023 23:08:17 -0800 Subject: [PATCH] simplify --- cmd/root.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 389c6f8..15e9909 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -21,18 +21,19 @@ examples and usage of using your application. For example: Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, + Args: cobra.MatchAll(cobra.ExactArgs(3)), Run: func(cmd *cobra.Command, args []string) { - in, err := strconv.ParseFloat(args[0], 64) + in, err := strconv.ParseFloat(args[2], 64) if err != nil { fmt.Println(err.Error()) return } - fromVal, err := u.Find(cmd.Flag("from").Value.String()) + fromVal, err := u.Find(args[0]) if err != nil { fmt.Println(err.Error()) return } - toVal, err := u.Find(cmd.Flag("to").Value.String()) + toVal, err := u.Find(args[1]) if err != nil { fmt.Println(err.Error()) return @@ -54,8 +55,3 @@ func Execute() { os.Exit(1) } } - -func init() { - rootCmd.PersistentFlags().StringVarP(&from, "from", "f", "c", "unit system to convert from") - rootCmd.PersistentFlags().StringVarP(&to, "to", "t", "f", "unit system to convert to") -}