Module: Up::CLI

Defined in:
lib/up/cli.rb,
lib/up/bun/server_cli.rb,
lib/up/ruby/cluster_cli.rb,
lib/up/u_web_socket/cluster_cli.rb

Defined Under Namespace

Classes: Options

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.callObject



11
12
13
# File 'lib/up/bun/server_cli.rb', line 11

def self.call
  Up::Bun::RackServer.run(get_app, get_options)
end

.get_app(filename = 'config.ru') ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
# File 'lib/up/cli.rb', line 123

def get_app(filename = 'config.ru')
  app = nil
  filename ||= 'config.ru'
  app = try_file(filename)
  unless app
    filename = "#{filename}.ru"
    app = try_file(filename)
  end
  raise "Something wrong with #{filename}\n" unless app
  app
end

.get_gems_for_cmdObject



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/up/cli.rb', line 104

def get_gems_for_cmd
  # Opal does not yet support gems, so lets read the Gemfile and simply add each gem
  # to the Opal load path and require it, works for some gems, fails for others
  gems = ""
  if File.exist?("Gemfile")
    lines = File.readlines('Gemfile')
    lines.each do |line|
      m = /gem ['"](\w+)['"]/.match(line)
      gems << " -g #{m[1]} -r #{m[1]}" if m && m[1] != 'opal-up'
    end
  end
  gems
end

.get_optionsObject



95
96
97
98
99
100
101
102
# File 'lib/up/cli.rb', line 95

def get_options
  options = Up::CLI::Options.new
  options.parse!
  options.options
rescue OptionParser::InvalidOption => e
  $stderr.puts "#{$0}: #{e.message} (-h will show valid options)"
  exit 64
end

.stoppable?Boolean

Returns:

  • (Boolean)


135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/up/cli.rb', line 135

def stoppable?
  sleep 0.1
  puts 'deflating request chain links'
  sleep 0.1
  puts 'optimizing response distortion'
  sleep 0.1
  print 'releasing boost pressure: '
  3.times do
    sleep 0.2
    print '.'
  end
  3.times do 
    puts "\n\033[5;31;47mRED ALERT: boost pressure to high, cannot open release valve!1!!!\033[0m"
    sleep 0.1
    print '.'
    sleep 0.1
  end
  puts 'stopping engines failed, for further help see:'
  puts 'https://www.youtube.com/watch?v=ecBco63zvas'
  sleep 0.2
  puts "Just kidding :)"
  true
end

.try_file(filename) ⇒ Object



118
119
120
121
# File 'lib/up/cli.rb', line 118

def try_file(filename)
  return nil unless File.exist? filename
  ::Rack::Builder.parse_file filename
end

Instance Method Details

#setup_bunObject



63
64
65
66
67
68
69
70
# File 'lib/up/cli.rb', line 63

def setup_bun
  bun_cmd = `which bun`
  if !bun_cmd || bun_cmd.empty?
    puts "Please install bun first!"
    exit 2
  end
  true
end

#setup_nodeObject



72
73
74
75
76
77
78
79
# File 'lib/up/cli.rb', line 72

def setup_node
  node_cmd = `which node`
  if !node_cmd || node_cmd.empty?
    puts "Please install node first!"
    exit 2
  end
  true
end

#setup_u_web_socketObject



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/up/cli.rb', line 81

def setup_u_web_socket
  setup_node
  npm_cmd = `which npm`
  if !npm_cmd || npm_cmd.empty?
    puts "Please install npm first!"
    exit 2
  end
  npm_cmd.chop! if npm_cmd.end_with?("\n")
  have_uws = `npm list|grep uWebSockets.js@20`
  `npm i uNetworking/uWebSockets.js#v20.41.0` if have_uws.empty?
  true
end