-
Notifications
You must be signed in to change notification settings - Fork 0
/
supercommand.go
60 lines (51 loc) · 1.74 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package cmd
import (
"fmt"
"os"
"github.com/juju/cmd"
"github.com/juju/loggo"
"github.com/juju/utils/arch"
"github.com/juju/utils/series"
"github.com/juju/version"
"github.com/juju/juju/juju/osenv"
"github.com/juju/juju/jujuversion"
)
func init() {
// If the environment key is empty, ConfigureLoggers returns nil and does
// nothing.
err := loggo.ConfigureLoggers(os.Getenv(osenv.JujuStartupLoggingConfigEnvKey))
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR parsing %s: %s\n\n", osenv.JujuStartupLoggingConfigEnvKey, err)
}
}
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),
}
current := version.Binary{
Number: jujuversion.Current,
Arch: arch.HostArch(),
Series: series.HostSeries(),
}
// p.Version should be a version.Binary, but juju/cmd does not
// import juju/juju/version so this cannot happen. We have
// tests to assert that this string value is correct.
p.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, jujuversion.Current, jujuversion.Compiler)
}