Class: VMC::Cli::Command::FileWithPercentOutput

Inherits:
File
  • Object
show all
Defined in:
lib/cli/commands/apps.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.display_strObject

Returns the value of attribute display_str.



1268
1269
1270
# File 'lib/cli/commands/apps.rb', line 1268

def display_str
  @display_str
end

.upload_sizeObject

Returns the value of attribute upload_size.



1268
1269
1270
# File 'lib/cli/commands/apps.rb', line 1268

def upload_size
  @upload_size
end

Instance Method Details

#read(*args) ⇒ Object



1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
# File 'lib/cli/commands/apps.rb', line 1282

def read(*args)
  result  = super(*args)
  if result && result.size > 0
    update_display(result.size)
  else
    unless VMC::Cli::Config.output.nil? || !STDOUT.tty?
      clear(FileWithPercentOutput.display_str.size + 5)
      VMC::Cli::Config.output.print(FileWithPercentOutput.display_str)
      display('OK'.green)
    end
  end
  result
end

#update_display(rsize) ⇒ Object



1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
# File 'lib/cli/commands/apps.rb', line 1271

def update_display(rsize)
  @read ||= 0
  @read += rsize
  p = (@read * 100 / FileWithPercentOutput.upload_size).to_i
  unless VMC::Cli::Config.output.nil? || !STDOUT.tty?
    clear(FileWithPercentOutput.display_str.size + 5)
    VMC::Cli::Config.output.print("#{FileWithPercentOutput.display_str} #{p}%")
    VMC::Cli::Config.output.flush
  end
end