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