cmd2pkg

command
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package bb builds one busybox-like binary out of many Go command sources.

This allows you to take two Go commands, such as Go implementations of `sl` and `cowsay` and compile them into one binary, callable like `./bb sl` and `./bb cowsay`. Which command is invoked is determined by `argv[0]` or `argv[1]` if `argv[0]` is not recognized.

Under the hood, bb implements a Go source-to-source transformation on pure Go code. This AST transformation does the following:

  • Takes a Go command's source files and rewrites them into Go package files without global side effects.
  • Writes a `main.go` file with a `main()` that calls into the appropriate Go command package based on `argv[0]`.

Principally, the AST transformation moves all global side-effects into callable package functions. E.g. `main` becomes `registeredMain`, each `init` becomes `initN`, and global variable assignments are moved into their own `initN`.

cmd2pkg converts one or more commands into a set of packages.

Directories

Path Synopsis
Package bbinternal is the internal API for both bazel and standard Go busybox builds.
Package bbinternal is the internal API for both bazel and standard Go busybox builds.
Package findpkg finds packages from user-input strings that are either file paths or Go package paths.
Package findpkg finds packages from user-input strings that are either file paths or Go package paths.
test/goglob/foo command

Jump to

Keyboard shortcuts

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