使用codegangsta / cli捕获命令标志变量

I try to write my first CLI App in Go.

I use codegangsta/cli for the structure.

My problem :

I have some commands :

Add  --name 

Show --all

Delete  --force

From the file /commands/add.go I can't get the variable StackName from /commands.go set like this :

package main
var StackName string
var Commands = []cli.Command{
{
    Name:   "add",
    Usage:  "",
    Action: command.CmdAdd,

    Flags:  []cli.Flag{
        cli.StringFlag{
            Name: "name, n",
            Value: "default",
            Usage: "Stack name",
            Destination: &StackName,
        },

And in my add.go file, I try to get $stackName but I don't find how to do this :

package command

func CmdAdd(c *cli.Context) {
    fmt.PrintF(StackName)
}

I got this : command/add.go:25: undefined: StackName.

Thanks to help to find where I'm wrong.

What does your file hierarchy look like? Because you may need to import the commands.go file import "github.com/YourGithubName/YourDirectory/commands". I say this because you are trying to call the variable in the command package when it is declared in the main package.