cli

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigDir

func ConfigDir() (string, error)

ConfigDir returns the path to the config directory (~/.local/sandbox-cli/).

func ConfigPath

func ConfigPath() (string, error)

ConfigPath returns the path to the config file.

func Execute

func Execute()

Execute runs the root command.

func ReadError

func ReadError(resp *http.Response) error

ReadError reads the response body and returns it as an error string. It also closes the body.

func ReadJSON

func ReadJSON(resp *http.Response, v any) error

ReadJSON reads the response body and decodes it into v. It also closes the body. Returns an error with the body text on non-2xx status.

func SetBuildInfo

func SetBuildInfo(version, commit, buildTime string)

SetBuildInfo sets build-time info from ldflags.

Types

type Client

type Client struct {
	BaseURL    string
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

Client wraps HTTP calls to the sandbox API.

func NewClient

func NewClient(baseURL, accessToken string) *Client

NewClient creates a client with the given base URL and access token.

func (*Client) Delete

func (c *Client) Delete(path string) (*http.Response, error)

Delete performs a DELETE request.

func (*Client) Get

func (c *Client) Get(path string) (*http.Response, error)

Get performs a GET request and returns the raw response.

func (*Client) Post

func (c *Client) Post(path string, body io.Reader) (*http.Response, error)

Post performs a POST request with a JSON body.

func (*Client) Put

func (c *Client) Put(path string, body io.Reader) (*http.Response, error)

Put performs a PUT request with an optional JSON body.

type Config

type Config struct {
	Server      string     `json:"server"`
	LoginToken  string     `json:"login_token"`
	AccessToken string     `json:"access_token,omitempty"`
	AccessExp   *time.Time `json:"access_token_exp,omitempty"`
}

Config holds persisted CLI state.

func LoadConfig

func LoadConfig() (Config, error)

LoadConfig reads config from disk. Returns zero Config if file doesn't exist.

func (Config) HasValidAccessToken

func (c Config) HasValidAccessToken() bool

HasValidAccessToken returns true if the access token exists and hasn't expired.

func (Config) Save

func (c Config) Save() error

Save writes config to disk, creating the directory if needed.

type LoginResponse

type LoginResponse struct {
	AccessToken    string     `json:"access_token"`
	AccessTokenExp *time.Time `json:"access_token_exp"`
}

LoginResponse is the response from GET /api/v1/login.

func Login

func Login(baseURL, loginToken string) (*LoginResponse, error)

Login exchanges a login token for an access token.

Jump to

Keyboard shortcuts

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