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") -}