Documentation
¶
Overview ¶
Package config resolves the CLI home directory and loads config.json.
Index ¶
- Constants
- Variables
- func Home(getenv func(string) string) string
- func LegacyLayout(home string) bool
- func NormalizeHome(home string) string
- func Path(home string) string
- func SetKeystore(home, backend string, log *slog.Logger) error
- func SetTUIColorScheme(home, scheme string, log *slog.Logger) error
- func SetTUIOrderLevels(home string, levels []int, log *slog.Logger) error
- func ValidBackend(name string) bool
- func ValidColorScheme(name string) bool
- func ValidOrderLevels(levels []int) bool
- type Config
Constants ¶
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.
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.
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 ¶
var Backends = []string{"file", "keychain"}
Backends are the supported keystore backend names.
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 ¶
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 ¶
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 ¶
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 SetKeystore ¶
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 ¶
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 ¶
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 ¶
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 ¶
ValidColorScheme reports whether name is a recognized tui color-scheme value.
func ValidOrderLevels ¶
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.