summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go40
1 files changed, 34 insertions, 6 deletions
diff --git a/main.go b/main.go
index 9e23ee6..079ccc5 100644
--- a/main.go
+++ b/main.go
@@ -5,19 +5,47 @@ import (
"fmt"
"log"
"os"
+ "strings"
"github.com/urfave/cli/v3"
)
func main() {
- cmd := new(cli.Command{
- Name: "boom",
- Usage: "make an explosive entrance",
- Action: func(context.Context, *cli.Command) error {
- fmt.Println("Boom! I say!")
+ cmd := &cli.Command{
+ Flags: []cli.Flag{
+ &cli.StringFlag{
+ Name: "lang",
+ Value: "en",
+ Usage: "language used for the greeting",
+ },
+ &cli.IntFlag{
+ Name: "times",
+ Value: 1,
+ Usage: "number of times to repeat word for hello",
+ },
+ },
+ Usage: "top level application",
+ Action: func(ctx context.Context, cmd *cli.Command) error {
+ name := "Brandon"
+ if cmd.NArg() > 0 {
+ name = cmd.Args().First()
+ }
+
+ dir := map[string]string{
+ "es": "Hola",
+ "en": "Hello",
+ }
+
+ greeting, ok := dir[cmd.String("lang")]
+ if !ok {
+ greeting = "???"
+ }
+
+ fmt.Printf("%s, %s\n", strings.Repeat(greeting, cmd.Int("times")), name)
+
return nil
},
- })
+ }
if err := cmd.Run(context.Background(), os.Args); err != nil {
log.Fatal(err)