Class: Steep::CLI
- Inherits:
-
Object
- Object
- Steep::CLI
- Defined in:
- lib/steep/cli.rb
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Class Method Summary collapse
Instance Method Summary collapse
- #handle_logging_options(opts) ⇒ Object
-
#initialize(stdout:, stdin:, stderr:, argv:) ⇒ CLI
constructor
A new instance of CLI.
- #process_annotations ⇒ Object
- #process_check ⇒ Object
- #process_global_options ⇒ Object
- #process_init ⇒ Object
- #process_langserver ⇒ Object
- #process_project ⇒ Object
- #process_validate ⇒ Object
- #process_vendor ⇒ Object
- #process_version ⇒ Object
- #process_watch ⇒ Object
- #run ⇒ Object
- #setup_command ⇒ Object
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
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
5 6 7 |
# File 'lib/steep/cli.rb', line 5 def argv @argv end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
9 10 11 |
# File 'lib/steep/cli.rb', line 9 def command @command end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
8 9 10 |
# File 'lib/steep/cli.rb', line 8 def stderr @stderr end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
7 8 9 |
# File 'lib/steep/cli.rb', line 7 def stdin @stdin end |
#stdout ⇒ Object (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_commands ⇒ Object
18 19 20 |
# File 'lib/steep/cli.rb', line 18 def self.available_commands [:init, :check, :validate, :annotations, :version, :project, :watch, :langserver, :vendor] end |
Instance Method Details
#handle_logging_options(opts) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/steep/cli.rb', line 53 def (opts) opts.on("--log-level=[debug,info,warn,error,fatal]") do |level| Steep.logger.level = level end opts.on("--log-output=[PATH]") do |file| Steep.log_output = file end opts.on("--verbose") do Steep.logger.level = Logger::DEBUG end end |
#process_annotations ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/steep/cli.rb', line 102 def process_annotations Drivers::Annotations.new(stdout: stdout, stderr: stderr).tap do |command| OptionParser.new do |opts| opts. = "Usage: steep annotations [options] [sources]" opts end.parse!(argv) command.command_line_patterns.push *argv end.run end |
#process_check ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/steep/cli.rb', line 80 def process_check Drivers::Check.new(stdout: stdout, stderr: stderr).tap do |check| OptionParser.new do |opts| opts. = "Usage: steep check [options] [sources]" opts.on("--steepfile=PATH") {|path| check.steepfile = Pathname(path) } opts.on("--dump-all-types") { check.dump_all_types = true } opts end.parse!(argv) check.command_line_patterns.push *argv end.run end |
#process_global_options ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/steep/cli.rb', line 22 def OptionParser.new do |opts| opts.on("--version") do process_version exit 0 end (opts) end.order!(argv) true end |
#process_init ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/steep/cli.rb', line 67 def process_init Drivers::Init.new(stdout: stdout, stderr: stderr).tap do |command| OptionParser.new do |opts| opts. = "Usage: steep init [options]" opts.on("--steepfile=PATH") {|path| command.steepfile = Pathname(path) } opts.on("--force") { command.force_write = true } opts end.parse!(argv) end.run() end |
#process_langserver ⇒ Object
134 135 136 137 138 139 140 141 |
# File 'lib/steep/cli.rb', line 134 def process_langserver Drivers::Langserver.new(stdout: stdout, stderr: stderr, stdin: stdin).tap do |command| OptionParser.new do |opts| opts.on("--steepfile=PATH") {|path| command.steepfile = Pathname(path) } opts end.parse!(argv) end.run end |
#process_project ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/steep/cli.rb', line 113 def process_project Drivers::PrintProject.new(stdout: stdout, stderr: stderr).tap do |command| OptionParser.new do |opts| opts. = "Usage: steep project [options]" opts.on("--steepfile=PATH") {|path| command.steepfile = Pathname(path) } opts end.parse!(argv) end.run end |
#process_validate ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/steep/cli.rb', line 94 def process_validate Drivers::Validate.new(stdout: stdout, stderr: stderr).tap do |command| OptionParser.new do |opts| opts end.parse!(argv) end.run end |
#process_vendor ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/steep/cli.rb', line 143 def process_vendor Drivers::Vendor.new(stdout: stdout, stderr: stderr, stdin: stdin).tap do |command| OptionParser.new do |opts| opts. = "Usage: steep vendor [options] [dir]" 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_version ⇒ Object
158 159 160 161 |
# File 'lib/steep/cli.rb', line 158 def process_version stdout.puts Steep::VERSION 0 end |
#process_watch ⇒ Object
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/steep/cli.rb', line 123 def process_watch Drivers::Watch.new(stdout: stdout, stderr: stderr).tap do |command| OptionParser.new do |opts| opts. = "Usage: steep watch [options] [dirs]" opts end.parse!(argv) command.dirs.push *argv end.run end |
#run ⇒ Object
46 47 48 49 50 51 |
# File 'lib/steep/cli.rb', line 46 def run or return 1 setup_command or return 1 __send__(:"process_#{command}") end |
#setup_command ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/steep/cli.rb', line 35 def setup_command @command = argv.shift&.to_sym if CLI.available_commands.include?(@command) true else stderr.puts "Unknown command: #{command}" stderr.puts " available commands: #{CLI.available_commands.join(', ')}" false end end |