Class: Wavify::CLI
- Inherits:
-
Object
- Object
- Wavify::CLI
- Defined in:
- lib/wavify/cli.rb
Overview
Minimal command-line interface for common Wavify workflows.
Constant Summary collapse
- COMMANDS =
%w[info convert tone normalize trim chain render timeline formats doctor].freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv, stdout:, stderr:) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize(argv, stdout:, stderr:) ⇒ CLI
Returns a new instance of CLI.
14 15 16 17 18 |
# File 'lib/wavify/cli.rb', line 14 def initialize(argv, stdout:, stderr:) @argv = argv.dup @stdout = stdout @stderr = stderr end |
Class Method Details
.run(argv = ARGV, stdout: $stdout, stderr: $stderr) ⇒ Object
10 11 12 |
# File 'lib/wavify/cli.rb', line 10 def self.run(argv = ARGV, stdout: $stdout, stderr: $stderr) new(argv, stdout: stdout, stderr: stderr).run end |
Instance Method Details
#run ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/wavify/cli.rb', line 20 def run command = @argv.shift return usage if command.nil? || %w[-h --help help].include?(command) return version if command == "--version" unless COMMANDS.include?(command) @stderr.puts "wavify: unknown command #{command.inspect}" return usage(status: 1, output: @stderr) end = (@argv) return usage if .delete(:help) return version if .delete(:version) @options = send("run_#{command}") raise InvalidParameterError, "unexpected arguments: #{@argv.join(' ')}" unless @argv.empty? 0 rescue Wavify::Error, ArgumentError, SyntaxError => e @stderr.puts "wavify: #{e.}" 1 rescue StandardError => e @stderr.puts "wavify: unexpected error (#{e.class}): #{e.}" 1 end |