Class: RubyCms::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/ruby_cms/cli.rb,
lib/generators/ruby_cms/templates/lib/ruby_cms/cli.rb

Overview

Standalone ruby_cms CLI: install (interactive), sync (app->gem), update (gem->app).

Defined Under Namespace

Classes: ShellRunner

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


19
# File 'lib/ruby_cms/cli.rb', line 19

def self.exit_on_failure? = true

.parse_modules(str) ⇒ Object



13
14
15
16
17
# File 'lib/ruby_cms/cli.rb', line 13

def self.parse_modules(str)
  return [] if str.nil? || str.strip.empty?

  str.split(",").map {|s| s.strip.to_sym }
end

Instance Method Details

#installObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ruby_cms/cli.rb', line 24

def install
  app_root = detect_app_root!
  installer = Installer.new(
    manifest: RubyCms.manifest, templates_root: templates_root,
    app_root: app_root, shell: ShellRunner.new(self, app_root), version: RubyCms::VERSION
  )

  modules =
    if options[:add]
      installer.add(new_keys: self.class.parse_modules(options[:add]))
    else
      selected = options[:modules] ? self.class.parse_modules(options[:modules]) : pick_modules
      installer.install(selected:)
    end

  say "\n#{set_color('✓ RubyCMS installed', :red, :bold)}#{modules.size} modules"
  say "  #{set_color(modules.map(&:key).join(', '), :cyan)}"

  if yes?("\nCreate your admin user now? (runs ruby_cms:setup_admin) [y/N]")
    # Interactive (prompts for email/password) — run with an inherited TTY, not the
    # capturing ShellRunner.
    system("bin/rails ruby_cms:setup_admin", chdir: app_root)
    say "\nNext: #{set_color('bin/rails server', :yellow)}#{set_color('/admin', :yellow)}"
  else
    say "\nNext: #{set_color('bin/rails ruby_cms:setup_admin', :yellow)}" \
        "#{set_color('bin/rails server', :yellow)}#{set_color('/admin', :yellow)}"
  end
rescue Installer::Error => e
  raise Thor::Error, "✗ Install aborted: #{e.message}"
end

#setup_adminObject



11
12
13
# File 'lib/generators/ruby_cms/templates/lib/ruby_cms/cli.rb', line 11

def setup_admin
  RunSetupAdmin.call(shell:)
end

#syncObject



60
61
62
63
64
65
66
67
68
69
# File 'lib/ruby_cms/cli.rb', line 60

def sync
  result = Syncer.new(
    manifest: RubyCms.manifest, source_root: File.expand_path(options[:from]),
    templates_root: templates_root
  ).sync(dry_run: options[:dry_run], include_new: options[:include_new])
  say "#{'[dry-run] ' if options[:dry_run]}#{result.changed.size} changed, #{result.unchanged.size} unchanged.", :green
  result.changed.each {|f| say "  ~ #{f}", :cyan }
  report_skipped_new(result.skipped_new)
  report_excluded(result.excluded)
end

#updateObject



74
75
76
77
78
79
80
81
# File 'lib/ruby_cms/cli.rb', line 74

def update
  result = Updater.new(
    manifest: RubyCms.manifest, templates_root: templates_root, app_root: detect_app_root!
  ).update(dry_run: options[:dry_run], only: options[:only] && self.class.parse_modules(options[:only]))
  say "#{'[dry-run] ' if options[:dry_run]}#{result.changed.size} file(s) updated.", :green
  result.changed.each {|f| say "  ~ #{f}", :cyan }
  report_excluded(result.excluded)
end