Class: Ledmon::CLI::Monster
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#deploy ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ledmon/cli/monster.rb', line 19 def deploy packer = Ledmon::Monster::Packer.new(path: Dir.pwd) packer.pack! do |bundle_path| deployer = Ledmon::Monster::Deployer.new say "Uploading packed file ...", :yellow deployer.deploy!(bundle_path:) do |json_data| if json_data['message'] say json_data['message'], :cyan elsif json_data['error'] say_error json_data['error'], :red else say json_data.to_s, :white end end say "Successfully deployed monster code!", :green end rescue Ledmon::Error => e say_error e., :red exit 1 end |
#docs ⇒ Object
66 67 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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/ledmon/cli/monster.rb', line 66 def docs say "Generating API documentation ...", :yellow # Find DOCS.md file from gem root docs_path = File.join(Ledmon.root, 'DOCS.md') unless File.exist?(docs_path) say_error "DOCS.md not found in current directory", :red exit 1 end # Read markdown content markdown_content = File.read(docs_path) # Convert to HTML html_content = markdown_to_html(markdown_content) # Start simple web server require 'webrick' port = 31337 server = WEBrick::HTTPServer.new(Port: port, Logger: WEBrick::Log.new('/dev/null')) server.mount_proc '/docs' do |req, res| res.content_type = 'text/html' res.body = html_content end say "Documentation server started at http://localhost:#{port}/docs", :green # Start server in background thread server_thread = Thread.new { server.start } # Give server a moment to start sleep 1 # Open in browser require 'launchy' Launchy.open("http://localhost:#{port}/docs") do |error| if RbConfig::CONFIG['host_os'] == 'linux' && %x[uname -a] =~ /WSL/ ENV['BROWSER'] = 'cmd.exe /c start' Launchy.open("http://localhost:#{port}/docs") else say_error "Failed to open browser automatically: #{error.}", :red end end say "Press any key to stop the server ...", :cyan # Wait for keypress STDIN.getch rescue nil # Stop server server.shutdown server_thread.join say "Documentation server stopped", :yellow rescue Ledmon::Error => e say_error e., :red exit 1 end |
#local ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ledmon/cli/monster.rb', line 5 def local runner = Ledmon::Monster::Runner.new(path: Dir.pwd) runner.run! rescue Interrupt exit 1 rescue Ledmon::Error => e say_error e., :yellow if Ledmon::Config.log_level.to_sym == :debug say_error e.backtrace.join("\n"), :white end end |
#logs ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ledmon/cli/monster.rb', line 44 def logs say "Fetching logs from the deployed monster ...", :yellow deployer = Ledmon::Monster::Deployer.new deployer.logs do |json_data| case json_data['stream'] when 'stdout' say json_data['chunk'], :white when 'stderr' say_error json_data['chunk'], :red else if json_data.has_key?('chunk') say json_data['chunk'], :white else say_error "Unknown log format: #{json_data.inspect}", :red end end end end |