Class: Pocketbook::CLI::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/pocketbook/cli/runner.rb

Defined Under Namespace

Classes: GitHubThemeSource

Instance Method Summary collapse

Constructor Details

#initialize(stdout: $stdout, stderr: $stderr, options_parser: nil, watcher_class: Watcher) ⇒ Runner

Returns a new instance of Runner.



39
40
41
42
43
44
# File 'lib/pocketbook/cli/runner.rb', line 39

def initialize(stdout: $stdout, stderr: $stderr, options_parser: nil, watcher_class: Watcher)
  @stdout = stdout
  @stderr = stderr
  @options_parser = options_parser || OptionsParser.new(stdout: @stdout)
  @watcher_class = watcher_class
end

Instance Method Details

#run(argv = ARGV) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/pocketbook/cli/runner.rb', line 46

def run(argv = ARGV)
  command, request, parse_status = @options_parser.parse(argv)
  return if parse_status == :exit

  case command
  when :build
    run_build_command(request)
  when :watch
    build_watcher(request).run
  when :theme_new
    scaffold_theme(request)
  when :theme_validate
    validate_theme(request)
  when :theme_inspect
    inspect_theme(request)
  when :theme_get
    get_theme(request)
  else
    raise OptionParser::InvalidArgument, "Unknown command '#{command}'"
  end
rescue OptionParser::ParseError, ArgumentError => e
  @stderr.puts("Error: #{e.message}")
  @stderr.puts("Run with --help for usage.")
  exit(1)
end