Module: GDK::Command

Defined in:
lib/gdk/command.rb,
lib/gdk/command/bao.rb,
lib/gdk/command/env.rb,
lib/gdk/command/run.rb,
lib/gdk/command/help.rb,
lib/gdk/command/kill.rb,
lib/gdk/command/open.rb,
lib/gdk/command/psql.rb,
lib/gdk/command/stop.rb,
lib/gdk/command/tail.rb,
lib/gdk/command/thin.rb,
lib/gdk/command/cells.rb,
lib/gdk/command/rails.rb,
lib/gdk/command/start.rb,
lib/gdk/command/trust.rb,
lib/gdk/command/config.rb,
lib/gdk/command/doctor.rb,
lib/gdk/command/status.rb,
lib/gdk/command/update.rb,
lib/gdk/command/cleanup.rb,
lib/gdk/command/install.rb,
lib/gdk/command/restart.rb,
lib/gdk/command/version.rb,
lib/gdk/command/evaluate.rb,
lib/gdk/command/pristine.rb,
lib/gdk/command/psql_geo.rb,
lib/gdk/command/redis_cli.rb,
lib/gdk/command/telemetry.rb,
lib/gdk/command/clickhouse.rb,
lib/gdk/command/debug_info.rb,
lib/gdk/command/reset_data.rb,
lib/gdk/command/diff_config.rb,
lib/gdk/command/measure_url.rb,
lib/gdk/command/reconfigure.rb,
lib/gdk/command/base_command.rb,
lib/gdk/command/measure_base.rb,
lib/gdk/command/measure_workflow.rb,
lib/gdk/command/reset_praefect_data.rb,
lib/gdk/command/truncate_legacy_tables.rb

Overview

GDK Commands

Defined Under Namespace

Classes: Bao, BaseCommand, Cells, Cleanup, Clickhouse, Config, DebugInfo, DiffConfig, Doctor, Env, Evaluate, Help, Install, Kill, MeasureBase, MeasureUrl, MeasureWorkflow, Open, Pristine, Psql, PsqlGeo, Rails, Reconfigure, RedisCli, ResetData, ResetPraefectData, Restart, Run, Start, Status, Stop, Tail, Telemetry, Thin, TruncateLegacyTables, Trust, Update, Version

Constant Summary collapse

COMMANDS =

This is a list of existing supported commands and their associated implementation class

{
  'cells' => -> { GDK::Command::Cells },
  'cleanup' => -> { GDK::Command::Cleanup },
  'clickhouse' => -> { GDK::Command::Clickhouse },
  'config' => -> { GDK::Command::Config },
  'bao' => -> { GDK::Command::Bao },
  'debug-info' => -> { GDK::Command::DebugInfo },
  'diff-config' => -> { GDK::Command::DiffConfig },
  'doctor' => -> { GDK::Command::Doctor },
  'env' => -> { GDK::Command::Env },
  'evaluate' => -> { GDK::Command::Evaluate },
  'install' => -> { GDK::Command::Install },
  'kill' => -> { GDK::Command::Kill },
  'help' => -> { GDK::Command::Help },
  '-help' => -> { GDK::Command::Help },
  '--help' => -> { GDK::Command::Help },
  '-h' => -> { GDK::Command::Help },
  nil => -> { GDK::Command::Help },
  'measure' => -> { GDK::Command::MeasureUrl },
  'measure-workflow' => -> { GDK::Command::MeasureWorkflow },
  'open' => -> { GDK::Command::Open },
  'telemetry' => -> { GDK::Command::Telemetry },
  'psql' => -> { GDK::Command::Psql },
  'psql-geo' => -> { GDK::Command::PsqlGeo },
  'pristine' => -> { GDK::Command::Pristine },
  'rails' => -> { GDK::Command::Rails },
  'reconfigure' => -> { GDK::Command::Reconfigure },
  'redis-cli' => -> { GDK::Command::RedisCli },
  'reset-data' => -> { GDK::Command::ResetData },
  'reset-praefect-data' => -> { GDK::Command::ResetPraefectData },
  'restart' => -> { GDK::Command::Restart },
  'run' => -> { GDK::Command::Run },
  'start' => -> { GDK::Command::Start },
  'status' => -> { GDK::Command::Status },
  'stop' => -> { GDK::Command::Stop },
  'tail' => -> { GDK::Command::Tail },
  'thin' => -> { GDK::Command::Thin },
  'trust' => -> { GDK::Command::Trust },
  'truncate-legacy-tables' => -> { GDK::Command::TruncateLegacyTables },
  'update' => -> { GDK::Command::Update },
  'version' => -> { GDK::Command::Version },
  '-version' => -> { GDK::Command::Version },
  '--version' => -> { GDK::Command::Version }
}.freeze

Class Method Summary collapse

Class Method Details

.check_gem_version!Object



97
98
99
100
101
102
103
104
# File 'lib/gdk/command.rb', line 97

def self.check_gem_version!
  return if Gem::Version.new(GDK::GEM_VERSION) >= Gem::Version.new(GDK::REQUIRED_GEM_VERSION)

  GDK::Output.warn("You are running an old version of the `gitlab-development-kit` gem (#{GDK::GEM_VERSION})")
  GDK::Output.info("Please update your `gitlab-development-kit` to version #{GDK::REQUIRED_GEM_VERSION}:")
  GDK::Output.info("gem install gitlab-development-kit -v #{GDK::REQUIRED_GEM_VERSION}")
  GDK::Output.puts
end

.run(argv) ⇒ Object

Entry point for gem/bin/gdk.

It must return true/false or an exit code.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/gdk/command.rb', line 56

def self.run(argv)
  name = argv.shift
  command = ::GDK::Command::COMMANDS[name]

  if command
    klass = command.call

    check_gem_version!
    validate_yaml! if klass.validate_config?
    result = GDK::Telemetry.with_telemetry(name) { klass.new.run(argv) }

    exit result
  else
    suggestions = DidYouMean::SpellChecker.new(dictionary: ::GDK::Command::COMMANDS.keys).correct(name)
    message = ["#{name} is not a GDK command"]

    if suggestions.any?
      message << ', did you mean - '
      message << suggestions.map { |suggestion| "'gdk #{suggestion}'" }.join(' or ')
      message << '?'
    else
      message << '.'
    end

    GDK::Output.warn message.join
    GDK::Output.puts

    GDK::Output.info "See 'gdk help' for more detail."
    false
  end
end

.validate_yaml!Object



88
89
90
91
92
93
94
95
# File 'lib/gdk/command.rb', line 88

def self.validate_yaml!
  GDK.config.validate!
  nil
rescue StandardError => e
  GDK::Output.error("Your gdk.yml is invalid.\n\n", e)
  GDK::Output.puts(e.message, stderr: true)
  abort('')
end