in cli/azd/main.go [40:163]
func main() {
ctx := context.Background()
restoreColorMode := colorable.EnableColorsStdout(nil)
defer restoreColorMode()
log.SetFlags(log.LstdFlags | log.Lshortfile)
if isDebugEnabled() {
azcorelog.SetListener(func(event azcorelog.Event, msg string) {
log.Printf("%s: %s\n", event, msg)
})
} else {
log.SetOutput(io.Discard)
}
log.Printf("azd version: %s", internal.Version)
ts := telemetry.GetTelemetrySystem()
latest := make(chan semver.Version)
go fetchLatestVersion(latest)
rootContainer := ioc.NewNestedContainer(nil)
ioc.RegisterInstance(rootContainer, ctx)
cmdErr := cmd.NewRootCmd(false, nil, rootContainer).ExecuteContext(ctx)
oneauth.Shutdown()
if !isJsonOutput() {
if firstNotice := telemetry.FirstNotice(); firstNotice != "" {
fmt.Fprintln(os.Stderr, output.WithWarningFormat(firstNotice))
}
}
latestVersion, ok := <-latest
// If we were able to fetch a latest version, check to see if we are up to date and
// print a warning if we are not. Note that we don't print this warning when the CLI version
// is exactly 0.0.0-dev.0, which is a sentinel value used for `internal.Version` when
// a version is not explicitly applied at build time (i.e. dev builds installed with `go install`)
//
// Don't write this message when JSON output is enabled, since in that case we use stderr to return structured
// information about command progress.
if !isJsonOutput() && ok {
if internal.IsDevVersion() {
// This is a dev build (i.e. built using `go install without setting a version`) - don't print a warning in this
// case
log.Printf("eliding update message for dev build")
} else if latestVersion.GT(internal.VersionInfo().Version) {
var upgradeText string
installedBy := installer.InstalledBy()
if runtime.GOOS == "windows" {
switch installedBy {
case installer.InstallTypePs:
//nolint:lll
upgradeText = "run:\npowershell -ex AllSigned -c \"Invoke-RestMethod 'https://aka.ms/install-azd.ps1' | Invoke-Expression\"\n\nIf the install script was run with custom parameters, ensure that the same parameters are used for the upgrade. For advanced install instructions, see: https://aka.ms/azd/upgrade/windows"
case installer.InstallTypeWinget:
upgradeText = "run:\nwinget upgrade Microsoft.Azd"
case installer.InstallTypeChoco:
upgradeText = "run:\nchoco upgrade azd"
default:
// Also covers "msi" case where the user installed directly
// via MSI
upgradeText = "visit https://aka.ms/azd/upgrade/windows"
}
} else if runtime.GOOS == "linux" {
switch installedBy {
case installer.InstallTypeSh:
//nolint:lll
upgradeText = "run:\ncurl -fsSL https://aka.ms/install-azd.sh | bash\n\nIf the install script was run with custom parameters, ensure that the same parameters are used for the upgrade. For advanced install instructions, see: https://aka.ms/azd/upgrade/linux"
default:
// Also covers "deb" and "rpm" cases which are currently
// documented. When package manager distribution support is
// added, this will need to be updated.
upgradeText = "visit https://aka.ms/azd/upgrade/linux"
}
} else if runtime.GOOS == "darwin" {
switch installedBy {
case installer.InstallTypeBrew:
upgradeText = "run:\nbrew update && brew upgrade azd"
case installer.InstallTypeSh:
//nolint:lll
upgradeText = "run:\ncurl -fsSL https://aka.ms/install-azd.sh | bash\n\nIf the install script was run with custom parameters, ensure that the same parameters are used for the upgrade. For advanced install instructions, see: https://aka.ms/azd/upgrade/mac"
default:
upgradeText = "visit https://aka.ms/azd/upgrade/mac"
}
} else {
// Platform is not recognized, use the generic install link
upgradeText = "visit https://aka.ms/azd/upgrade"
}
fmt.Fprintln(
os.Stderr,
output.WithWarningFormat(
"WARNING: your version of azd is out of date, you have %s and the latest version is %s",
internal.VersionInfo().Version.String(), latestVersion.String()))
fmt.Fprintln(os.Stderr)
fmt.Fprintln(
os.Stderr,
output.WithWarningFormat(`To update to the latest version, %s`,
upgradeText))
}
}
if ts != nil {
err := ts.Shutdown(ctx)
if err != nil {
log.Printf("non-graceful telemetry shutdown: %v\n", err)
}
if ts.EmittedAnyTelemetry() {
err := startBackgroundUploadProcess()
if err != nil {
log.Printf("failed to start background telemetry upload: %v\n", err)
}
}
}
if cmdErr != nil {
os.Exit(1)
}
}