Class: Steep::CLI

Inherits:
Object show all
Defined in:
lib/steep/cli.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout:, stdin:, stderr:, argv:) ⇒ CLI

Returns a new instance of CLI.



11
12
13
14
15
16
# File 'lib/steep/cli.rb', line 11

def initialize(stdout:, stdin:, stderr:, argv:)
  @stdout = stdout
  @stdin = stdin
  @stderr = stderr
  @argv = argv
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



5
6
7
# File 'lib/steep/cli.rb', line 5

def argv
  @argv
end

#commandObject (readonly)

Returns the value of attribute command.



9
10
11
# File 'lib/steep/cli.rb', line 9

def command
  @command
end

#stderrObject (readonly)

Returns the value of attribute stderr.



8
9
10
# File 'lib/steep/cli.rb', line 8

def stderr
  @stderr
end

#stdinObject (readonly)

Returns the value of attribute stdin.



7
8
9
# File 'lib/steep/cli.rb', line 7

def stdin
  @stdin
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



6
7
8
# File 'lib/steep/cli.rb', line 6

def stdout
  @stdout
end

Class Method Details

.available_commandsObject



18
19
20
# File 'lib/steep/cli.rb', line 18

def self.available_commands
  [:init, :check, :validate, :annotations, :version, :project, :watch, :langserver, :stats, :binstub, :checkfile, :server, :query]
end

Instance Method Details

#handle_jobs_option(option, opts) ⇒ Object



87
88
89
90
91
92
93
94
95
# File 'lib/steep/cli.rb', line 87

def handle_jobs_option(option, opts)
  opts.on("-j N", "--jobs=N", "Specify the number of type check workers (defaults: #{option.default_jobs_count})") do |count|
    option.jobs_count = Integer(count) if Integer(count) > 0
  end

  opts.on("--steep-command=COMMAND", "Specify command to exec Steep CLI for worker (defaults: steep)") do |cmd|
    option.steep_command = cmd
  end
end

#handle_logging_options(opts) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/steep/cli.rb', line 69

def handle_logging_options(opts)
  opts.on("--log-level=LEVEL", "Specify log level: debug, info, warn, error, fatal") do |level|
    # @type var level: String
    Steep.logger.level = level
    Steep.ui_logger.level = level
  end

  opts.on("--log-output=PATH", "Print logs to given path") do |file|
    # @type var file: String
    Steep.log_output = file
  end

  opts.on("--verbose", "Set log level to debug") do
    Steep.logger.level = Logger::DEBUG
    Steep.ui_logger.level = Logger::DEBUG
  end
end

#handle_steepfile_option(opts, command) ⇒ Object



65
66
67
# File 'lib/steep/cli.rb', line 65

def handle_steepfile_option(opts, command)
  opts.on("--steepfile=PATH", "Specify path to Steepfile") {|path| command.steepfile = Pathname(path) }
end

#process_annotationsObject



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/steep/cli.rb', line 280

def process_annotations
  Drivers::Annotations.new(stdout: stdout, stderr: stderr).tap do |command|
    OptionParser.new do |opts|
      opts.banner = <<BANNER
Usage: steep annotations [options] [sources]

Description:
Prints the type annotations in the Ruby code.

Options:
BANNER
      handle_logging_options opts
    end.parse!(argv)

    command.command_line_patterns.push(*argv)
  end.run
end

#process_binstubObject



379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/steep/cli.rb', line 379

def process_binstub
  path = Pathname("bin/steep")
  root_path = Pathname.pwd
  force = false

  OptionParser.new do |opts|
    opts.banner = <<BANNER
Usage: steep binstub [options]

Description:
Generate a binstub which set up ruby executables and bundlers.

