Documentation
¶
Overview ¶
Package pp handles pretty-printing.
Index ¶
- Constants
- func EnglishJoinMapOrEmptyLabel[T any](f func(t T) string, items []T, emptyLabel string) string
- func EnglishJoinOrEmptyLabel(items []string, emptyLabel string) string
- func Join(items []string) string
- func JoinMap[T any](f func(t T) string, items []T) string
- func Ordinal(n int) string
- func QuoteIfNotHumanReadable(s string) string
- func QuoteIfUnsafeInSentence(s string) string
- func QuoteOrEmptyLabel(s string, emptyLabel string) string
- func QuotePreviewIfNotHumanReadable(s string, limit int) string
- func QuotePreviewOrEmptyLabel(s string, limit int, emptyLabel string) string
- type Emoji
- type ID
- type PP
- type Verbosity
Constants ¶
const ( IssueReportingURL string = "https://github.com/favonia/cloudflare-ddns/issues/new/choose" ManualURL string = "https://github.com/favonia/cloudflare-ddns/blob/main/README.markdown" )
Fixed URLs in messages.
const AdvisoryPreviewLimit = 48
AdvisoryPreviewLimit is the centralized advisory preview limit. Keep advisory value previews short in operator-facing messages while preserving full-fidelity values for mismatch or validation diagnostics. See docs/designs/guides/operator-messages.markdown.
Variables ¶
This section is empty.
Functions ¶
func EnglishJoinMapOrEmptyLabel ¶ added in v1.16.0
EnglishJoinMapOrEmptyLabel applies f to each item and then joins the results with English punctuation, returning emptyLabel when items is empty.
func EnglishJoinOrEmptyLabel ¶ added in v1.16.0
EnglishJoinOrEmptyLabel joins words using English punctuation and returns emptyLabel when items is empty. It uses the Oxford comma.
func JoinMap ¶ added in v1.14.0
JoinMap applies a function to each element in the slice and then call Join.
func Ordinal ¶ added in v1.16.0
Ordinal returns the ordinal string for a positive integer (1st, 2nd, 3rd, etc.).
func QuoteIfNotHumanReadable ¶ added in v1.16.0
QuoteIfNotHumanReadable keeps human-readable single-line strings raw and quotes the rest to keep escaping explicit.
This follows the operator-message rule that values should be rendered for operator inspection rather than quoted mechanically.
func QuoteIfUnsafeInSentence ¶ added in v1.16.0
QuoteIfUnsafeInSentence keeps simple sentence-safe ASCII tokens raw and quotes the rest so they can be embedded safely in English prose.
The heuristic is positional rather than flat: some punctuation is fine at the start, more is fine in the middle, and only a small subset is fine at the end. This keeps common URLs, paths, regexes, dotfiles, fragments, env vars, and handles readable without letting raw tokens blend into prose punctuation. Use this for known token-like formats where preserving the raw shape improves readability. For opaque, malformed, or otherwise unknown literal data, prefer unconditional quoting at the call site instead of relying on this heuristic.
func QuoteOrEmptyLabel ¶ added in v1.16.0
QuoteOrEmptyLabel quotes non-empty strings and keeps a caller-defined label for the empty string.
This supports the operator-message rule that empty-string state should stay explicit when that is clearer than showing "".
func QuotePreviewIfNotHumanReadable ¶ added in v1.16.0
QuotePreviewIfNotHumanReadable keeps short human-readable strings raw, but quotes non-human-readable previews or truncated previews.
Truncated previews are always quoted so the operator can see that the shown value is only a preview, not the full original string.
func QuotePreviewOrEmptyLabel ¶ added in v1.16.0
QuotePreviewOrEmptyLabel quotes a non-empty preview string and truncates it in a rune-safe way when it exceeds the given limit. A non-positive limit disables truncation. For an empty string, it returns the caller-defined label unchanged.
This is the advisory-preview form of the operator-message rule from docs/designs/guides/operator-messages.markdown: keep advisory values short, but preserve explicit empty-state labels.
Types ¶
type Emoji ¶
type Emoji string
Emoji is the type of emoji strings.
const ( EmojiStar Emoji = "🌟" // stars attached to the updater name EmojiBullet Emoji = "🔸" // generic bullet points EmojiEnvVars Emoji = "📖" // reading configuration EmojiConfig Emoji = "🔧" // showing configuration EmojiInternet Emoji = "🌐" // network address detection EmojiMute Emoji = "🔇" // quiet mode EmojiDisabled Emoji = "🚫" // feature is disabled EmojiExperimental Emoji = "🧪" // experimental features EmojiSwitch Emoji = "🔀" // the happy eyeballs algorithm chose the alternative EmojiCreation Emoji = "🐣" // adding new DNS records EmojiDeletion Emoji = "💀" // deleting DNS records EmojiUpdate Emoji = "📡" // updating DNS records EmojiClear Emoji = "🧹" // clearing DNS records when exiting EmojiPing Emoji = "🔔" // pinging and health checks EmojiNotify Emoji = "📣" // notifications EmojiTimeout Emoji = "⌛" // Timeout or abortion EmojiSignal Emoji = "🚨" // catching signals EmojiAlreadyDone Emoji = "🤷" // DNS records were already up to date EmojiNow Emoji = "🏃" // an event that is happening now or immediately EmojiAlarm Emoji = "⏰" // an event that is scheduled to happen, but not immediately EmojiBye Emoji = "👋" // bye! EmojiGood Emoji = "😊" // good news EmojiUserError Emoji = "😡" // configuration mistakes made by users EmojiUserWarning Emoji = "😦" // warnings about possible configuration mistakes EmojiError Emoji = "😞" // errors that are not (directly) caused by user errors EmojiWarning Emoji = "😐" // warnings about something unusual EmojiImpossible Emoji = "🤯" // the impossible happened EmojiHint Emoji = "💡" // Hints )
Various constants defining emojis used in the updater.
type ID ¶ added in v1.16.0
type ID int
ID is the identifier of a message.
const ( MessageUpdateDockerTemplate ID = iota // PUID or PGID was used MessageAuthTokenNewPrefix // "CF_*" to "CLOUDFLARE_*" MessageIP4DetectionFails // How to turn off IPv4 MessageIP6DetectionFails // How to set up IPv6 or turn it off MessageIP4MappedIP6Address // IPv4-mapped IPv6 addresses are bad for AAAA records MessageDetectionTimeouts // Longer detection timeout MessageUpdateTimeouts // Longer update timeout MessageRecordPermission // Permissions to update DNS tokens MessageWAFListPermission // Permissions to update WAF lists MessageExperimentalWAF // New feature introduced in 1.14.0 on 2024/8/25 MessageExperimentalLocalWithInterface // New feature introduced in 1.15.0 MessageExperimentalMultipleAddressesURL // Multi-address URL response introduced in 1.16.0 MessageExperimentalMultipleAddressesFile // Multi-address file content introduced in 1.16.0 MessageUndocumentedCustomCloudflareTraceProvider // Undocumented feature )
All the registered hints.
type PP ¶
type PP interface {
// IsShowing checks whether a message of a certain level will be printed.
IsShowing(v Verbosity) bool
// Indent returns a new pretty-printer with more indentation.
Indent() PP
// BlankLineIfVerbose prints a blank line at the [Verbose] level
BlankLineIfVerbose()
// Infof formats and prints a message at the info level.
Infof(emoji Emoji, format string, args ...any)
// Noticef formats and prints a message at the notice level.
Noticef(emoji Emoji, format string, args ...any)
// Suppress marks a message ID as seen.
//
// The seen-state is shared with [InfoOncef] and [NoticeOncef].
Suppress(id ID)
// InfoOncef formats and prints an info at most once for a message ID.
//
// The once-state is shared with [NoticeOncef] and [Suppress].
InfoOncef(id ID, emoji Emoji, format string, args ...any)
// NoticeOncef formats and prints a notice at most once for a message ID.
//
// The once-state is shared with [InfoOncef] and [Suppress].
NoticeOncef(id ID, emoji Emoji, format string, args ...any)
}
PP is the abstraction of a pretty printer.
func NewDefault ¶ added in v1.14.0
NewDefault creates a new pretty printer with default settings.