package main

import (
	"fmt"
	"github.com/spf13/cobra"
	"os"
)

func newRoot() *cobra.Command {
	root := &cobra.Command{Use: "shop", SilenceUsage: true, SilenceErrors: true}
	qty := 1
	quote := &cobra.Command{Use: "quote [sku]", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error {
		if qty < 1 || qty > 100 {
			return fmt.Errorf("quantity must be between 1 and 100")
		}
		_, err := fmt.Fprintf(cmd.OutOrStdout(), "sku=%s qty=%d total=%d\n", args[0], qty, 250*qty)
		return err
	}}
	quote.Flags().IntVar(&qty, "qty", 1, "number of items")
	root.AddCommand(quote)
	return root
}
func main() {
	if err := newRoot().Execute(); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}
