larkcli

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package larkcli provides a subprocess bridge to the official Feishu/Lark CLI tool (lark-cli). GitCode CLI delegates Feishu operations (messaging, auth status) to lark-cli instead of reimplementing the Feishu OpenAPI and OAuth flow in Go. lark-cli keeps its own credentials in the OS keychain.

Index

Constants

View Source
const EnvBin = "GC_LARK_CLI_BIN"

EnvBin overrides the resolved lark-cli binary path. When set and pointing to an executable file, it takes precedence over PATH lookup.

View Source
const EnvDefaultChat = "GC_LARK_DEFAULT_CHAT_ID"

EnvDefaultChat overrides the default Feishu chat id used by notifications.

Variables

View Source
var ErrNotInstalled = errors.New("lark-cli is not installed; run: gc lark install")

ErrNotInstalled is returned when lark-cli cannot be found on PATH or via GC_LARK_CLI_BIN.

Functions

func ClearDefaultChat

func ClearDefaultChat() error

ClearDefaultChat removes the persisted default chat id.

func ConfigPath

func ConfigPath() string

ConfigPath returns the lark config file path (~/.config/gc/lark.json or $GC_CONFIG_DIR/lark.json).

func DefaultChatID

func DefaultChatID() string

DefaultChatID resolves the default Feishu chat id from, in priority order: the GC_LARK_DEFAULT_CHAT_ID environment variable, then the persisted lark.json. Returns an empty string when nothing is configured.

func EnsureInstalled

func EnsureInstalled() error

EnsureInstalled returns ErrNotInstalled when lark-cli is not available.

func FindLarkCLI

func FindLarkCLI() string

FindLarkCLI resolves the lark-cli binary path. It returns an empty string when no usable binary is found.

func SaveDefaultChat

func SaveDefaultChat(chatID string) error

SaveDefaultChat persists the default chat id to lark.json.

Types

type Installer

type Installer struct {
	// Stdout and Stderr receive installer output.
	Stdout io.Writer
	Stderr io.Writer
	// Stdin is forwarded to the installer (interactive prompts).
	Stdin io.Reader
	// contains filtered or unexported fields
}

Installer runs the official lark-cli installer. It is split out so the command layer can inject a fake for tests.

func (*Installer) Install

func (i *Installer) Install() error

Install runs `npx @larksuite/cli@latest install`. On success lark-cli is available on PATH.

type Result

type Result struct {
	Stdout   []byte
	Stderr   []byte
	ExitCode int
}

Result holds the captured output of a lark-cli invocation.

func JSONResult

func JSONResult(run RunFunc, args []string) (*Result, error)

JSONResult runs lark-cli with "--json" appended and returns raw stdout. Callers parse the JSON payload according to lark-cli's success/error envelope contract.

type RunFunc

type RunFunc func(args []string) (*Result, error)

RunFunc is the injectable signature for executing lark-cli subcommands. Command packages accept a RunFunc so tests can stub out the subprocess.

var DefaultRun RunFunc = func(args []string) (*Result, error) {
	bin := FindLarkCLI()
	if bin == "" {
		return nil, ErrNotInstalled
	}
	return runExec(bin, args)
}

DefaultRun is the production RunFunc. It resolves lark-cli via FindLarkCLI and executes it with the given args. stdin is NOT inherited (gc passes all content as explicit args; lark-cli never needs gc's stdin) and GitCode tokens (GC_TOKEN/GITCODE_TOKEN) are stripped from the child environment as defense in depth — lark-cli only needs its own keychain credentials.

Source Files

  • config.go
  • install.go
  • larkcli.go

Jump to

Keyboard shortcuts

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