Class: SchemaFerry::CLI
- Inherits:
-
Object
- Object
- SchemaFerry::CLI
- Defined in:
- lib/schema_ferry/cli.rb
Overview
Minimal command-line interface: schema_ferry <apply|dry-run> [-c FILE].
#run returns a process exit code instead of calling Kernel#exit so the
class stays testable.
Constant Summary collapse
- DEFAULT_CONFIG_PATH =
"Ferryfile"- COMMANDS =
%w[apply dry-run].freeze
Instance Method Summary collapse
-
#initialize(stdout: $stdout, stderr: $stderr) ⇒ CLI
constructor
A new instance of CLI.
- #run(argv) ⇒ Object
Constructor Details
#initialize(stdout: $stdout, stderr: $stderr) ⇒ CLI
Returns a new instance of CLI.
13 14 15 16 |
# File 'lib/schema_ferry/cli.rb', line 13 def initialize(stdout: $stdout, stderr: $stderr) @stdout = stdout @stderr = stderr end |
Instance Method Details
#run(argv) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/schema_ferry/cli.rb', line 18 def run(argv) args = parser.parse(argv) return print_and_succeed(parser.to_s) if @mode == :help return print_and_succeed(VERSION) if @mode == :version command = args.first return usage_error("missing command") if command.nil? return usage_error("unknown command: #{command}") unless COMMANDS.include?(command) run_command(command) rescue Error, OptionParser::ParseError => e @stderr.puts "schema_ferry: #{e.}" 1 end |