config

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config resolves the CLI home directory and loads config.json.

Index

Constants

View Source
const (
	MinOrderLevel  = 1
	MaxOrderLevel  = 100
	MaxOrderLevels = 9
)

Order-size preset bounds. Each level is a percentage of the funding balance (1..100, where 100 = "max"); MaxOrderLevels caps the count at the number of digit keys (1..9) the order UIs can bind. The list is stored as a plain JSON array, so extending it later needs no schema change and an older binary reads a longer list without error.

View Source
const (
	DirName       = ".digitalx-cli"
	LegacyDirName = ".korbit-cli"
)

DirName is the CLI home directory under the user's home; LegacyDirName is the directory an installation made under the earlier product name carries. Home keeps using an existing LegacyDirName rather than starting an empty new one beside it, so keys, config, and the journal stay where they already are.

View Source
const EnvHome = "DIGITALX_CLI_HOME"

EnvHome names the environment variable that relocates the CLI home. The legacy KORBIT_CLI_HOME spelling is accepted as a fallback (see envalias).

Variables

View Source
var Backends = []string{"file", "keychain"}

Backends are the supported keystore backend names.

View Source
var ColorSchemes = []string{"green-red", "red-blue"}

ColorSchemes are the valid persisted tui color-scheme names. They mirror uikit.ColorScheme.String(); config keeps its own copy so it need not import the (charm-dependent) tui/uikit layer. A uikit test pins the two lists together so they cannot drift.

Functions

func Home

func Home(getenv func(string) string) string

Home returns the CLI home directory: $DIGITALX_CLI_HOME (else the legacy $KORBIT_CLI_HOME) when set; otherwise ~/.digitalx-cli, unless that does not exist and ~/.korbit-cli does, in which case the existing directory is used. The chosen directory need not exist — the write paths create it.

A pinned path is normalized (see NormalizeHome), so the value the user typed and the absolute path it names resolve to one home — and to ONE file-name layout (LegacyLayout reads the basename).

func LegacyLayout

func LegacyLayout(home string) bool

LegacyLayout reports whether home is a CLI home created under the earlier product name — its basename is LegacyDirName. It is the ONE backwards-compat predicate in the codebase: the files a home holds carry NO service name (journal.db, bot.db, sandbox/sandbox.db), and this is the single condition under which a consumer picks the earlier, product-named spelling instead (korbit-cli.db, korbit-bot.db, sandbox/korbit-sandbox.db).

The folder's name decides the filenames, and nothing renames a file on open, so an install still sharing ~/.korbit-cli with an older `korbit` binary keeps working — both binaries derive the same legacy names from the same directory. Every other home, including one pinned elsewhere with DIGITALX_CLI_HOME, uses the official names. No command in this CLI moves or renames a home: a user who wants ~/.digitalx-cli moves the directory and renames the files inside it as one step, because the two are one unit (see MIGRATION.md).

The path is NORMALIZED before its basename is read (NormalizeHome), because the rule is about the directory, not about the spelling that reached it: a home pinned as `.` from inside ~/.korbit-cli is that directory, and on a case-insensitive filesystem so is `~/.KORBIT-CLI`.

func NormalizeHome

func NormalizeHome(home string) string

NormalizeHome returns home as an absolute, lexically cleaned path — the form every comparison of one home against another, and the basename rule that picks the file names inside it, is made on.

Symlinks are deliberately NOT resolved: a home that is a symlink is a layout the user built on purpose, and resolving it would apply the file-name rule to an arbitrarily named target instead of to the name the user pinned.

A relative path with no working directory to resolve against (filepath.Abs fails only then) falls back to the cleaned original — there is nothing better available, and it is at least stable.

func Path

func Path(home string) string

Path is the config.json path under home.

func SetKeystore

func SetKeystore(home, backend string, log *slog.Logger) error

SetKeystore persists the default-keystore-for-new-keys choice into config.json (the `keystore default` command), leaving every other field (baseUrl, and any field this version doesn't model) exactly as it was.

func SetTUIColorScheme

func SetTUIColorScheme(home, scheme string, log *slog.Logger) error

SetTUIColorScheme persists the tui command's up/down color convention ("green-red" or "red-blue") under config.json's "tui" object, leaving every other field — top-level, and any other key inside "tui" — exactly as it was. The tui command calls it off the UI goroutine when the C key toggles the scheme.

func SetTUIOrderLevels

func SetTUIOrderLevels(home string, levels []int, log *slog.Logger) error

SetTUIOrderLevels persists the tui command's %-of-balance size presets under config.json's "tui" object, leaving every other field alone. The tui command pins the built-in defaults here on first launch.

func ValidBackend

func ValidBackend(name string) bool

ValidBackend reports whether name is a recognized keystore backend. It is the single home for the "is this a real backend" check — callers (the CLI command, the keystore constructors) should use it rather than re-listing Backends.

func ValidColorScheme

func ValidColorScheme(name string) bool

ValidColorScheme reports whether name is a recognized tui color-scheme value.

func ValidOrderLevels

func ValidOrderLevels(levels []int) bool

ValidOrderLevels reports whether levels is an acceptable size-preset list: 1..MaxOrderLevels entries, each a percentage in MinOrderLevel..MaxOrderLevel.

Types

type Config

type Config struct {
	// Keystore selects where NEWLY CREATED keys' private material goes: "file"
	// (default, encrypted file) or "keychain" (the OS keyring). It applies only
	// at key creation — every existing key carries its own backend in keys.json,
	// and changing this default never moves or re-routes an existing key (that
	// is `keystore migrate`'s job).
	Keystore string
	// BaseURL optionally overrides the REST base URL.
	BaseURL string
	// WSBaseURL optionally overrides the WebSocket base URL (scheme ws/wss),
	// used by the streaming `monitor` command. Empty means it is derived from
	// the resolved REST base URL.
	WSBaseURL string
	// TUIColorScheme is the persisted up/down color convention for the `tui`
	// command ("green-red" or "red-blue"), toggled with the C key and saved back
	// so it survives across launches. Stored under the "tui" object in
	// config.json. Empty means the TUI's default.
	TUIColorScheme string
	// TUIOrderLevels are the persisted %-of-balance size presets the `tui`
	// order UIs bind to number keys (e.g. [10,25,50,100], where 100 renders as
	// "max"). Stored under the "tui" object. Nil means unset — the tui command
	// pins the built-in defaults on first launch, so a later program update
	// never silently changes what a preset key does.
	TUIOrderLevels []int
}

Config is the resolved CLI configuration.

func Load

func Load(home string, log *slog.Logger) (Config, error)

Load reads config.json from home. A missing file yields the defaults (file backend, no base URL). Malformed config is a ConfigError. log (nil = silent) records the path, whether the file was present, and a parse failure — config.json holds no secrets, so it is safe to name the path.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL