github.com/Pankov404/juju@v0.0.0-20150703034450-be266991dceb/cmd/supercommand.go (about)

     1  package cmd
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/juju/cmd"
     7  	"github.com/juju/loggo"
     8  
     9  	"github.com/juju/juju/juju/osenv"
    10  	"github.com/juju/juju/version"
    11  )
    12  
    13  var logger = loggo.GetLogger("juju.cmd")
    14  
    15  // NewSuperCommand is like cmd.NewSuperCommand but
    16  // it adds juju-specific functionality:
    17  // - The default logging configuration is taken from the environment;
    18  // - The version is configured to the current juju version;
    19  // - The command emits a log message when a command runs.
    20  func NewSuperCommand(p cmd.SuperCommandParams) *cmd.SuperCommand {
    21  	p.Log = &cmd.Log{
    22  		DefaultConfig: os.Getenv(osenv.JujuLoggingConfigEnvKey),
    23  	}
    24  	p.Version = version.Current.String()
    25  	p.NotifyRun = runNotifier
    26  	return cmd.NewSuperCommand(p)
    27  }
    28  
    29  // NewSubSuperCommand should be used to create a SuperCommand
    30  // that runs as a subcommand of some other SuperCommand.
    31  func NewSubSuperCommand(p cmd.SuperCommandParams) *cmd.SuperCommand {
    32  	p.NotifyRun = runNotifier
    33  	return cmd.NewSuperCommand(p)
    34  }
    35  
    36  func runNotifier(name string) {
    37  	logger.Infof("running %s [%s %s]", name, version.Current, version.Compiler)
    38  }