Skip to content

Include argv[0] in IO.args() (or add IO.program_name) #935

Description

@noah-emp

Behavior

A Bend program’s IO.args() list is the process arguments after the runtime strips its own flags (--threads, --gpu, --gpu-build, --help). It does not include argv[0] (the executable / script path).

So a compiled or JS-emitted CLI cannot recover its own invocation name for usage text, relative resource paths, or re-exec, without a foreign effect or an external wrapper.

Minimal example

# args_demo.bend
import Base

def widen(ss: List<&1, String>) -> List<&2, String>:
  match ss:
    case Nil{}:
      Nil{}
    case Con{s, t}:
      s <> widen(t)

def show_all(ss: List<&2, String>) -> String:
  match ss:
    case Nil{}:
      "(none)"
    case Con{h, t}:
      "[" ++ h ++ "] " ++ show_all(t)

def main() -> IO(Unit):
  do IO<Unit>:
    ss : List<&1, String> <- IO.args()
    IO.print(show_all(widen(ss)))
bend args_demo.bend -o args_demo.js
node args_demo.js hello world
# prints: [hello] [world] (none)
# not: [<path-to-args_demo.js>] [hello] [world] (none)

node args_demo.js
# prints: (none)

(Same shape on a native -o binary once clang is available.)

Request

Prefer one of:

  1. Prepend argv[0] to IO.args(), or
  2. Add a dedicated IO.program_name() -> IO(String) (or similar) that returns argv[0] without changing the existing args list.

Goal: a Bend CLI can print usage: <name> … and locate itself the way users expect.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions