Class: Charming::CLI
- Inherits:
-
Object
- Object
- Charming::CLI
- Defined in:
- lib/charming/cli.rb
Overview
CLI dispatches the ‘charming` executable’s subcommands to the appropriate generators or database commands. Subcommands:
-
‘charming new NAME [–database sqlite3] [–force]` — scaffolds a new app
-
‘charming generate TYPE NAME [args]` — runs a sub-generator (controller, model, screen, view, component)
-
‘charming db:COMMAND` — runs a database command (db:create, db:migrate, db:rollback, db:drop, db:seed, db:install)
Generator errors are caught and printed to stderr; the process exits with status 1.
Instance Method Summary collapse
-
#call(argv) ⇒ Object
Runs the CLI with the given argv array.
-
#initialize(out: $stdout, err: $stderr, pwd: Dir.pwd) ⇒ CLI
constructor
out defaults to ‘$stdout`, err to `$stderr`, pwd to `Dir.pwd` (overridable for tests).
Constructor Details
#initialize(out: $stdout, err: $stderr, pwd: Dir.pwd) ⇒ CLI
out defaults to ‘$stdout`, err to `$stderr`, pwd to `Dir.pwd` (overridable for tests).
13 14 15 16 17 |
# File 'lib/charming/cli.rb', line 13 def initialize(out: $stdout, err: $stderr, pwd: Dir.pwd) @out = out @err = err @pwd = pwd end |
Instance Method Details
#call(argv) ⇒ Object
Runs the CLI with the given argv array. Returns 0 on success, 1 on a generator error, or the status from ‘usage` for unknown subcommands.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/charming/cli.rb', line 21 def call(argv) command, *args = argv case command when "new" then new_app(args) when "generate", "g" then generate(args) when /^db:/ then database(command, args) else usage(1) end rescue Generators::Error => e err.puts e. 1 end |