github.com/kat-co/cmd@v0.0.0-20140616103059-5da365f9d57e/version.go (about)

     1  // Copyright 2012, 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package cmd
     5  
     6  import (
     7  	"launchpad.net/gnuflag"
     8  )
     9  
    10  // versionCommand is a cmd.Command that prints the current version.
    11  type versionCommand struct {
    12  	CommandBase
    13  	out   Output
    14  	version string
    15  }
    16  
    17  func newVersionCommand(version string) *versionCommand {
    18  	return &versionCommand{
    19  		version: version,
    20  	}
    21  }
    22  
    23  func (v *versionCommand) Info() *Info {
    24  	return &Info{
    25  		Name:    "version",
    26  		Purpose: "print the current version",
    27  	}
    28  }
    29  
    30  func (v *versionCommand) SetFlags(f *gnuflag.FlagSet) {
    31  	v.out.AddFlags(f, "smart", DefaultFormatters)
    32  }
    33  
    34  func (v *versionCommand) Run(ctxt *Context) error {
    35  	return v.out.Write(ctxt, v.version)
    36  }