Manuscript Documentation
v2026.12.0

Command-line programs#

Print output, read arguments and build a command with subcommands and flags. Each program is a complete .ms file: save it under the shown name and run the command from that directory (getting started ). main returns the exit status.

Save as hello.ms. print is available without an import and adds a newline.

Manuscript
fn main() Void {
    print("Hello, Manuscript!")
}
sh
ms run hello.ms
text
Hello, Manuscript!

print returns Void. The next recipe uses stdout().write(...) and stdout().flush() to control text and flushing explicitly. These methods use the stream Result interface, but ordinary stdout does not expose native write errors through it. Use stdout_bytes() for byte output.

Read command-line arguments#

Save as args.ms. arguments() excludes the executable; values after -- reach your program.

Manuscript
import (
    stdout from "@std/io/io.ms",
    arguments from "@std/os/env.ms",
)

fn run() Result[Void, Error] {
    for name in arguments() {
        stdout().write(f"Hello, {name}!\n")?
    }
    return stdout().flush()
}

fn main() Void! {
    return run()
}
sh
ms run args.ms -- Sam Ada
text
Hello, Sam!
Hello, Ada!

Parse subcommands and flags#

Save as tool.ms. @std/cli/command.ms resolves nested commands, typed flags and positional arguments, writes --help, and hands your handler a value of a type you define: each field is filled from the flag or argument with the same name (dry-run fills dry_run). Usage errors print a message and exit with status 2.

Manuscript
import (
    Arg, Command, Flag, FlagKind, command from "@std/cli/command.ms",
    stdout from "@std/io/io.ms",
    arguments from "@std/os/env.ms",
)

type Greeting {
    name String
    times Int
}

fn greet(options Greeting) Result[Int, Error] {
    for round in 0..options.times {
        stdout().write(f"Hello, {options.name}!\n")?
    }
    stdout().flush()?
    return ok(0)
}

fn main() Int {
    hello := command[Greeting](
        name: "hello",
        about: "Print a greeting",
        flags: [Flag("times", FlagKind.Int, "n", "1", "Repeat count")],
        args: [Arg("name", "Who to greet")],
        run: options => greet(options),
    )
    return Command(name: "tool", about: "Example tool", children: [hello]).execute(
        arguments()
    )
}
sh
ms run tool.ms -- hello Ada -n 2
text
Hello, Ada!
Hello, Ada!

Run ms run tool.ms -- hello --help to see the command’s arguments and flags.