CLI reference#
Meta: enumerated from cmd/dang/ (root main.go, repl_commands.go). The binary is a single Cobra command (dang) with three subcommands (fmt, init, migrate); running scripts, directory modules, the REPL, and LSP are all modes of the root command — there is no run/check subcommand.
Synopsis#
dang [flags] [file|directory] dang <file.dang> # run a single script dang <directory> # run a directory as a module dang # no path -> interactive REPL dang fmt [flags] [path...] dang init [dir] dang migrate [flags] [path...]
Root command#
dang <file.dang>— run a single.dangscript (RunFile)dang <directory>— run all.dangfiles in the directory as one module (RunDir). See Modules and imports.dang(no args) — start the interactive REPL (TUI)- accepts at most one positional path argument
Root flags#
-d, --debug— enable debug logging (slog at debug level)--debug-addr <addr>— serve debug/pprof handlers on this address (e.g.localhost:6060)--clear-cache— clear the GraphQL schema cache and exit. Cache lives under$XDG_CACHE_HOME/dang/schemas(or~/.cache/dang/schemas).--lsp— run as a Language Server (JSON-RPC over stdio)--lsp-log-file <path>— LSP log file (defaults to stderr)--cpuprofile <file>— write a CPU profile to file--version— print version (v0.1.0, commitdev) — provided by thefangwrapper-h, --help
dang fmt#
- format Dang source according to the canonical style. See Syntax and literals.
- args: one or more files/directories (directories are scanned for
*.dang, non-recursively) - flags:
-w, --write— write the result back to the source file (default: print to stdout)-l, --list— list files that would be formatted (or, with-w, that were changed)
dang init#
- make a directory (default:
.) a project whosedang.tomldeclares its Dang version (dang = "X.Y"; seedang.toml) - with no
dang.toml, creates one declaring the running Dang's version; adang.tomlwithout the key gets that version too, which is the one it already means: nothing changes meaning, and later Dang releases leave it pinned there - refuses a directory that is already part of a project further up
dang migrate#
- move every project under the given directories (default:
.) to a newer Dang version: each.dangfile adang.tomlgoverns is rewritten in the new version's syntax, and thedang.toml'sdangkey is updated with it - given a file, prints what migrating it makes of it, writing nothing;
-wrefuses a file, since migrating it alone would leave the rest of its project read in the new version without having been rewritten for it - only reports what it would change unless
-wis given; files spelled the same in both versions are left untouched - it rewrites syntax only: code a newer version rejects for other reasons (e.g. a stricter type check) is left for you to fix
- refuses a file whose meaning would change, e.g. old syntax inside a
#nofmtregion, which must be migrated by hand - flags:
-w, --write— write the migrated files anddang.toml--to <X.Y>— version to migrate to (default: the running Dang's version)--from <X.Y>— version of source whose version nodang.tomldeclares: source nodang.tomlgoverns (e.g. a Dagger module pinned by its engine version), or a project from an older Dang whosedang.tomlpredates thedangkey; migrating records the new version, creating adang.tomlif there is none. It applies to all such source under the given directories, nested projects without adangkey included; projects whosedang.tomldeclares a version migrate from it. Without it,migratelists the projects that declare no version, read as the running Dang's--skip-unparseable— leave files that don't parse in their version as they are (otherwise-wrefuses to write)
REPL#
Started by running dang with no path. Banner:
Welcome to Dang REPL v0.1.0 Imports: GitHub, Dagger Type :help for commands, Tab for completion, Alt+Enter for multiline, Ctrl+D to exit
The Imports: line appears only when dang.toml configures imports.
REPL commands (prefix :):
:help— list commands:exit/:quit— leave the REPL (also Ctrl+D):doc— interactive API/schema browser. See GraphQL interop.:env— show environment bindings:type <expr>— show the inferred type of an expression. A bounded type variable shows its bound, as a type parameter list does (:type [].sumis[a: Numeric] a!), and selecting a method whose type variables are bounded also shows the method's own signature (:type [1].sortaddsMethod: List.sort[a: Ordered](descending: Boolean = false): [a]!):find/:search <pattern>— find functions/types by pattern:reset— rebuild the environment from imports:clear— clear the screen:debug— toggle debug mode:version— show version + configured imports:history— show recent input history
Input keys: Tab completion, Up/Down history, Alt+Enter (or Shift+Enter under a Kitty-protocol terminal) for multiline, Ctrl+L to clear.
Configuration#
dang.toml's top-leveldang = "X.Y"key declares the Dang version the project is written for; seedang.toml.- GraphQL connections are configured per-import in
dang.tomlunder[imports.<Name>]. Keys:dagger,schema(local.graphqlsSDL path),endpoint,service(command that prints its endpoint/session JSON),authorization,headers. Apathkey instead imports a native Dang module (a local directory of.dangfiles); see Importing another Dang module. endpoint,authorization, andheadersvalues support${VAR}environment expansion.$(...)command substitution is not supported (use an env var instead). See Getting started and GraphQL interop.- config is discovered by walking up from the working directory, stopping at a
.gitboundary.
Exit codes#
0— success1— any error (runtime error, assertion failure, type/parse error, or a CLI usage error); there is no distinct exit code per failure kind
Editor integration#
- LSP via
dang --lsp(handler inpkg/lsp) — point your editor's LSP client at thedangbinary with that flag - hover shows a symbol's type, with the bounds of its type variables (
largest: [a: Ordered](x: a!, y: a!): a!); on a builtin method with bounds it adds the method's signature (// List.sum[a: Numeric]: a); on a closure it also lists the effects that limit where it can go — what it writes outside itself and which block parameters it calls, e.g.// Effects: writes n; calls block(see Closures that write can't escape) - editor configs under
editors/(nvim,vscode,zed)