Class: Neptuno::CLI::List
- Includes:
- DOTIW::Methods, TTY::Config, TTY::File
- Defined in:
- lib/neptuno/cli/list.rb
Overview
Init Neptuno files
Constant Summary collapse
- STATE_ORDER =
%w[on dead off].freeze
Constants included from TTY::Config
TTY::Config::ABORT_MESSAGE, TTY::Config::TTY
Constants included from TTY::File
TTY::File::ABORT_MESSAGE, TTY::File::TTY
Constants inherited from Base
Constants included from TTY::Command
TTY::Command::TTY, TTY::Command::TTYP
Constants included from TTY::Prompt
Instance Method Summary collapse
- #call(**options) ⇒ Object
- #get_display_date(date, relative) ⇒ Object
- #last_commit_date ⇒ Object
- #service_current_branches ⇒ Object
- #services_and_procs ⇒ Object
Methods included from TTY::Config
#auto_restart_procs, #config, #configured_services, #docker_compose_hash, #docker_compose_services, #get_dependants, #healthy_services, #json_services_status, #running_services, #services, #services_with_procs, #starting_services
Methods included from TTY::File
#file, #in_service?, #make_service_files, #neptuno_path, #project, #service
Methods inherited from Base
#command_service_to, #command_services_to, #initialize
Methods included from TTY::Command
#command, #command_p, #neptuno_command
Methods included from TTY::Prompt
Constructor Details
This class inherits a constructor from Neptuno::CLI::Base
Instance Method Details
#call(**options) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/neptuno/cli/list.rb', line 53 def call(**) jss = json_services_status.to_h branches = service_current_branches dates = last_commit_date procs = services_and_procs.map do |name, *processes| display_date = get_display_date(dates[name], .fetch(:relative)) state = jss.to_h[name] || "Off" {state: state, name: name, branch: branches[name], last_commit: display_date, processes: processes} end puts Hirb::Helpers::AutoTable.render(procs.sort do |a, b| a[:state].split(" ").first <=> b[:state].split(" ").first end.reverse, fields: %i[state name branch last_commit processes]) end |
#get_display_date(date, relative) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/neptuno/cli/list.rb', line 46 def get_display_date(date, relative) return unless date return date unless relative distance_of_time_in_words(Time.now, Time.parse(date), false, highest_measures: 1).concat(" ago") end |
#last_commit_date ⇒ Object
39 40 41 42 43 44 |
# File 'lib/neptuno/cli/list.rb', line 39 def last_commit_date dates = `cd #{neptuno_path} && git submodule foreach 'git log -1 --format=%cd'` dates.lines.each_slice(2).map do |service, date| [service.match(%r{services/(.*)'}).to_a.last, date.to_s.strip] end.to_h end |
#service_current_branches ⇒ Object
32 33 34 35 36 37 |
# File 'lib/neptuno/cli/list.rb', line 32 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] end.to_h end |
#services_and_procs ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/neptuno/cli/list.rb', line 18 def services_and_procs proc_files = Dir.glob("procfiles/**/Procfile", base: neptuno_path) sap = proc_files.map do |f| [f.split("/")[1], File.read("#{neptuno_path}/#{f}").split("\n").map do |s| next if /^\w*#/.match?(s) s.split(":").first end.compact] end.to_h services.each { |s| sap[s] ||= [] } sap end |