harbor run -t openthoughts/tasktrove-exp-flat25-pseudocode-v2-5k-pseudocode-4597harbor download openthoughts/tasktrove-exp-flat25-pseudocode-v2-5k-pseudocode-4597PSEUDOCODE
MODULE brownie._cli.main
docstring := """ Brownie CLI entry point. Use as a lightweight dispatcher for subcommands. Exposes main() and uses this module's docstring as help text when invoked without arguments. Commands: - init [PATH] [--force] - bake TOKEN [PATH] [--force] - compile [--all] - analyze - run PATH [-r] - ethpm LIST| - test [ARGS...] - pm list """
all := ["main"]
FUNCTION main(): args := CAPTURE(sys.argv[1:]) // list of command-line arguments excluding program name
IF LENGTH(args) == 0 THEN
PRINT(docstring)
RAISE SystemExit
cmd := args[0]
rest := args[1:]
KNOWN_COMMANDS := ["init", "bake", "compile", "analyze", "run", "ethpm", "test", "pm"]
IF cmd NOT IN KNOWN_COMMANDS THEN
IF cmd == "account" THEN
RAISE SystemExit("Unknown command: account. Did you mean 'brownie accounts'?")
ELSE
RAISE SystemExit("Unknown command: " + cmd + ". Did you mean 'brownie accounts'?")
// Helpers (conceptual)
FUNCTION project_loaded() -> BOOLEAN
RETURN brownie.project._loaded // true if a project has been loaded in memory
FUNCTION current_project_path() -> STRING OR None
IF project_loaded() THEN RETURN brownie.project.path
ELSE RETURN None
// Subcommand dispatch
IF cmd == "init" THEN
path := "."
force := FALSE
FOR a IN rest DO
IF a == "--force" THEN
force := TRUE
ELSE
path := a
brownie.project.new(path, force, force)
ELSE IF cmd == "bake" THEN
IF LENGTH(rest) == 0 THEN
RAISE SystemExit("Missing required TOKEN for bake")
token := rest[0]
remaining := REST(rest, 1) // all items after token
path := None
force := FALSE
FOR a IN remaining DO
IF a == "--force" THEN
force := TRUE
ELSE
path := a
brownie.project.from_brownie_mix(token, path, force)
ELSE IF cmd == "compile" THEN
// --all flag exists but per tests both forms call load() with no args
TRY
brownie.project.load()
CATCH ProjectNotFoundError
RAISE SystemExit
END TRY
ELSE IF cmd == "analyze" THEN
IF NOT project_loaded() THEN
RAISE SystemExit
END IF
// Analysis path (may be a call to brownie.project.analyze if defined)
brownie.project.analyze() // optional based on implementation
ELSE IF cmd == "run" THEN
IF LENGTH(rest) == 0 THEN
RAISE SystemExit("Missing PATH for run")
path := rest[0]
options := REST(rest, 1)
IF "-r" IN options THEN
RAISE FileNotFoundError(path)
ELSE
// May establish network connection; tests only require a single call to brownie.run(path)
brownie.run(path)
ELSE IF cmd == "ethpm" THEN
// ethpm LIST|<name>
sub := IF LENGTH(rest) > 0 THEN rest[0] ELSE "list"
project_path := current_project_path()
TRY
IF sub == "list" THEN
brownie._cli.ethpm._list(project_path)
ELSE
brownie._cli.ethpm._list(project_path, sub)
END IF
CATCH TypeError
// If _list raises TypeError, CLI should exit and not call further subroutines
RETURN
END TRY
// If project not found, main() should raise SystemExit (handled by _list or callers)
ELSE IF cmd == "test" THEN
// Forward to pytest.main with required arguments
tests_path := get_test_project_tests_path() // derives path from test project fixture
IF LENGTH(rest) == 0 THEN
pytest_args := [tests_path]
pytest_keywords := ["pytest-brownie"]
ELSE
pytest_args := rest
pytest_keywords := ["pytest-brownie"]
END IF
pytest.main(pytest_args, pytest_keywords)
ELSE IF cmd == "pm" THEN
// Minimal no-op implementation for pm list
// Do not trigger other subroutines unless explicitly required
PASS
END FUNCTION
END MODULE