runtime

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package runtime is the proto-free half of the Metalhost CLI library.

It exposes:

  • Options / Profile aliases consumers need
  • NewRootCommand — builds a BARE cobra root (persistent flags + version + profile management). No customer commands are attached here, and no SDK gen/aes/* packages are imported transitively.
  • Runtime helpers (RuntimeFromCommand, SDKConfig, Write) for callers that want to make API calls themselves once authenticated.

The customer-facing CLI (`metalhost` binary) wraps this package in pkg/metalhostcli, which adds the full vm/disk/network/... command tree.

Internal admin tools (the `mh` binary in the Metalhost backend repo) import this package directly to avoid pulling in customer proto descriptors and triggering a duplicate-registration panic — the backend already has its own generated copy of those proto packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRootCommand

func NewRootCommand(opts Options) *cobra.Command

NewRootCommand returns a bare cobra root command — persistent flags, plus the truly common subcommands (`version`, `profile`). Callers attach their own command tree on top.

Types

type Options

type Options struct {
	// Use is the cobra Use string (binary name).
	Use string
	// Short is the one-line description shown in --help.
	Short string
	// UserAgent is sent on outgoing API calls. Falls back to a derived value.
	UserAgent string
}

Options configures the bare cobra root produced by NewRootCommand.

type Profile

type Profile = config.Profile

Profile is re-exported for callers that want to type Profile pointers without depending on internal/config directly.

type Runtime

type Runtime struct {
	Profile   *Profile
	UserAgent string
}

Runtime carries the active profile + the user-agent string for outgoing requests. Build one with RuntimeFromCommand at the start of a RunE handler.

func RuntimeFromCommand

func RuntimeFromCommand(cmd *cobra.Command, userAgent string) (*Runtime, error)

RuntimeFromCommand reads the persistent flags off the root command and builds a Runtime tied to the active profile. RunE handlers should call this first; surface its error to the user.

func (*Runtime) SDKConfig

func (r *Runtime) SDKConfig() (metalhost.Config, error)

SDKConfig converts the active Runtime into a metalhost SDK Config. Returns a clear error when no endpoint is set (the most common misconfiguration).

func (*Runtime) Write

func (r *Runtime) Write(value any) error

Write renders a value to stdout in the active profile's format.

Jump to

Keyboard shortcuts

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