Class: JDC::App::Files
- Defined in:
- lib/jdc/cli/app/files.rb
Instance Method Summary collapse
Methods inherited from Base
#app_status, #human_mb, #human_size, #megabytes, #memory_choices, #state_color
Methods included from LoginRequirements
Methods inherited from CLI
#add_exception_name_to_msg, #build_client, #check_key, #check_logged_in, #check_organization_and_space, #check_target, client, #client, client=, #client_target, #color_enabled?, #debug?, #default_action, #ensure_config_dir, #err, #execute, #fail, #fail_unknown, #force?, #formatted_exception_output, #help, #help_header, #invalidate_client, #log_error, #name_list, #normalize_targets_info, #one_of, #quiet?, #remove_target_info, #sane_target_url, #save_target_info, #save_targets, #save_token_if_it_changes, #set_target, #table, #target_info, #targets_info, #user_colors, #verbose?, #wrap_errors
Methods included from Spacing
#indented, #justify, #line, #lines, #quiet?, #spaced, #start_line, #tabular, #text_width, #trim_escapes
Methods included from Interactive
#ask, #handler, #input_state, #list_choices, #prompt, #show_default
Instance Method Details
#file ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/jdc/cli/app/files.rb', line 12 def file app = input[:app] path = input[:path] file = with_progress("Getting file contents") do app.file(*path.split("/")) end if quiet? print file else line file.split("\n").each do |l| line l end end rescue JFoundry::NotFound fail "Invalid path #{b(path)} for app #{b(app.name)}" rescue JFoundry::FileError => e fail e.description end |
#files ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/jdc/cli/app/files.rb', line 42 def files app = input[:app] path = input[:path] if quiet? files = with_progress("Getting file listing") do app.files(*path.split("/")) end files.each do |file| line file.join("/") end else invoke :file, :app => app, :path => path end rescue JFoundry::NotFound fail "Invalid path #{b(path)} for app #{b(app.name)}" rescue JFoundry::FileError => e fail e.description end |
#stream_path(lines, instance, path) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/jdc/cli/app/files.rb', line 113 def stream_path(lines, instance, path) if verbose? lines << [instance, path, c("streaming...", :good) + "\n"] end instance.stream_file(*path) do |contents| contents.each_line do |line| lines << [instance, path, line] end end lines << [instance, path, c("end of file", :bad) + "\n"] rescue Timeout::Error if verbose? lines << [ instance, path, c("timed out; reconnecting...", :bad) + "\n" ] end retry end |
#tail ⇒ Object
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 |
# File 'lib/jdc/cli/app/files.rb', line 69 def tail app = input[:app] lines = Queue.new max_len = 0 if path = input[:path] max_len = path.size app.instances.each do |i| Thread.new do stream_path(lines, i, path.split("/")) end end else app.instances.each do |i| i.files("logs").each do |path| len = path.join("/").size max_len = len if len > max_len Thread.new do stream_path(lines, i, path) end end end end while line = lines.pop instance, path, log = line unless log.end_with?("\n") log += i("%") if color? log += "\n" end print "\##{c(instance.id, :instance)} " print "#{c(path.join("/").ljust(max_len), :name)} " print log end rescue JFoundry::NotFound fail "Invalid path #{b(path)} for app #{b(app.name)}" rescue JFoundry::FileError => e fail e.description end |