Class: GDK::Command::BaseCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/gdk/command/base_command.rb

Overview

Base interface for GDK commands

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout: GDK::Output, stderr: GDK::Output) ⇒ BaseCommand

Returns a new instance of BaseCommand.



14
15
16
17
# File 'lib/gdk/command/base_command.rb', line 14

def initialize(stdout: GDK::Output, stderr: GDK::Output)
  @stdout = stdout
  @stderr = stderr
end

Instance Attribute Details

#stderrObject (readonly)

Returns the value of attribute stderr.



7
8
9
# File 'lib/gdk/command/base_command.rb', line 7

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



7
8
9
# File 'lib/gdk/command/base_command.rb', line 7

def stdout
  @stdout
end

Class Method Details

.validate_config?Boolean

Ensure that gdk.yml is valid by default.

Returns:

  • (Boolean)


10
11
12
# File 'lib/gdk/command/base_command.rb', line 10

def self.validate_config?
  true
end

Instance Method Details

#configObject (protected)



29
30
31
# File 'lib/gdk/command/base_command.rb', line 29

def config
  GDK.config
end

#display_help_messageObject (protected)



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/gdk/command/base_command.rb', line 41

def display_help_message
  GDK::Output.divider(length: 55)
  GDK::Output.puts <<~HELP_MESSAGE
    You can try the following that may be of assistance:

    - Run 'gdk doctor'.

    - Visit the troubleshooting documentation:
      https://gitlab.com/gitlab-org/gitlab-development-kit/-/blob/main/doc/troubleshooting/index.md.
    - Visit https://gitlab.com/gitlab-org/gitlab-development-kit/-/issues to
      see if there are known issues.

    - Run 'gdk reset-data' if appropriate.
    - Run 'gdk pristine' which will restore your GDK to a pristine state.
  HELP_MESSAGE
  GDK::Output.divider(length: 55)
end

#helpObject

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/gdk/command/base_command.rb', line 23

def help
  raise NotImplementedError
end


33
34
35
36
37
38
39
# File 'lib/gdk/command/base_command.rb', line 33

def print_help(args)
  return false unless (args & ['-h', '--help']).any?

  GDK::Output.puts(help)

  true
end


59
60
61
62
63
64
65
# File 'lib/gdk/command/base_command.rb', line 59

def print_ready_message
  notices = ready_messages
  return if notices.empty?

  GDK::Output.puts
  notices.each { |msg| GDK::Output.notice(msg) }
end

#ready_messagesObject (protected)

rubocop:disable Metrics/AbcSize – Just simple if statements



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/gdk/command/base_command.rb', line 68

def ready_messages
  notices = []

  if config.rails_web?
    debug_info = GDK::Command::DebugInfo.new
    notices << "GitLab available at #{config.__uri}."
    notices << "  - Ruby: #{debug_info.ruby_version}."
    notices << "  - Node.js: #{debug_info.node_version}."
  end

  notices << "GitLab Docs available at #{config.gitlab_docs.__uri}." if config.gitlab_docs?

  if config.gitlab_k8s_agent?
    notices << "GitLab Agent Server (KAS) available at #{config.gitlab_k8s_agent.__url_for_agentk}."
    notices << "Kubernetes proxy (via KAS) available at #{config.gitlab_k8s_agent.__k8s_api_url}."
  end

  notices << "GitLab AI Gateway is available at #{config.gitlab_ai_gateway.__listen}/docs." if config.gitlab_ai_gateway?

  notices << "Prometheus available at #{config.prometheus.__uri}." if config.prometheus?
  notices << "Grafana available at #{config.grafana.__uri}." if config.grafana?
  notices << "A container registry is available at #{config.registry.__listen}." if config.registry?

  notices << GDK::Services::GitlabHttpRouter.new.ready_message if config.gitlab_http_router?
  notices << GDK::Services::GitlabTopologyService.new.ready_message if config.gitlab_topology_service?

  notices
end

#run(args = []) ⇒ Object

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/gdk/command/base_command.rb', line 19

def run(args = [])
  raise NotImplementedError
end