Class: MilkTea::CLI
- Inherits:
-
Object
- Object
- MilkTea::CLI
- Includes:
- CommandBase, CommandBindgen, CommandBuild, CommandCache, CommandCheck, CommandCompletions, CommandDap, CommandDebug, CommandDeps, CommandDocs, CommandEmitC, CommandFormat, CommandLex, CommandLint, CommandLower, CommandLsp, CommandNew, CommandParse, CommandRun, CommandSnapshot, CommandTest, CommandToolchain
- Defined in:
- lib/milk_tea/tooling/cli.rb,
lib/milk_tea/tooling/cli/commands/dap.rb,
lib/milk_tea/tooling/cli/commands/lex.rb,
lib/milk_tea/tooling/cli/commands/lsp.rb,
lib/milk_tea/tooling/cli/commands/new.rb,
lib/milk_tea/tooling/cli/commands/run.rb,
lib/milk_tea/tooling/cli/commands/deps.rb,
lib/milk_tea/tooling/cli/commands/docs.rb,
lib/milk_tea/tooling/cli/commands/lint.rb,
lib/milk_tea/tooling/cli/commands/test.rb,
lib/milk_tea/tooling/cli/commands/build.rb,
lib/milk_tea/tooling/cli/commands/cache.rb,
lib/milk_tea/tooling/cli/commands/check.rb,
lib/milk_tea/tooling/cli/commands/debug.rb,
lib/milk_tea/tooling/cli/commands/lower.rb,
lib/milk_tea/tooling/cli/commands/parse.rb,
lib/milk_tea/tooling/cli/commands/emit_c.rb,
lib/milk_tea/tooling/cli/commands/format.rb,
lib/milk_tea/tooling/cli/commands/bindgen.rb,
lib/milk_tea/tooling/cli/commands/snapshot.rb,
lib/milk_tea/tooling/cli/commands/toolchain.rb,
lib/milk_tea/tooling/cli/commands/completions.rb,
lib/milk_tea/tooling/cli/commands/command_base.rb
Defined Under Namespace
Modules: CommandBase, CommandBindgen, CommandBuild, CommandCache, CommandCheck, CommandCompletions, CommandDap, CommandDebug, CommandDeps, CommandDocs, CommandEmitC, CommandFormat, CommandLex, CommandLint, CommandLower, CommandLsp, CommandNew, CommandParse, CommandRun, CommandSnapshot, CommandTest, CommandToolchain
Constant Summary collapse
- GENERATED_FILE_HEADER_PREFIX =
"# generated by mtc".freeze
- COMMANDS =
Single source of truth for the top-level command set: used by the help overview and shell-completion generation so they cannot drift.
[ ["check", "Type-check and lint source files"], ["build", "Compile a source file or package"], ["run", "Build and execute a program"], ["run-module", "Resolve, build, and run a module by name"], ["test", "Discover and run @[test] functions"], ["new", "Scaffold a new package"], ["format", "Format source files in place or check formatting"], ["lint", "Lint source files and report warnings"], ["lex", "Print the lexer token stream"], ["parse", "Parse source and print the AST"], ["lower", "Lower source to IR and print it"], ["emit-c", "Compile source to C and print it"], ["debug", "Print tokens, AST, facts, and diagnostics"], ["deps", "Manage package dependencies"], ["toolchain", "Manage the native toolchain"], ["bindgen", "Generate a binding module from a C header"], ["cache", "Inspect and manage the build cache"], ["docs", "Serve the local documentation site"], ["snapshot", "Render a highlighted HTML snapshot"], ["lsp", "Start the Language Server Protocol server"], ["dap", "Start the Debug Adapter Protocol server"], ["completions", "Print a shell completion script"], ].freeze
Constants included from CommandTest
CommandTest::TEST_RUN_MEMORY_LIMIT_BYTES, CommandTest::TEST_RUN_TIMEOUT_SECONDS
Class Method Summary collapse
- .start(argv = ARGV, out: $stdout, err: $stderr, source_overrides: nil, build_frontend: nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(argv, out:, err:, source_overrides: nil, build_frontend: nil) ⇒ CLI
constructor
A new instance of CLI.
- #start ⇒ Object
Methods included from CommandCompletions
#completion_script, #completions_command
Methods included from CommandDap
#dap_command, #resolve_adapter_path
Methods included from CommandLsp
Methods included from CommandSnapshot
Methods included from CommandDocs
#docs_command, #resolve_docs_port
Methods included from CommandCache
Methods included from CommandBindgen
Methods included from CommandDeps
Methods included from CommandToolchain
Methods included from CommandDebug
Methods included from CommandNew
Methods included from CommandRun
#app_command, #extract_path_and_options, #resolve_app_module, #run_and_print_result, #run_command
Methods included from CommandTest
#classify_death_test, #classify_test_file, #compile_fail_diagnostics, #compile_fail_fixture?, #death_test_runner_main, #discover_test_files, #dispatch_test_run, #emit_junit, #emit_machine_results, #emit_tap, #expect_fatal_attribute?, #extract_expect_error_directives, #extract_test_limit_flags!, #matches_filter?, #parse_test_output, #run_classified_file, #run_compile_fail_test, #run_death_test, #run_synthesized_tests, #run_test_binary, #run_test_directory, #run_test_file, #run_test_file_guarded, #run_test_files_parallel, #spawn_sandboxed, #test_attribute?, #test_command, #test_runner_main, #with_synthesized_binary, #xml_escape
Methods included from CommandBuild
Methods included from CommandEmitC
#emit_c_command, #resolve_program_path
Methods included from CommandLower
Methods included from CommandCheck
#check_command, #check_single_reporting_all, #sort_by_location
Methods included from CommandLint
#init_lint_config, #lint_command, #lint_sema_facts_for, #print_lint_file_profiles, #print_lint_rule_profiles
Methods included from CommandFormat
#format_command, #format_paths, #parse_format_options, #print_file_profiles
Methods included from CommandParse
Methods included from CommandLex
Constructor Details
#initialize(argv, out:, err:, source_overrides: nil, build_frontend: nil) ⇒ CLI
Returns a new instance of CLI.
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/milk_tea/tooling/cli.rb', line 46 def initialize(argv, out:, err:, source_overrides: nil, build_frontend: nil) @argv = argv.dup @out = out @err = err @include_module_roots = [] @include_path_flags = [] @ambient_module_roots = MilkTea::ModuleRoots.roots_for_path(Dir.pwd) @source_overrides = normalize_source_overrides(source_overrides) @build_frontend = build_frontend @color = :auto @verbose = false @quiet = false end |
Class Method Details
.start(argv = ARGV, out: $stdout, err: $stderr, source_overrides: nil, build_frontend: nil) ⇒ Object
42 43 44 |
# File 'lib/milk_tea/tooling/cli.rb', line 42 def self.start(argv = ARGV, out: $stdout, err: $stderr, source_overrides: nil, build_frontend: nil) new(argv, out:, err:, source_overrides:, build_frontend:).start end |
Instance Method Details
#start ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/milk_tea/tooling/cli.rb', line 60 def start return 1 unless extract_include_paths! command = @argv.shift if version_request?(command) @out.puts("mtc #{MilkTea::VERSION}") return 0 end if help_request?(command) topic = command == "help" ? @argv.shift : nil if topic print_command_help(topic, @out) else print_help(@out) end return 0 end if command && @include_module_roots.any? && !command_supports_include_paths?(command) @err.puts("unknown option #{@include_path_flags.first} for #{command}") print_usage(@err) return 1 end if @argv.first == "--help" || @argv.first == "-h" @argv.shift print_command_help(command, @out) return 0 end case command when "lex" lex_command when "parse" parse_command when "format" format_command when "lint" lint_command when "check" check_command when "lower" lower_command when "emit-c" emit_c_command when "build" build_command when "test" test_command when "run" run_command when "run-module" app_command when "new" new_command when "debug" debug_command when "toolchain" toolchain_command when "deps" deps_command when "bindgen" bindgen_command when "cache" cache_command when "docs" docs_command when "snapshot" snapshot_command when "lsp" lsp_command when "dap" dap_command when "completions" completions_command else print_usage(@err) 1 end rescue StandardError => e raise unless handled_cli_error?(e) @err.puts(ErrorFormatter.format(e, color: error_color?(@err))) 1 end |