package main import ( "fmt" "strconv" "github.com/codegangsta/cli" ) func main() { app := cli.NewApp() app.Name = "calculator" app.Usage = "perform simple arithmetic operations" app.Commands = []cli.Command{ { Name: "add", Usage: "add two numbers", Action: func(c *cli.Context) error { a, _ := strconv.Atoi(c.Args()[0]) b, _ := strconv.Atoi(c.Args()[1]) total := Context.GlobalInt("total") Context.SetGlobalInt("total", total + a + b) fmt.Printf("Result: %d\n", total + a + b) return nil }, }, { Name: "subtract", Usage: "subtract two numbers", Action: func(c *cli.Context) error { a, _ := strconv.Atoi(c.Args()[0]) b, _ := strconv.Atoi(c.Args()[1]) total := Context.GlobalInt("total") Context.SetGlobalInt("total", total - a - b) fmt.Printf("Result: %d\n", total - a - b) return nil }, }, } app.Action = func(c *cli.Context) error { fmt.Printf("Starting with total value: %d\n", Context.GlobalInt("total")) return nil } Context.SetGlobalInt("total", 0) _ = app.Run(os.Args) }In this example, the CLI application has two commands, "add" and "subtract". Each command takes two integer arguments and updates the global total value using the Context GlobalInt variable. The initial value of the total variable is set to zero in the main function. The output of the program shows the final value of the total variable after all commands have been executed. Overall, the github.com/codegangsta/cli package is a useful library for building simple command-line applications in Go. Using the Context GlobalInt variable allows us to maintain shared state across different commands, making it easier to write more complex CLI applications.