diff --git a/Gemfile.lock b/Gemfile.lock index 2b41eb8..fe6ce43 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - neptuno (1.3.0) + neptuno (1.5.3) dotiw dry-cli hirb @@ -17,19 +17,29 @@ PATH GEM remote: https://rubygems.org/ specs: - activesupport (7.0.7.2) + activesupport (7.1.2) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) minitest (>= 5.1) + mutex_m tzinfo (~> 2.0) ansi (1.5.0) ast (2.4.2) + base64 (0.2.0) + bigdecimal (3.1.5) builder (3.2.4) concurrent-ruby (1.2.2) + connection_pool (2.4.1) diff-lcs (1.5.0) dotiw (5.3.3) activesupport i18n + drb (2.2.0) + ruby2_keywords dry-cli (1.0.0) hirb (0.7.3) i18n (1.14.1) @@ -41,6 +51,7 @@ GEM builder minitest (>= 5.0) ruby-progressbar + mutex_m (0.2.0) parallel (1.22.1) parser (3.1.2.1) ast (~> 2.4.1) @@ -67,6 +78,7 @@ GEM rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) ruby-progressbar (1.11.0) + ruby2_keywords (0.0.5) standard (1.18.0) rubocop (= 1.39.0) rubocop-performance (= 1.15.0) @@ -86,7 +98,7 @@ GEM tty-cursor (~> 0.7) tty-screen (~> 0.8) wisper (~> 2.0) - tty-screen (0.8.1) + tty-screen (0.8.2) tty-spinner (0.9.3) tty-cursor (~> 0.7) tty-which (0.5.0) @@ -94,7 +106,7 @@ GEM concurrent-ruby (~> 1.0) unicode-display_width (2.3.0) wisper (2.0.1) - zeitwerk (2.6.11) + zeitwerk (2.6.12) PLATFORMS arm64-darwin-21 diff --git a/lib/neptuno/cli.rb b/lib/neptuno/cli.rb index f39449b..667c17d 100644 --- a/lib/neptuno/cli.rb +++ b/lib/neptuno/cli.rb @@ -35,5 +35,6 @@ module CLI register "install", ::Neptuno::CLI::Install register "environment update", Environment::Update register "environment config", Environment::Config + register "jump", Jump, aliases: ['j'] end end diff --git a/lib/neptuno/cli/base.rb b/lib/neptuno/cli/base.rb index e3fc1b7..c69911c 100644 --- a/lib/neptuno/cli/base.rb +++ b/lib/neptuno/cli/base.rb @@ -18,7 +18,7 @@ def initialize end def command_service_to(request, service_as_args: "") - chosen_service ||= service_as_args.to_a.empty? ? nil : service_as_args + chosen_service ||= Array(service_as_args).empty? ? nil : service_as_args chosen_service ||= service if in_service? chosen_service ||= prompt.select("Command service to #{request}:", services) yield chosen_service, project @@ -26,9 +26,9 @@ def command_service_to(request, service_as_args: "") def command_services_to(request, all: nil, services_as_args: []) chosen_services = services if all - chosen_services ||= services_as_args.to_a.empty? ? nil : services_as_args + chosen_services ||= Array(services_as_args).empty? ? nil : services_as_args chosen_services ||= [service] if in_service? - chosen_services ||= configured_services.to_a.empty? ? nil : configured_services + chosen_services ||= Array(configured_services).empty? ? nil : configured_services chosen_services ||= prompt.multi_select("Command services to #{request}:", services) yield chosen_services, project end diff --git a/lib/neptuno/cli/jump.rb b/lib/neptuno/cli/jump.rb new file mode 100644 index 0000000..d108597 --- /dev/null +++ b/lib/neptuno/cli/jump.rb @@ -0,0 +1,17 @@ +module Neptuno + module CLI + class Jump < Neptuno::CLI::Base + include ::Neptuno::TTY::Config + desc "Jump between a service's files" + + def call(**options) + command_service_to("jump", service_as_args: options[:args]&.first) do |service, project| + files = [:procfiles, :dockerfiles, :environments, :services] + chosen_folder ||= prompt.select("Jump to #{service}'s:", files) + + puts "#{neptuno_path}/#{chosen_folder}/#{service}" + end + end + end + end +end diff --git a/lib/neptuno/cli/list.rb b/lib/neptuno/cli/list.rb index cbebe8e..b2128a8 100644 --- a/lib/neptuno/cli/list.rb +++ b/lib/neptuno/cli/list.rb @@ -32,7 +32,7 @@ def services_and_procs def service_current_branches branches = `cd #{neptuno_path} && git submodule foreach 'git branch --show-current'` branches.lines.each_slice(2).map do |service, branch| - [service.match(%r{services/(.*)'}).to_a.last, branch.to_s.strip] + [service.match(%r{services\/(.*)'}).to_a.last, branch.to_s.strip] end.to_h end diff --git a/lib/neptuno/docker/up.rb b/lib/neptuno/docker/up.rb index e194e5f..cf5de09 100644 --- a/lib/neptuno/docker/up.rb +++ b/lib/neptuno/docker/up.rb @@ -13,7 +13,7 @@ class Up < Neptuno::CLI::Base def call(services: [], **options) command_services_to('come up', all: options.fetch(:all), services_as_args: services) do |services, _project| make_service_files(services) - system("cd #{neptuno_path} && docker compose up -d --wait #{services.join(' ')}") + system("cd #{neptuno_path} && docker compose up --wait #{services.join(' ')}") end end end diff --git a/lib/neptuno/overmind/start.rb b/lib/neptuno/overmind/start.rb index 0e94b64..fe9813b 100644 --- a/lib/neptuno/overmind/start.rb +++ b/lib/neptuno/overmind/start.rb @@ -9,6 +9,7 @@ class Start < Neptuno::CLI::Base option :all, type: :boolean, default: false, desc: "Run on all services" option :up, type: :boolean, default: true, desc: "Try to start containers before connecting" + option :inline, type: :boolean, default: false, desc: 'Start processes inline' argument :services, type: :array, required: false, desc: "Optional list of services" def call(services: [], **options) @@ -27,9 +28,11 @@ def call(services: [], **options) end else services.each do |service| - system("cd #{neptuno_path}/procfiles/#{service} && overmind start -D -N #{if auto_restart_procs.to_a.size > 0 + inline = options.fetch(:inline) ? "" : "-D" + output = options.fetch(:inline) ? "" : "> /dev/null 2>&1" + system("cd #{neptuno_path}/procfiles/#{service} && overmind start #{inline} -N #{if auto_restart_procs.to_a.size > 0 ("-r " + auto_restart_procs.join(",") + " ") - end} > /dev/null 2>&1") + end} #{output}") end end end diff --git a/lib/neptuno/services/update.rb b/lib/neptuno/services/update.rb index 0c3f96a..2c0609e 100644 --- a/lib/neptuno/services/update.rb +++ b/lib/neptuno/services/update.rb @@ -15,8 +15,10 @@ def call(services: [], **options) command_services_to('update', all: options.fetch(:all), services_as_args: services) do |services| services.each do |service| puts "---Updating #{service}---" - current_branch = `git branch --show-current` - puts current_branch + if `ls -hal #{neptuno_path}/services/#{service} 2>/dev/null | grep .git`.empty? + next if !initialize_submodule(service) + end + current_branch = `cd #{neptuno_path}/services/#{service} 2>/dev/null && git branch --show-current` system("cd #{neptuno_path}/services/#{service} 2>/dev/null && git add . && git stash save -u -q neptuno_stash") `cd #{neptuno_path}/services/#{service} 2>/dev/null && git checkout main 2>/dev/null` `cd #{neptuno_path}/services/#{service} 2>/dev/null && git checkout master 2>/dev/null` @@ -33,6 +35,21 @@ def call(services: [], **options) end end end + + def initialize_submodule(service) + puts "Initializing submodule for #{service}" + if `git submodule | grep #{service} 2>/dev/null`.empty? + puts ("Skipping #{service}, it is not a git submodule.") + puts "" + return false + end + # TODO abort if the current user doesn't have access to the remote submodule repo + + `cd #{neptuno_path}/services/#{service} && git submodule update --init --recursive` + `cd #{neptuno_path}/services/#{service} && git checkout master 2>/dev/null` + `cd #{neptuno_path}/services/#{service} && git checkout main 2>/dev/null` + return true + end end end end diff --git a/lib/neptuno/tty/config.rb b/lib/neptuno/tty/config.rb index 5eb0523..ce0d953 100644 --- a/lib/neptuno/tty/config.rb +++ b/lib/neptuno/tty/config.rb @@ -47,7 +47,8 @@ def running_services end def json_services_status - JSON.parse(`cd #{neptuno_path} && docker compose ps --all --format json`).map do |service| + `cd #{neptuno_path} && docker compose ps --all --format json`.lines.map do |line| + service = JSON.parse(line) [service.dig('Service'), service.dig('Status')] end end diff --git a/lib/neptuno/version.rb b/lib/neptuno/version.rb index 1484e5e..754a22a 100644 --- a/lib/neptuno/version.rb +++ b/lib/neptuno/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Neptuno - VERSION = '1.4.0' + VERSION = '1.5.3' end diff --git a/neptuno-1.4.0.gem b/neptuno-1.4.0.gem new file mode 100644 index 0000000..390037f Binary files /dev/null and b/neptuno-1.4.0.gem differ