Process execution and file access go through @process and @fs. The spinner is a background task in a task group, and the C stub keeps only getenv, exit, isatty, symlink and stderr output. orbit info reads installed state only, and it records and restores package descriptions. just install adds Orbit's bin directory to ~/.bashrc once. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
155 lines
5.0 KiB
MoonBit
155 lines
5.0 KiB
MoonBit
// orbit: a package manager whose repository is any OCI registry, via ORAS.
|
|
|
|
///|
|
|
let usage : String =
|
|
#|orbit - packages as OCI artifacts (via oras)
|
|
#|
|
|
#|usage:
|
|
#| orbit init create folders and config.toml
|
|
#| orbit channel list channels, highest priority first
|
|
#| orbit channel add <name> <url> [--plain-http]
|
|
#| orbit publish <dir> [--channel <name>] [--no-latest]
|
|
#| push <dir>/orbit.json + <dir>/files/
|
|
#| orbit install [channel::]<name>[@constraint]...
|
|
#| install with dependencies
|
|
#| orbit remove <name>... [--force] remove, then drop unused dependencies
|
|
#| orbit upgrade [name...] upgrade within constraints
|
|
#| orbit rollback <name> switch to the previous build
|
|
#| orbit list installed packages
|
|
#| orbit info [channel::]<name> installed package details (local only)
|
|
#| orbit versions <name> published versions
|
|
#| orbit search [term] list repositories (needs catalog API)
|
|
#| orbit gc delete unused builds from the store
|
|
#| orbit env print the PATH line for your shell
|
|
#|
|
|
#|constraints: 1.2.3 =1.2.3 1.2 ^1.2.0 ~1.2.0 >=1.2 *
|
|
#|config: <orbit root>/config.toml
|
|
#|environment: ORBIT_ROOT (default ~/.orbit); ORBIT_REGISTRY and
|
|
#| ORBIT_PLAIN_HTTP=1 override the built-in main channel
|
|
#|authentication: run `oras login <registry-host>` once.
|
|
|
|
///|
|
|
/// Create the directories, and a config.toml if there is no config yet.
|
|
async fn cmd_init() -> Unit raise OrbitError {
|
|
let root = orbit_root()
|
|
sh_ok(
|
|
"mkdir -p " +
|
|
sq(root + "/bin") +
|
|
" " +
|
|
sq(root + "/store") +
|
|
" " +
|
|
sq(root + "/tmp"),
|
|
)
|
|
let config = root + "/config.toml"
|
|
// A legacy config.json is still honored, so don't hide it with a new file.
|
|
if !exists(config) && !exists(root + "/config.json") {
|
|
write_text_atomic(config, config_template)
|
|
}
|
|
println("orbit root: \{root}")
|
|
println("channels:")
|
|
print_channels(load_ctx().channels)
|
|
println("add to your shell profile:")
|
|
println(" export PATH=\"\{root}/bin:$PATH\"")
|
|
}
|
|
|
|
///|
|
|
fn need(pos : Array[String], n : Int32, what : String) -> Unit raise OrbitError {
|
|
if pos.length() < n {
|
|
raise OrbitError("usage: orbit \{what}")
|
|
}
|
|
}
|
|
|
|
///|
|
|
async fn dispatch(args : Array[String]) -> Unit raise OrbitError {
|
|
if args.length() == 0 {
|
|
println(usage)
|
|
return
|
|
}
|
|
let cmd = args[0]
|
|
let pos : Array[String] = []
|
|
let flags : Array[String] = []
|
|
let mut publish_to = MAIN_CHANNEL
|
|
let mut i = 1
|
|
while i < args.length() {
|
|
if args[i] == "--channel" {
|
|
if cmd != "publish" || i + 1 >= args.length() {
|
|
raise OrbitError("usage: orbit publish <dir> --channel <name>")
|
|
}
|
|
publish_to = args[i + 1]
|
|
i = i + 1
|
|
} else if has_prefix(args[i], "--") {
|
|
flags.push(args[i])
|
|
} else {
|
|
pos.push(args[i])
|
|
}
|
|
i = i + 1
|
|
}
|
|
match cmd {
|
|
"help" | "-h" | "--help" => println(usage)
|
|
"init" => {
|
|
if pos.length() > 0 {
|
|
raise OrbitError(
|
|
"init takes no arguments; use `orbit channel add <name> <url>`",
|
|
)
|
|
}
|
|
cmd_init()
|
|
}
|
|
"channel" => {
|
|
need(pos, 1, "channel list|add")
|
|
match pos[0] {
|
|
"list" => print_channels(load_ctx().channels)
|
|
"add" => {
|
|
need(pos, 3, "channel add <name> <url> [--plain-http]")
|
|
cmd_channel_add(
|
|
orbit_root(),
|
|
pos[1],
|
|
pos[2],
|
|
flags.contains("--plain-http"),
|
|
)
|
|
}
|
|
other => raise OrbitError("unknown channel command '\{other}'")
|
|
}
|
|
}
|
|
"env" => println("export PATH=\"\{orbit_root()}/bin:$PATH\"")
|
|
"publish" => {
|
|
need(pos, 1, "publish <dir>")
|
|
let ch = find_channel(load_ctx(), publish_to)
|
|
publish(ch, pos[0], !flags.contains("--no-latest"))
|
|
}
|
|
"install" | "add" => cmd_install(load_ctx(), pos)
|
|
"remove" | "rm" => cmd_remove(load_ctx(), pos, flags.contains("--force"))
|
|
"upgrade" | "up" => cmd_upgrade(load_ctx(), pos)
|
|
"rollback" => {
|
|
need(pos, 1, "rollback <name>")
|
|
cmd_rollback(load_ctx(), pos[0])
|
|
}
|
|
"list" | "ls" => cmd_list(load_ctx())
|
|
"info" => {
|
|
need(pos, 1, "info [channel::]<name>")
|
|
cmd_info(load_ctx(), pos[0])
|
|
}
|
|
"versions" => {
|
|
need(pos, 1, "versions <name>")
|
|
cmd_versions(load_ctx(), pos[0])
|
|
}
|
|
"search" =>
|
|
cmd_search(load_ctx(), if pos.length() > 0 { pos[0] } else { "" })
|
|
"gc" => cmd_gc(load_ctx())
|
|
_ => raise OrbitError("unknown command '\{cmd}' (try `orbit help`)")
|
|
}
|
|
}
|
|
|
|
///|
|
|
async fn main {
|
|
if sh("command -v oras >/dev/null 2>&1") != 0 {
|
|
println("orbit: error: `oras` not found on PATH (https://oras.land)")
|
|
c_exit(1)
|
|
}
|
|
dispatch(cli_args()) catch {
|
|
OrbitError(msg) => {
|
|
println("orbit: error: \{msg}")
|
|
c_exit(1)
|
|
}
|
|
}
|
|
}
|