Class: JadeSystemsToolbox::Cli
- Inherits:
-
Thor
- Object
- Thor
- JadeSystemsToolbox::Cli
- Defined in:
- lib/jade_systems_toolbox/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #down ⇒ Object
- #edit ⇒ Object
- #init ⇒ Object
- #initialize_docker ⇒ Object
- #initialize_vscode ⇒ Object
- #open ⇒ Object
- #port(container_port = 3000) ⇒ Object
- #ports ⇒ Object
- #server(command = "bin/dev") ⇒ Object
- #terminal ⇒ Object
- #up ⇒ Object
- #version ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
9 |
# File 'lib/jade_systems_toolbox/cli.rb', line 9 def exit_on_failure? = true |
Instance Method Details
#down ⇒ Object
18 19 20 |
# File 'lib/jade_systems_toolbox/cli.rb', line 18 def down system("docker compose down") end |
#edit ⇒ Object
23 24 25 |
# File 'lib/jade_systems_toolbox/cli.rb', line 23 def edit `devcontainer open` end |
#init ⇒ Object
32 33 34 35 |
# File 'lib/jade_systems_toolbox/cli.rb', line 32 def init invoke :initialize_docker invoke :initialize_vscode, [], {} end |
#initialize_docker ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/jade_systems_toolbox/cli.rb', line 42 def initialize_docker get_and_save_file( "https://github.com/lcreid/docker/raw/refs/heads/main/rails-app-sqlite/compose.yml", ) do |file_contents| file_contents.gsub!( /jade:rails-app-[0-9]+\.[0-9]+-\w+-\w+$/, "jade:rails-app-#{options[:ruby_version] || "3.4"}" \ "-#{options[:database] || "sqlite"}" \ "-#{options[:distro_version] || bookworm}", ) end case Gem::Platform.local.os when "linux" get_and_save_file("https://github.com/lcreid/docker/raw/refs/heads/main/Linux/compose.override.yml") else raise Error.new("Not implemented for #{Gem::Platform.local.os}", [:verbose]) end end |
#initialize_vscode ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/jade_systems_toolbox/cli.rb', line 63 def initialize_vscode get_and_save_file("https://github.com/lcreid/docker/raw/refs/heads/main/.devcontainer.json") do |file_contents| file_contents.gsub!(/, "compose.override.yml"/, "") unless Gem::Platform.local.os == "linux" end Dir.mkdir(".vscode") unless Dir.exist?(".vscode") [ "https://github.com/lcreid/jade_systems_toolbox/raw/refs/heads/main/templates/extensions.json", "https://github.com/lcreid/jade_systems_toolbox/raw/refs/heads/main/templates/settings.json", ].each { get_and_save_file(_1, target_directory: File.join(".", ".vscode")) } end |
#open ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/jade_systems_toolbox/cli.rb', line 80 def open service = [:service] path = [:path] container_port = [:container_port] protocol = [:protocol] container_ports = compose_yaml.dig("services", "service", "ports") container_port = container_ports&.[](0) || container_port path = "/#{path}" if path[0] != "/" `open "#{protocol}://localhost:#{host_port_from_container_port(service:, container_port:)}#{path}"` end |
#port(container_port = 3000) ⇒ Object
94 95 96 97 |
# File 'lib/jade_systems_toolbox/cli.rb', line 94 def port(container_port = 3000) service = [:service] puts host_port_from_container_port(service:, container_port:) end |
#ports ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/jade_systems_toolbox/cli.rb', line 101 def ports services = compose_yaml["services"] service_ports = services.transform_values { |attributes| attributes&.[]("ports") } service_ports.each do |service, ports| ports&.each do |container_port| puts "#{service}: #{host_port_from_container_port(service:, container_port:)}" end end end |
#server(command = "bin/dev") ⇒ Object
115 116 117 118 119 |
# File 'lib/jade_systems_toolbox/cli.rb', line 115 def server(command = "bin/dev") service = [:service] workdir = "-w #{options[:work_dir]} " unless [:work_dir].nil? system("docker compose exec #{workdir}#{service} #{command}") end |
#terminal ⇒ Object
123 124 125 126 |
# File 'lib/jade_systems_toolbox/cli.rb', line 123 def terminal service = [:service] system("docker compose exec -it #{service} '/bin/bash'") end |
#up ⇒ Object
129 130 131 |
# File 'lib/jade_systems_toolbox/cli.rb', line 129 def up system("docker compose up -d") end |
#version ⇒ Object
134 135 136 |
# File 'lib/jade_systems_toolbox/cli.rb', line 134 def version puts JadeSystemsToolbox::VERSION end |