cli

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 25 Imported by: 1 module, 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 cli is the open scanner's command line: scan one commit, derive its map, serve both to AI agents over MCP, compare a scan with a base scan the caller passes, write its bill of materials, write its architecture docs. Other commands can wrap it. See https://cernly.dev/how/open-core/.

scan [--repo id] [--out file] [--commit sha] [--committed-at rfc3339] [--exclude glob]... [--include glob]... [--no-repo-config] [--config file] [--plugins dir] [--trust-key key.pub]... <dir>
map [--default-branch main] [--out file] [--confirmations file] <facts.json>
mcp [--default-branch main] <facts.json | dir>
sbom [--default-branch main] [--service key] [--stack key] [--out file] <facts.json>
gate --base <earlier.facts.json> [--default-branch main] [--format text|json|sarif] [--out file] <facts.json>
docs [--default-branch main] [--out file.md] <facts.json>
plugin keygen [--test] --out prefix
plugin sign --key key.key --manifest manifest.json [--out dir] <module.wasm>
plugin verify [--trust-key key.pub]... <dir>
help | -h | --help

Usage prints the same list, built from the flag sets. The plugin commands sign and verify WebAssembly plugins.

Same commit + same binary + same operator flags = byte-identical output. The map is derived from a facts file alone: same facts + same rules version + same settings = byte-identical map.

Index

Constants

View Source
const (
	GateOK      = 0
	GateBlocked = 1
	GateError   = 2
)

Gate exit codes: 0 nothing or only warnings, 1 a finding at level block, 2 an error (as flag parsing already uses).

View Source
const (
	EnvPluginDir  = "CERNLY_PLUGIN_DIR"  // folder of <name>.wasm + <name>.plugin.json
	EnvPluginKeys = "CERNLY_PLUGIN_KEYS" // PEM public keys to trust, separated by the OS list separator
)

Environment defaults for the plugin flags, so a program that embeds this package loads the same WebAssembly plugins as `scan`.

Variables

View Source
var MapFacts = pipeline.Map

MapFacts derives a map from a facts file. A wrapping command may replace it to accept more schema ids than the open core does.

Functions

func BuildDocs

func BuildDocs(path, branch string, o archdoc.Options) ([]byte, error)

BuildDocs reads a facts file, derives its map and writes the Markdown.

func BuildSBOM

func BuildSBOM(path, branch, service string) ([]byte, error)

BuildSBOM reads a facts file, derives its map and writes the BOM as canonical JSON.

func BuildSBOMScope

func BuildSBOMScope(path, branch string, sc sbom.Scope) ([]byte, error)

BuildSBOMScope is BuildSBOM for a service or a stack.

func Docs

func Docs(args []string)

Docs writes the architecture documentation of one scan as Markdown: arc42 sections, C4 context and container views in Mermaid, every statement with a footnote naming its facts, file and line.

func Gate

func Gate(args []string)

Gate compares a facts file with a base facts file the caller passes and exits 1 when a finding is at level block.

func IsHelp

func IsHelp(args []string) bool

IsHelp reports whether args ask for the usage text: help, -h or --help.

func LoadPlugins

func LoadPlugins(dir string, keyFiles []string) ([]plugin.Plugin, error)

LoadPlugins returns plugin.All() plus the WebAssembly plugins in dir, signed by Cernly or by one of the key files. A plugin that does not load, or that takes a built-in's name, is an error: the operator asked for it.

func LoadSource

func LoadSource(path, branch string) (*mcp.Source, error)

LoadSource reads a facts file, or scans a directory's HEAD, and derives the map. Scan warnings go to stderr: stdout belongs to the protocol.

func MCP

func MCP(args []string)

MCP serves one scan over stdio. Given a directory it scans the commit at HEAD first, with the repo's own hint file; given a facts file it serves that file.

func Main

func Main(args []string) bool

Main runs one of the open commands and reports whether args named one.

func Map

func Map(args []string)

Map derives the map from a facts file.

func NewFlagSet

func NewFlagSet(name string, args []string) *flag.FlagSet

NewFlagSet returns the flag set of a command that exits on a parse error. Asked for help with -h or --help, it prints the flags to stdout and exits 0; a parse error still goes to stderr.

func PluginCmd

func PluginCmd(args []string)

PluginCmd is `cernly plugin keygen | sign | verify`: what a plugin author needs to ship a module the scanner loads.

plugin keygen [--test] --out name   writes name.key (private) and name.pub
plugin sign --key name.key --manifest manifest.json [--out dir] module.wasm
plugin verify --trust-key name.pub [--trust-key ...] dir

func ReadConfirmations

func ReadConfirmations(path string) ([]rules.Confirmation, error)

ReadConfirmations reads a JSON array of confirmations, as a map's settings.confirmations holds them, so a map can be derived again.

func ReadOperatorFile

func ReadOperatorFile(op *config.Operator, name string)

ReadOperatorFile loads --config into the operator settings.

func RenderGate

func RenderGate(r *rules.GateResult, format string) ([]byte, error)

RenderGate writes a result as text, canonical JSON or SARIF 2.1.0.

func RunGate

func RunGate(basePath, headPath, branch string) (*rules.GateResult, error)

RunGate reads both facts files, derives both maps with the same settings and compares them.

func SBOM

func SBOM(args []string)

SBOM writes a CycloneDX 1.6 bill of materials for one scan: the whole repo, or one service with --service.

func Scan

func Scan(args []string)

Scan runs every plugin on one commit and writes the facts file.

func Usage

func Usage(prog string, extra ...string) string

Usage lists the open commands with every flag each accepts, for a wrapping command's own usage text. Each extra line is added after the open commands.

func Write

func Write(out string, data []byte)

Write writes data plus a newline to a file, or to stdout for "-".

Types

type Multi

type Multi []string

Multi is a repeatable string flag.

func (*Multi) Set

func (m *Multi) Set(v string) error

func (*Multi) String

func (m *Multi) String() string

type PluginFlags

type PluginFlags struct {
	Dir  string
	Keys Multi
}

PluginFlags adds --plugins and --trust-key to a flag set.

func (*PluginFlags) Plugins

func (pf *PluginFlags) Plugins() ([]plugin.Plugin, error)

Plugins returns the built-in plugins plus the loaded ones, sorted by name.

func (*PluginFlags) Register

func (pf *PluginFlags) Register(fs *flag.FlagSet)

Jump to

Keyboard shortcuts

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