github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/util/config/commands.go (about) 1 package config 2 3 import ( 4 "fmt" 5 6 "github.com/urfave/cli/v2" 7 ) 8 9 var ( 10 // Commands defines a set of commands for local config 11 Commands = []*cli.Command{ 12 { 13 Name: "get", 14 Usage: "Get a value by specifying [key] as an arg", 15 Action: get, 16 }, 17 { 18 Name: "set", 19 Usage: "Set a key-val using [key] [value] as args", 20 Action: set, 21 }, 22 { 23 Name: "delete", 24 Usage: "Delete a value using [key] as an arg", 25 Action: del, 26 }, 27 } 28 ) 29 30 func get(ctx *cli.Context) error { 31 args := ctx.Args() 32 key := args.Get(0) 33 val := args.Get(1) 34 35 val, err := Get(key) 36 if err != nil { 37 return err 38 } 39 40 fmt.Println(val) 41 return nil 42 } 43 44 func set(ctx *cli.Context) error { 45 args := ctx.Args() 46 key := args.Get(0) 47 val := args.Get(1) 48 49 return Set(key, val) 50 } 51 52 func del(ctx *cli.Context) error { 53 args := ctx.Args() 54 key := args.Get(0) 55 56 if len(key) == 0 { 57 return fmt.Errorf("key cannot be blank") 58 } 59 60 // TODO: actually delete the key also 61 return Set(key, "") 62 }