{"modulePath":"github.com/kernel/cli","version":"v0.54.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package util\n\n## Constants\n\n```go\nconst DefaultTimeLayout = \"2006-01-02 15:04:05 MST\"\n```\nDefaultTimeLayout is the standard layout used for displaying timestamps. Includes the local timezone abbreviation to make it clear times are local.\n\n```go\nconst JSONOutputFlagDescription = \"Output format: json for raw API response\"\n```\n\n## Functions\n\n```go\nfunc AddJSONOutputFlag(cmd *cobra.Command)\n```\n\n```go\nfunc ConvertJWKToPEM(jwkJSON string) ([]byte, error)\n```\nConvertJWKToPEM converts an Ed25519 JWK to PEM format\n\n```go\nfunc ConvertPEMToJWK(pemData string) (string, error)\n```\nConvertPEMToJWK converts an Ed25519 PEM private key to JWK format\n\n```go\nfunc CopyDir(src, dst string) error\n```\nCopyDir recursively copies a directory from src to dst\n\n```go\nfunc CopyFile(src, dst string) error\n```\nCopyFile copies a single file from src to dst\n\n```go\nfunc FirstOrDash(items ...string) string\n```\nFirstOrDash returns the first non-empty string from the provided items. If all items are empty, it returns \"-\".\n\n```go\nfunc FormatBytes(bytes int64) string\n```\nFormatBytes formats bytes in a human-readable format\n\n```go\nfunc FormatLocal(t time.Time) string\n```\nFormatLocal formats the provided time in the user's local timezone. If the time is zero, it returns \"-\".\n\n```go\nfunc GetBaseURL() string\n```\nGetBaseURL returns the Kernel API base URL, falling back to production. KERNEL\\_BASE\\_URL is never set in .env; it exists solely for internal dev/staging overrides.\n\n```go\nfunc GetKernelClient(cmd *cobra.Command) kernel.Client\n```\nGetKernelClient retrieves the kernel client from the command context\n\n```go\nfunc IsNotFound(err error) bool\n```\nIsNotFound returns true if the error is a Kernel API error with HTTP 404.\n\n```go\nfunc IsPEMKey(data string) bool\n```\nIsPEMKey checks if the input string is in PEM format\n\n```go\nfunc JoinOrDash(items ...string) string\n```\nJoinOrDash joins the provided strings with \", \" as separator. If no items are provided, it returns \"-\".\n\n```go\nfunc ModifyFile(path, oldStr, newStr string) error\n```\nModifyFile replaces all occurrences of oldStr with newStr in the file. Returns an error if the pattern is not found in the file\n\n```go\nfunc NewClient(opts ...option.RequestOption) kernel.Client\n```\nNewClient returns a kernel API client preconfigured with middleware that detects when a newer CLI/SDK version is required and informs the user.\n\nIt mirrors kernel.NewClient but injects an HTTP middleware that intercepts 400 responses with error codes \"sdk\\_upgrade\\_required\" or \"sdk\\_update\\_required\". When encountered, a helpful upgrade message is displayed once per process.\n\n```go\nfunc OrDash(s string) string\n```\nOrDash returns the string if non-empty, otherwise returns \"-\".\n\n```go\nfunc PrintCompactJSONLine(v RawJSONProvider) error\n```\nPrintCompactJSONLine prints v as a single compact JSON line followed by a newline. Use inside SSE loops where downstream tooling (jq -c, log shippers) expects newline-delimited JSON.\n\n```go\nfunc PrintPageJSON[T RawJSONProvider](items []T, page, perPage int, hasMore bool) error\n```\nPrintPageJSON prints one page of a page-based list as {\"items\": \\[...], \"page\": N, \"per\\_page\": N, \"has\\_more\": bool}, using each item's raw JSON.\n\n```go\nfunc PrintPrettyJSON(v RawJSONProvider) error\n```\nPrintPrettyJSON prints the raw JSON from an SDK response type with indentation. It uses the RawJSON() method to get the original API response, avoiding zero-value fields that would appear when re-marshaling the Go struct.\n\n```go\nfunc PrintPrettyJSONSlice[T RawJSONProvider](items []T) error\n```\nPrintPrettyJSONSlice prints a slice of SDK response types as a JSON array. Each element must implement RawJSONProvider.\n\n```go\nfunc Unzip(zipFilePath, destDir string) error\n```\nUnzip extracts a zip file to the specified directory\n\n```go\nfunc ValidateJSONOutput(output string) error\n```\n\n```go\nfunc ValidatePEMKey(pemData string) error\n```\nValidatePEMKey validates that a PEM-encoded string contains a valid Ed25519 private key\n\n```go\nfunc ZipDirectory(srcDir, destZip string, opts *ZipOptions) error\n```\nZipDirectory compresses the given source directory into the destination file path.\n\n## Types\n\n```go\ntype CleanedUpSdkError struct {\n\tErr error\n}\n```\nCleanedUpSdkError extracts a message field from the raw JSON resposne. This is the convention we use in the API for error response bodies (400s and 500s)\n\n```go\nfunc (e CleanedUpSdkError) Error() string\n```\n\n```go\nfunc (e CleanedUpSdkError) Unwrap() error\n```\n\n```go\ntype ContextKey string\n```\nContextKey is the type for context keys\n\n```go\nconst KernelClientKey ContextKey = \"kernel_client\"\n```\nKernelClientKey is the context key for the kernel client\n\n```go\ntype RawJSONProvider interface {\n\tRawJSON() string\n}\n```\nRawJSONProvider is an interface for SDK types that provide raw JSON responses.\n\n```go\ntype ZipOptions struct {\n\t// ExcludeDirectories: exact directory names to exclude (case-sensitive)\n\tExcludeDirectories []string\n\t// ExcludeFilenamePatterns: glob patterns for filename exclusion (e.g., \"*.test.js\")\n\tExcludeFilenamePatterns []string\n}\n```\nZipOptions which directories and files to exclude from the zip\n\n","path":"github.com/kernel/cli/pkg/util","name":"util","synopsis":"","isRedistributable":true}