Options:
BANNER
    handle_logging_options opts

    opts.on("-o PATH", "--output=PATH", "The path of the executable file (defaults to `bin/steep`)") do |v|
      path = Pathname(v)
    end

    opts.on("--root=PATH", "The repository root path (defaults to `.`)") do |v|
      root_path = (Pathname.pwd + v).cleanpath
    end

    opts.on("--[no-]force", "Overwrite file (defaults to false)") do
      force = true
    end
  end.parse!(argv)

  binstub_path = (Pathname.pwd + path).cleanpath
  bindir_path = binstub_path.parent

  bindir_path.mkpath

  gemfile_path =
    if defined?(Bundler)
      Bundler.default_gemfile.relative_path_from(bindir_path)
    else
      Pathname("../Gemfile")
    end

  if binstub_path.file?
    if force
      stdout.puts Rainbow("#{path} already exists. Overwriting...").yellow
    else
      stdout.puts Rainbow(''"⚠️ #{path} already exists. Bye! 👋").red
      return 0
    end
  end

  template = <<TEMPLATE
#!/usr/bin/env bash

BINSTUB_DIR=$(cd $(dirname $0); pwd)
GEMFILE=$(readlink -f ${BINSTUB_DIR}/#{gemfile_path})
ROOT_DIR=$(readlink -f ${BINSTUB_DIR}/#{root_path.relative_path_from(bindir_path)})

STEEP="bundle exec --gemfile=${GEMFILE} steep"

if type "rbenv" > /dev/null 2>&1; then
  STEEP="rbenv exec ${STEEP}"
else
  if type "rvm" > /dev/null 2>&1; then
if [ -e ${ROOT_DIR}/.ruby-version ]; then
  STEEP="rvm ${ROOT_DIR} do ${STEEP}"
fi
  fi
fi

exec $STEEP $@
TEMPLATE

  binstub_path.write(template)
  binstub_path.chmod(0755)

  stdout.puts Rainbow("Successfully generated executable #{path} 🎉").blue

  0
end

#process_checkObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/steep/cli.rb', line 128

def process_check
  Drivers::Check.new(stdout: stdout, stderr: stderr).tap do |command|
    OptionParser.new do |opts|
      opts.banner = <<BANNER
Usage: steep check [options] [paths]
   steep check [options] -e 'expr' [-e 'expr' ...]

Description:
Type check the program.

If paths are specified, it type checks and validates the files at the given path.
Otherwise, it type checks and validates all files in the project or the groups if specified.

Options:
BANNER

      handle_steepfile_option(opts, command)
      opts.on("-e", "--expression=EXPRESSION", "Type check a Ruby expression (may be specified multiple times)") do |expr|
        command.expressions << expr
      end
      opts.on("--with-expectations[=PATH]", "Type check with expectations saved in PATH (or steep_expectations.yml)") do |path|
        command.with_expectations_path = Pathname(path || "steep_expectations.yml")
      end
      opts.on("--save-expectations[=PATH]", "Save expectations with current type check result to PATH (or steep_expectations.yml)") do |path|
        command.save_expectations_path = Pathname(path || "steep_expectations.yml")
      end
      opts.on("--severity-level=LEVEL", /^error|warning|information|hint$/, "Specify the minimum diagnostic severity to be recognized as an error (defaults: warning): error, warning, information, or hint") do |level|
        command.severity_level = level.to_sym
      end

      opts.on("--group=GROUP", "Specify target/group name to type check") do |arg|
        # @type var arg: String
        target, group = arg.split(".")
        target or raise
        case group
        when "*"
          command.active_group_names << [target.to_sym, true]
        when nil
          command.active_group_names << [target.to_sym, nil]
        else
          command.active_group_names << [target.to_sym, group.to_sym]
        end
      end

      opts.on("--[no-]type-check", "Type check Ruby code") do |v|
        command.type_check_code = v ? true : false
      end

      opts.on("--validate=OPTION", ["skip", "group", "project", "library"], "Validation levels of signatures (default: group, options: skip,group,project,library)") do |level|
        case level
        when "skip"
          command.validate_group_signatures = false
          command.validate_project_signatures = false
          command.validate_library_signatures = false
        when "group"
          command.validate_group_signatures = true
          command.validate_project_signatures = false
          command.validate_library_signatures = false
        when "project"
          command.validate_group_signatures = true
          command.validate_project_signatures = true
          command.validate_library_signatures = false
        when "library"
          command.validate_group_signatures = true
          command.validate_project_signatures = true
          command.validate_library_signatures = true
        end
      end

      opts.on("--format=FORMATTER", ["code", "github"], "Output formatters (default: code, options: code,github)") do |formatter|
        command.formatter = formatter
      end

      opts.on("--[no-]daemon", "Use daemon server if available (default: true)") do |v|
        command.use_daemon = v ? true : false
      end

      handle_jobs_option command.jobs_option, opts
      handle_logging_options opts
    end.parse!(argv)

    setup_jobs_for_ci(command.jobs_option)

    command.command_line_patterns.push(*argv)

    unless command.expressions.empty? || argv.empty?
      abort "Cannot specify both -e and file paths"
    end
  end.run
end

#process_checkfileObject



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/steep/cli.rb', line 219

def process_checkfile
  Drivers::Checkfile.new(stdout: stdout, stderr: stderr).tap do |command|
    OptionParser.new do |opts|
      opts.banner = <<BANNER
Usage: steep checkfile [options] [files]

Description:
Deprecated: Use `steep check` instead.

Options:
BANNER

      handle_steepfile_option(opts, command)
      opts.on("--all-rbs", "Type check all RBS files") { command.all_rbs = true }
      opts.on("--all-ruby", "Type check all Ruby files") { command.all_ruby = true }
      opts.on("--stdin", "Read files to type check from stdin") do
        while line = stdin.gets()
          object = JSON.parse(line, symbolize_names: true)
          Steep.logger.info { "Loading content of `#{object[:path]}` from stdin: #{object[:content].lines[0].chomp}" }
          command.stdin_input[Pathname(object[:path])] = object[:content]
        end
      end
      handle_jobs_option command.jobs_option, opts
      handle_logging_options opts
    end.parse!(argv)

    setup_jobs_for_ci(command.jobs_option)

    command.command_line_args.push(*argv)
  end.run
end

#process_global_optionsObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/steep/cli.rb', line 22

def process_global_options
  OptionParser.new do |opts|
    opts.banner = <<~USAGE
      Usage: steep [options]

      Available commands:
          #{CLI.available_commands.join(', ')}

      Options:
    USAGE

    opts.on("--version", "Print Steep version") do
      process_version
      exit 0
    end

    handle_logging_options(opts)
  end.order!(argv)

  true
end

#process_initObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/steep/cli.rb', line 109

def process_init
  Drivers::Init.new(stdout: stdout, stderr: stderr).tap do |command|
    OptionParser.new do |opts|
      opts.banner = <<BANNER
Usage: steep init [options]

Description:
Generates a Steepfile at specified path.

Options:
BANNER
      handle_steepfile_option(opts, command)
      opts.on("--force", "Overwrite the Steepfile if it already exists") { command.force_write = true }

      handle_logging_options opts
    end.parse!(argv)
  end.run()
end

#process_langserverObject



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/steep/cli.rb', line 345

def process_langserver
  Drivers::Langserver.new(stdout: stdout, stderr: stderr, stdin: stdin).tap do |command|
    OptionParser.new do |opts|
      opts.banner = <<BANNER
Usage: steep langserver [options]

Description:
Starts language server, which is assumed to be invoked from language client.

Options:
BANNER
      handle_steepfile_option(opts, command)
      opts.on("--refork") { command.refork = true }
      handle_jobs_option command.jobs_option, opts
      handle_logging_options opts
    end.parse!(argv)
  end.run
end

#process_projectObject



298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/steep/cli.rb', line 298

def process_project
  Drivers::PrintProject.new(stdout: stdout, stderr: stderr).tap do |command|
    OptionParser.new do |opts|
      opts.banner = <<BANNER
Usage: steep project [options]

Description:
Prints the project configuration.

Options:
BANNER
      handle_steepfile_option(opts, command)
      opts.on("--[no-]print-files", "Print files") {|v|
        command.print_files = v ? true : false
      }
      handle_logging_options opts
    end.parse!(argv)
  end.run
end

#process_queryObject



605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
# File 'lib/steep/cli.rb', line 605

def process_query
  subcommand = argv.shift

  if subcommand.nil? || subcommand == "--help" || subcommand == "-h"
    stderr.puts <<~HELP
      Usage: steep query <subcommand> [options]

      Description:
          Query type information from the Steep daemon server.
          The daemon must be running (start it with `steep server start`).

      Note:
          `steep query` is an experimental command.
          The user interface and output format may change without deprecation.

      Available subcommands:
          hover      Get hover information (type, documentation) for a position
          definition Get the definition(s) of a class, type alias, constant, or method name

      Options:
          --help    Show this help message

      Examples:
          steep query hover lib/foo.rb:10:5
          steep query definition RBS::Location
          steep query definition RBS::Parser.parse_signature
    HELP
    return 0
  end

  case subcommand
  when "hover"
    OptionParser.new do |opts|
      opts.banner = <<BANNER
Usage: steep query hover [options] FILE:LINE:COL [FILE:LINE:COL ...]

Description:
Get hover information for the specified position(s).
Connects to the running Steep daemon and returns type information as JSONL
(one JSON object per line for each queried position).

FILE:LINE:COL - File path with 1-based line and column numbers.

Note:
This is an experimental command.
The user interface and output format may change without deprecation.

Options:
BANNER
      handle_logging_options opts
    end.parse!(argv)

    if argv.empty?
      stderr.puts "Error: Missing FILE:LINE:COL argument"
      stderr.puts "  Usage: steep query hover FILE:LINE:COL [FILE:LINE:COL ...]"
      return 1
    end

    locations = [] #: Array[[String, Integer, Integer]]

    argv.each do |location|
      match = location.match(/\A(.+):(\d+):(\d+)\z/)
      unless match
        stderr.puts "Error: Invalid format: #{location}"
        stderr.puts "  Expected format: FILE:LINE:COL (e.g., lib/foo.rb:10:5)"
        return 1
      end

      path = match[1] or raise
      line = match[2].to_i
      column = match[3].to_i

      if line < 1 || column < 1
        stderr.puts "Error: LINE and COL must be positive integers (1-based)"
        return 1
      end

      locations << [path, line, column]
    end

    Drivers::Query.new(stdout: stdout, stderr: stderr).run_hover(locations: locations)
  when "definition"
    OptionParser.new do |opts|
      opts.banner = <<BANNER
Usage: steep query definition [options] NAME [NAME ...]

Description:
Get the definition(s) of the specified name(s).
Connects to the running Steep daemon and returns both RBS declarations and
Ruby definitions as JSONL (one JSON object per line for each queried name).

NAME can be one of:
  * A class, module, interface, type alias, or constant (e.g., RBS::Location)
  * An instance method (e.g., RBS::Parser#parse_type)
  * A singleton method (e.g., RBS::Parser.parse_signature)

Note:
This is an experimental command.
The user interface and output format may change without deprecation.

Options:
BANNER
      handle_logging_options opts
    end.parse!(argv)

    if argv.empty?
      stderr.puts "Error: Missing NAME argument"
      stderr.puts "  Usage: steep query definition NAME [NAME ...]"
      return 1
    end

    Drivers::Query.new(stdout: stdout, stderr: stderr).run_definition(names: argv.dup)
  else
    stderr.puts "Unknown query subcommand: #{subcommand}"
    stderr.puts "  available subcommands: hover, definition"
    1
  end
end

#process_serverObject



495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
# File 'lib/steep/cli.rb', line 495

def process_server
  subcommand = argv.shift

  if subcommand.nil? || subcommand == "--help" || subcommand == "-h"
    stderr.puts <<~HELP
      Usage: steep server <subcommand> [options]

      Description:
          Manage the Steep daemon server for faster type checking.
          The daemon keeps RBS environment loaded in memory.

      Available subcommands:
          start     Start the daemon server
          stop      Stop the daemon server
          restart   Restart the daemon server
          status    Show daemon server status

      Options:
          --help    Show this help message

      Examples:
          steep server start
          steep server stop
          steep server restart
          steep server status
    HELP
    return 0
  end

  case subcommand
  when "start"
    unless Steep.can_fork?
      stderr.puts "Error: `steep server start` is not supported on this platform (fork() is not available)"
      return 1
    end
    Drivers::StartServer.new(stdout: stdout, stderr: stderr).tap do |command|
      OptionParser.new do |opts|
        opts.banner = <<BANNER
Usage: steep server start [options]

Description:
Starts a persistent daemon server for faster type checking.
The daemon keeps RBS environment loaded in memory.

Options:
BANNER
        handle_logging_options opts
      end.parse!(argv)
    end.run
  when "stop"
    Drivers::StopServer.new(stdout: stdout, stderr: stderr).tap do |command|
      OptionParser.new do |opts|
        opts.banner = <<BANNER
Usage: steep server stop [options]

Description:
Stops the running daemon server.

Options:
BANNER
        handle_logging_options opts
      end.parse!(argv)
    end.run
  when "restart"
    unless Steep.can_fork?
      stderr.puts "Error: `steep server restart` is not supported on this platform (fork() is not available)"
      return 1
    end
    OptionParser.new do |opts|
      opts.banner = <<BANNER
Usage: steep server restart [options]

Description:
Restarts the daemon server (stops and then starts it).

Options:
BANNER
      handle_logging_options opts
    end.parse!(argv)

    stop_command = Drivers::StopServer.new(stdout: stdout, stderr: stderr)
    stop_command.run

    # Brief pause to ensure clean shutdown
    sleep 0.5

    start_command = Drivers::StartServer.new(stdout: stdout, stderr: stderr)
    start_command.run
  when "status"
    OptionParser.new do |opts|
      opts.banner = <<BANNER
Usage: steep server status [options]

Description:
Shows the status of the daemon server.

Options:
BANNER
      handle_logging_options opts
    end.parse!(argv)

    Daemon.status(stderr: stderr)
    0
  else
    stderr.puts "Unknown server subcommand: #{subcommand}"
    stderr.puts "  available subcommands: start, stop, restart, status"
    1
  end
end

#process_statsObject



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/steep/cli.rb', line 251

def process_stats
  Drivers::Stats.new(stdout: stdout, stderr: stderr).tap do |command|
    OptionParser.new do |opts|
      opts.banner = <<BANNER
Usage: steep stats [options] [sources]

Description:
Displays statistics about the typing of method calls.

Options:
BANNER

      handle_steepfile_option(opts, command)
      opts.on("--format=FORMAT", "Specify output format: csv, table") {|format| command.format = format }
      handle_jobs_option command.jobs_option, opts
      handle_logging_options opts
    end.parse!(argv)

    setup_jobs_for_ci(command.jobs_option)

    command.command_line_patterns.push(*argv)
  end.run
end

#process_validateObject



275
276
277
278
# File 'lib/steep/cli.rb', line 275

def process_validate
  stderr.puts "`steep validate` is deprecated. Use `steep check` with `--validate` option instead."
  1
end

#process_vendorObject



364
365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/steep/cli.rb', line 364

def process_vendor
  Drivers::Vendor.new(stdout: stdout, stderr: stderr, stdin: stdin).tap do |command|
    OptionParser.new do |opts|
      opts.banner = "Usage: steep vendor [options] [dir]"
      handle_logging_options opts

      opts.on("--[no-]clean") do |v|
        command.clean_before = v
      end
    end.parse!(argv)

    command.vendor_dir = Pathname(argv[0] || "vendor/sigs")
  end.run
end

#process_versionObject



459
460
461
462
463
464
465
466
467
468
469
470
471
# File 'lib/steep/cli.rb', line 459

def process_version
  OptionParser.new do |opts|
    opts.banner = <<BANNER
Usage: steep version [options]

Description:
Prints Steep version.
BANNER
  end.parse!(argv)

  stdout.puts Steep::VERSION
  0
end

#process_watchObject



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/steep/cli.rb', line 318

def process_watch
  Drivers::Watch.new(stdout: stdout, stderr: stderr).tap do |command|
    OptionParser.new do |opts|
      opts.banner = <<BANNER
Usage: steep watch [options] [dirs]

Description:
Monitors file changes and automatically type checks updated files.
Using LSP is recommended for better performance and more features.

Options:
BANNER
      opts.on("--severity-level=LEVEL", /^error|warning|information|hint$/, "Specify the minimum diagnostic severity to be recognized as an error (defaults: warning): error, warning, information, or hint") do |level|
        # @type var level: String
        command.severity_level = _ = level.to_sym
      end
      handle_jobs_option command.jobs_option, opts
      handle_logging_options opts
    end.parse!(argv)

    setup_jobs_for_ci(command.jobs_option)

    dirs = argv.map {|dir| Pathname(dir) }
    command.dirs.push(*dirs)
  end.run
end

#process_workerObject



473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/steep/cli.rb', line 473

def process_worker
  Drivers::Worker.new(stdout: stdout, stderr: stderr, stdin: stdin).tap do |command|
    OptionParser.new do |opts|
      opts.banner = "Usage: steep worker [options] [dir]"
      handle_logging_options opts

      opts.on("--interaction") { command.worker_type = :interaction }
      opts.on("--typecheck") { command.worker_type = :typecheck }
      handle_steepfile_option(opts, command)
      opts.on("--name=NAME") {|name| command.worker_name = name }
      opts.on("--delay-shutdown") { command.delay_shutdown = true }
      opts.on("--max-index=COUNT") {|count| command.max_index = Integer(count) }
      opts.on("--index=INDEX") {|index| command.index = Integer(index) }
    end.parse!(argv)

    # Disable any `ui_logger` output in workers
    Steep.ui_logger.level = :fatal

    command.commandline_args.push(*argv)
  end.run
end

#runObject



57
58
59
60
61
62
63
# File 'lib/steep/cli.rb', line 57

def run
  process_global_options or return 1
  setup_command or return 1

  method_name = command.to_s.gsub('-', '_')
  __send__(:"process_#{method_name}")
end

#setup_commandObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/steep/cli.rb', line 44

def setup_command
  return false unless command = argv.shift&.to_sym
  @command = command

  if CLI.available_commands.include?(@command) || @command == :worker || @command == :vendor
    true
  else
    stderr.puts "Unknown command: #{command}"
    stderr.puts "  available commands: #{CLI.available_commands.join(', ')}"
    false
  end
end

#setup_jobs_for_ci(jobs_option) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/steep/cli.rb', line 97

def setup_jobs_for_ci(jobs_option)
  if ENV["CI"]
    unless jobs_option.jobs_count
      stderr.puts Rainbow("CI environment is detected but no `--jobs` option is given.").yellow
      stderr.puts "  Using `[2, #{jobs_option.default_jobs_count} (# or processors)].min` to avoid hitting memory limit."
      stderr.puts "  Specify `--jobs` option to increase the number of jobs."

      jobs_option.jobs_count = [2, jobs_option.default_jobs_count].min
    end
  end
end