Class: LittleGhost::CLI

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

Overview

Command-line entrypoint for generating standalone LittleGhost applications.

Constant Summary collapse

USAGE =

:nodoc:

<<~TEXT
  Usage:
    little_ghost new APP_NAME
    little_ghost console
    little_ghost --version
    little_ghost --help
TEXT

Instance Method Summary collapse

Constructor Details

#initialize(arguments, stdout: $stdout, stderr: $stderr, current_directory: Dir.pwd, generator_class: Generators::ApplicationGenerator, bundle_installer: nil, console_runner: nil, source_path: nil) ⇒ CLI

Returns a new instance of CLI.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/little_ghost/cli.rb', line 50

def initialize(
  arguments,
  stdout: $stdout,
  stderr: $stderr,
  current_directory: Dir.pwd,
  generator_class: Generators::ApplicationGenerator,
  bundle_installer: nil,
  console_runner: nil,
  source_path: nil
)
  @arguments = Array(arguments).dup
  @stdout = stdout
  @stderr = stderr
  @current_directory = File.expand_path(current_directory)
  @generator_class = generator_class
  @bundle_installer = bundle_installer || BundleInstaller.new(stdout:, stderr:)
  @console_runner = console_runner
  @source_path = source_path
end

Instance Method Details

#runObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/little_ghost/cli.rb', line 70

def run
  case arguments.first
  when "--help", "-h", nil
    return usage_error("--help does not accept arguments") if arguments.length > 1

    stdout.write(USAGE)
    0
  when "--version", "-v"
    return usage_error("--version does not accept arguments") if arguments.length > 1

    stdout.puts("little_ghost #{VERSION}")
    0
  when "new"
    generate_application
  when "console"
    open_console
  else
    usage_error("Unknown command: #{arguments.first}")
  end
end