Files
s3-cli/cmd/update-notifier.go
zeekay a3245a76f4 Rebrand: Hanzo S3 CLI -- remove all MinIO branding
- Replace copyright headers: "MinIO, Inc." -> "Hanzo AI, Inc." across 411+ Go files
- Replace "MinIO Object Storage stack" -> "Hanzo S3 stack" in all file headers
- Replace all user-facing "MinIO" references -> "Hanzo S3" in Usage, help text, examples
- Replace example alias "myminio" -> "mys3" throughout
- Replace example endpoints play.min.io -> s3.hanzo.ai, dl.min.io -> s3.hanzo.ai
- Replace doc URLs min.io -> hanzo.space
- Rewrite README.md/README_zh_CN.md: product is "Hanzo S3 CLI" (the s3 command)
- Update CONTRIBUTING.md, CONFLICT.md, NOTICE, code_of_conduct.md
- Update all Dockerfiles: labels, entrypoints, image refs -> ghcr.io/hanzos3/cli
- Update Makefile: build output, docker tags, install paths -> s3
- Update docker-buildx.sh: image tags -> ghcr.io/hanzos3/cli
- DO NOT change go.mod module path or import paths (github.com/minio/mc preserved)
- DO NOT change Go identifiers, SDK types, or wire protocol constants
- All unit tests pass
2026-02-21 14:19:07 -08:00

100 lines
3.3 KiB
Go

// Copyright (c) 2015-2022 Hanzo AI, Inc.
//
// This file is part of Hanzo S3 stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package cmd
import (
"fmt"
"math"
"runtime"
"strings"
"time"
"github.com/cheggaaa/pb"
humanize "github.com/dustin/go-humanize"
)
// prepareUpdateMessage - prepares the update message, only if a
// newer version is available.
func prepareUpdateMessage(downloadURL string, older time.Duration) string {
if downloadURL == "" || older <= 0 {
return ""
}
// Compute friendly duration string to indicate time
// difference between newer and current release.
t := time.Time{}
newerThan := humanize.RelTime(t, t.Add(older), "ago", "")
// Return the nicely colored and formatted update message.
return colorizeUpdateMessage(downloadURL, newerThan)
}
// colorizeUpdateMessage - inspired from Yeoman project npm package https://github.com/yeoman/update-notifier
func colorizeUpdateMessage(updateString, newerThan string) string {
msgLine1Fmt := " You are running an older version of mc released %s "
msgLine2Fmt := " Update: %s "
// Calculate length *without* color coding: with ANSI terminal
// color characters, the result is incorrect.
line1Length := len(fmt.Sprintf(msgLine1Fmt, newerThan))
line2Length := len(fmt.Sprintf(msgLine2Fmt, updateString))
// Populate lines with color coding.
line1InColor := fmt.Sprintf(msgLine1Fmt, colorYellowBold(newerThan))
line2InColor := fmt.Sprintf(msgLine2Fmt, colorCyanBold(updateString))
// calculate the rectangular box size.
maxContentWidth := int(math.Max(float64(line1Length), float64(line2Length)))
// termWidth is set to a default one to use when we are
// not able to calculate terminal width via OS syscalls
termWidth := 25
if width, err := pb.GetTerminalWidth(); err == nil {
termWidth = width
}
// Box cannot be printed if terminal width is small than maxContentWidth
if maxContentWidth > termWidth {
return "\n" + line1InColor + "\n" + line2InColor + "\n\n"
}
topLeftChar := "┏"
topRightChar := "┓"
bottomLeftChar := "┗"
bottomRightChar := "┛"
horizBarChar := "━"
vertBarChar := "┃"
// on windows terminal turn off unicode characters.
if runtime.GOOS == "windows" {
topLeftChar = "+"
topRightChar = "+"
bottomLeftChar = "+"
bottomRightChar = "+"
horizBarChar = "-"
vertBarChar = "|"
}
lines := []string{
colorYellowBold(topLeftChar + strings.Repeat(horizBarChar, maxContentWidth) + topRightChar),
vertBarChar + line1InColor + strings.Repeat(" ", maxContentWidth-line1Length) + vertBarChar,
vertBarChar + line2InColor + strings.Repeat(" ", maxContentWidth-line2Length) + vertBarChar,
colorYellowBold(bottomLeftChar + strings.Repeat(horizBarChar, maxContentWidth) + bottomRightChar),
}
return "\n" + strings.Join(lines, "\n") + "\n"
}