simplify
This commit is contained in:
parent
5b0e465dc5
commit
d22ce15be8
12
cmd/root.go
12
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.
|
Cobra is a CLI library for Go that empowers applications.
|
||||||
This application is a tool to generate the needed files
|
This application is a tool to generate the needed files
|
||||||
to quickly create a Cobra application.`,
|
to quickly create a Cobra application.`,
|
||||||
|
Args: cobra.MatchAll(cobra.ExactArgs(3)),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
in, err := strconv.ParseFloat(args[0], 64)
|
in, err := strconv.ParseFloat(args[2], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fromVal, err := u.Find(cmd.Flag("from").Value.String())
|
fromVal, err := u.Find(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
toVal, err := u.Find(cmd.Flag("to").Value.String())
|
toVal, err := u.Find(args[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
return
|
return
|
||||||
@ -54,8 +55,3 @@ func Execute() {
|
|||||||
os.Exit(1)
|
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")
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user